Ejemplo n.º 1
0
        public static void TestDictionaryResizing()
        {
            Random random = new Random(5);
            UnsafeBufferPool <int>     pool              = new UnsafeBufferPool <int>();
            QuickDictionary <int, int> dictionary        = new QuickDictionary <int, int>(pool, pool, pool);
            Dictionary <int, int>      controlDictionary = new Dictionary <int, int>();

            for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex)
            {
                if (random.NextDouble() < 0.7)
                {
                    dictionary.Add(iterationIndex, iterationIndex);
                    controlDictionary.Add(iterationIndex, iterationIndex);
                }
                if (random.NextDouble() < 0.2)
                {
                    var indexToRemove = random.Next(dictionary.Count);
                    var toRemove      = dictionary.Keys[indexToRemove];
                    dictionary.FastRemove(toRemove);
                    controlDictionary.Remove(toRemove);
                }
                if (iterationIndex % 1000 == 0)
                {
                    dictionary.EnsureCapacity(dictionary.Count * 3);
                }
                else if (iterationIndex % 7777 == 0)
                {
                    dictionary.Compact();
                }
            }

            Assert.IsTrue(dictionary.Count == controlDictionary.Count);
            for (int i = 0; i < dictionary.Count; ++i)
            {
                Assert.IsTrue(controlDictionary.ContainsKey(dictionary.Keys[i]));
            }
            foreach (var element in controlDictionary.Keys)
            {
                Assert.IsTrue(dictionary.ContainsKey(element));
            }
        }
        public static void TestDictionaryResizing(IUnmanagedMemoryPool pool)
        {
            Random random     = new Random(5);
            var    dictionary = new QuickDictionary <int, int, PrimitiveComparer <int> >(4, pool);
            Dictionary <int, int> controlDictionary = new Dictionary <int, int>();

            for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex)
            {
                if (random.NextDouble() < 0.7)
                {
                    dictionary.Add(iterationIndex, iterationIndex, pool);
                    controlDictionary.Add(iterationIndex, iterationIndex);
                }
                if (random.NextDouble() < 0.2)
                {
                    var indexToRemove = random.Next(dictionary.Count);
                    var toRemove      = dictionary.Keys[indexToRemove];
                    dictionary.FastRemove(toRemove);
                    controlDictionary.Remove(toRemove);
                }
                if (iterationIndex % 1000 == 0)
                {
                    dictionary.EnsureCapacity(dictionary.Count * 3, pool);
                }
                else if (iterationIndex % 7777 == 0)
                {
                    dictionary.Compact(pool);
                }
            }

            Debug.Assert(dictionary.Count == controlDictionary.Count);
            for (int i = 0; i < dictionary.Count; ++i)
            {
                Debug.Assert(controlDictionary.ContainsKey(dictionary.Keys[i]));
            }
            foreach (var element in controlDictionary.Keys)
            {
                Debug.Assert(dictionary.ContainsKey(element));
            }
            dictionary.Dispose(pool);
        }
Ejemplo n.º 3
0
        public static void TestDictionaryResizing()
        {
            Random random = new Random(5);
            UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>();
            QuickDictionary<int, int> dictionary = new QuickDictionary<int, int>(pool, pool, pool);
            Dictionary<int, int> controlDictionary = new Dictionary<int, int>();

            for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex)
            {
                if (random.NextDouble() < 0.7)
                {
                    dictionary.Add(iterationIndex, iterationIndex);
                    controlDictionary.Add(iterationIndex, iterationIndex);
                }
                if (random.NextDouble() < 0.2)
                {
                    var indexToRemove = random.Next(dictionary.Count);
                    var toRemove = dictionary.Keys[indexToRemove];
                    dictionary.FastRemove(toRemove);
                    controlDictionary.Remove(toRemove);
                }
                if (iterationIndex % 1000 == 0)
                {
                    dictionary.EnsureCapacity(dictionary.Count * 3);
                }
                else if (iterationIndex % 7777 == 0)
                {
                    dictionary.Compact();
                }
            }

            Assert.IsTrue(dictionary.Count == controlDictionary.Count);
            for (int i = 0; i < dictionary.Count; ++i)
            {
                Assert.IsTrue(controlDictionary.ContainsKey(dictionary.Keys[i]));
            }
            foreach (var element in controlDictionary.Keys)
            {
                Assert.IsTrue(dictionary.ContainsKey(element));
            }
        }
Ejemplo n.º 4
0
 public bool Contains(ulong id)
 {
     return(allocations.ContainsKey(id));
 }