public void AddTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { hashSet.Add(0); Assert.IsTrue(hashSet.Contains(0)); Assert.AreEqual(hashSet.Count, 1); } }
public void AddTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { hashSet.Add(0); Assert.IsTrue(hashSet.Contains(0)); Assert.AreEqual(hashSet.Count, 1); } }
public void RemoveTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { hashSet.Add(0); Assert.IsTrue(hashSet.Contains(0)); hashSet.Remove(0); Assert.IsFalse(hashSet.Contains(0)); Assert.AreEqual(hashSet.Count, 0); } }
public void RemoveTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { hashSet.Add(0); Assert.IsTrue(hashSet.Contains(0)); hashSet.Remove(0); Assert.IsFalse(hashSet.Contains(0)); Assert.AreEqual(hashSet.Count, 0); } }
public void ClearTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { for (int i = 0; i < 100; i++) { hashSet.Add(i); } Assert.AreEqual(hashSet.Count, 100); hashSet.Clear(); Assert.AreEqual(hashSet.Count, 0); } }
public void IntersectWithTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { for (int i = 0; i < 10; i++) hashSet.Add(i); hashSet.IntersectWith(Enumerable.Range(5, 10)); for (int i = 5; i < 10; i++) Assert.IsTrue(hashSet.Contains(i), i.ToString()); Assert.AreEqual(hashSet.Count, 5); } }
public void SetEqualsTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { for (int i = 0; i < 5; i++) { hashSet.Add(i); } Assert.IsTrue(hashSet.SetEquals(Enumerable.Range(0, 5)), "Equal"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(0, 10)), "Superset"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(0, 3)), "Subset"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(1, 5)), "Overlap"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(5, 5)), "Disjoint"); } }
public void ExceptWithTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { for (int i = 0; i < 10; i++) { hashSet.Add(i); } hashSet.ExceptWith(Enumerable.Range(5, 10)); for (int i = 0; i < 5; i++) { Assert.IsTrue(hashSet.Contains(i), i.ToString()); } Assert.AreEqual(hashSet.Count, 5); } }
public void CompactTest() { using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { for (int i = 0; i < 10000; i += 4) { hashSet.Add(i); if (i % 100 == 0) { hashSet.Remove(i); } if (i % 400 == 0) { hashSet.Add(i); } } hashSet.Compact(); for (int i = 0; i < 10000; i++) { if (i % 400 == 0) { Assert.IsTrue(hashSet.Contains(i)); } else if (i % 100 == 0) { Assert.IsFalse(hashSet.Contains(i)); } else if (i % 4 == 0) { Assert.IsTrue(hashSet.Contains(i)); } else { Assert.IsFalse(hashSet.Contains(i)); } } } }
/// <summary> /// Creates a new instance of the <see cref="FileProcessor"/> class. /// </summary> /// <param name="processorID">Identifies the file processor so that it can locate its processed file cache.</param> public FileProcessor(Guid processorID) { m_processorID = processorID; m_filter = DefaultFilter; m_trackChanges = DefaultTrackChanges; m_cachePath = DefaultCachePath; m_fileWatchersLock = new object(); m_fileWatchers = new List <FileSystemWatcher>(); m_processingQueue = ProcessQueue <Action> .CreateRealTimeQueue(action => action()); m_processingQueue.SynchronizedOperationType = SynchronizedOperationType.LongBackground; m_processingQueue.ProcessException += (sender, args) => OnError(args.Argument); m_fileWatchTimer = new Timer(15000); m_fileWatchTimer.Elapsed += FileWatchTimer_Elapsed; m_waitObject = new ManualResetEvent(false); m_touchedFiles = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); m_processedFiles = new FileBackedHashSet <string>(Path.Combine(m_cachePath, m_processorID.ToString()), StringComparer.OrdinalIgnoreCase); }
public void CopyToTest() { int[] array; using (FileBackedHashSet <int> hashSet = new FileBackedHashSet <int>()) { for (int i = 1; i <= 100; i++) { hashSet.Add(i); } Assert.AreEqual(hashSet.Count, 100); array = new int[hashSet.Count]; hashSet.CopyTo(array, 0); foreach (int i in array) { Assert.IsTrue(hashSet.Contains(i)); } } }
public void ClearTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { for (int i = 0; i < 100; i++) hashSet.Add(i); Assert.AreEqual(hashSet.Count, 100); hashSet.Clear(); Assert.AreEqual(hashSet.Count, 0); } }
/// <summary> /// Releases all the resources used by the <see cref="FileProcessor"/> object. /// </summary> public void Dispose() { if (!m_disposed) { try { m_enumerator.Cancel(); ClearTrackedDirectories(); if ((object)m_fileWatchTimer != null) { m_fileWatchTimer.Dispose(); m_fileWatchTimer = null; } if ((object)m_processedFiles != null) { m_processedFiles.Dispose(); m_processedFiles = null; } if ((object)m_waitObject != null) { m_waitObject.Set(); m_waitObject.Dispose(); m_waitObject = null; } } finally { m_disposed = true; // Prevent duplicate dispose. } } }
/// <summary> /// Creates a new instance of the <see cref="FileProcessor"/> class. /// </summary> /// <param name="processorID">Identifies the file processor so that it can locate its processed file cache.</param> public FileProcessor(Guid processorID) { m_processorID = processorID; m_filter = DefaultFilter; m_trackChanges = DefaultTrackChanges; m_cachePath = DefaultCachePath; m_internalBufferSize = DefaultInternalBufferSize; m_fileWatchersLock = new object(); m_fileWatchers = new List<SafeFileWatcher>(); m_processingQueue = ProcessQueue<Action>.CreateRealTimeQueue(action => action()); m_processingQueue.SynchronizedOperationType = SynchronizedOperationType.LongBackground; m_processingQueue.ProcessException += (sender, args) => OnError(args.Argument); m_fileWatchTimer = new Timer(15000); m_fileWatchTimer.Elapsed += FileWatchTimer_Elapsed; m_waitObject = new ManualResetEvent(false); m_touchedFiles = new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase); m_processedFiles = new FileBackedHashSet<string>(Path.Combine(m_cachePath, m_processorID.ToString()), StringComparer.OrdinalIgnoreCase); }
public void CompactTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { for (int i = 0; i < 10000; i += 4) { hashSet.Add(i); if (i % 100 == 0) hashSet.Remove(i); if (i % 400 == 0) hashSet.Add(i); } hashSet.Compact(); for (int i = 0; i < 10000; i++) { if (i % 400 == 0) Assert.IsTrue(hashSet.Contains(i)); else if (i % 100 == 0) Assert.IsFalse(hashSet.Contains(i)); else if (i % 4 == 0) Assert.IsTrue(hashSet.Contains(i)); else Assert.IsFalse(hashSet.Contains(i)); } } }
public void CopyToTest() { int[] array; using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { for (int i = 1; i <= 100; i++) hashSet.Add(i); Assert.AreEqual(hashSet.Count, 100); array = new int[hashSet.Count]; hashSet.CopyTo(array, 0); foreach (int i in array) Assert.IsTrue(hashSet.Contains(i)); } }
/// <summary> /// Creates a new instance of the <see cref="FileProcessor"/> class. /// </summary> /// <param name="processorID">Identifies the file processor so that it can locate its processed file cache.</param> public FileProcessor(Guid processorID) { m_processorID = processorID; m_filter = DefaultFilter; m_filterMethod = filePath => true; m_trackChanges = DefaultTrackChanges; m_cachePath = DefaultCachePath; m_internalBufferSize = DefaultInternalBufferSize; m_maxFragmentation = DefaultMaxFragmentation; m_enumerationStrategy = DefaultEnumerationStrategy; m_fileWatchersLock = new object(); m_fileWatchers = new List<SafeFileWatcher>(); m_threadScheduler = new LogicalThreadScheduler(); m_threadScheduler.UnhandledException += (sender, args) => OnError(args.Argument); m_processingThread = m_threadScheduler.CreateThread(2); m_watcherThread = m_threadScheduler.CreateThread(); m_fileWatchTimer = new Timer(15000); m_fileWatchTimer.Elapsed += FileWatchTimer_Elapsed; m_waitObject = new ManualResetEvent(false); m_touchedFiles = new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase); m_processedFiles = new FileBackedHashSet<string>(Path.Combine(m_cachePath, m_processorID.ToString()), StringComparer.OrdinalIgnoreCase); // Create the enumerator last since we are passing // a reference to 'this' into its constructor m_enumerator = new FileEnumerator(this); }
public void SetEqualsTest() { using (FileBackedHashSet<int> hashSet = new FileBackedHashSet<int>()) { for (int i = 0; i < 5; i++) hashSet.Add(i); Assert.IsTrue(hashSet.SetEquals(Enumerable.Range(0, 5)), "Equal"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(0, 10)), "Superset"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(0, 3)), "Subset"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(1, 5)), "Overlap"); Assert.IsFalse(hashSet.SetEquals(Enumerable.Range(5, 5)), "Disjoint"); } }