public static void TestSetResizing(IUnmanagedMemoryPool pool) { Random random = new Random(5); var set = new QuickSet <int, PrimitiveComparer <int> >(4, pool); HashSet <int> controlSet = new HashSet <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex, pool); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3, pool); } else if (iterationIndex % 7777 == 0) { set.Compact(pool); } } Debug.Assert(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Debug.Assert(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Debug.Assert(set.Contains(element)); } set.Dispose(pool); }
public static void TestSetResizing() { Random random = new Random(5); UnsafeBufferPool <int> pool = new UnsafeBufferPool <int>(); QuickSet <int> set = new QuickSet <int>(pool, pool); HashSet <int> controlSet = new HashSet <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3); } else if (iterationIndex % 7777 == 0) { set.Compact(); } } Assert.IsTrue(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Assert.IsTrue(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Assert.IsTrue(set.Contains(element)); } }
public static void TestSetResizing() { Random random = new Random(5); UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>(); QuickSet<int> set = new QuickSet<int>(pool, pool); HashSet<int> controlSet = new HashSet<int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3); } else if (iterationIndex % 7777 == 0) { set.Compact(); } } Assert.IsTrue(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Assert.IsTrue(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Assert.IsTrue(set.Contains(element)); } }