示例#1
0
        public void HugeDictionary_Basic()
        {
            HugeDictionary <string, int> dictionary;
            int value;

            dictionary = new HugeDictionary <string, int>(10);
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));

            Assert.IsFalse(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsFalse(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(0, value);

            dictionary.Add("0", 0);
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(0, dictionary["0"]);
            Assert.IsTrue(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));

            Assert.IsTrue(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsFalse(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(0, value);

            dictionary.Add("1", 1);
            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual(0, dictionary["0"]);
            Assert.AreEqual(1, dictionary["1"]);
            Assert.IsTrue(dictionary.ContainsKey("0"));
            Assert.IsTrue(dictionary.ContainsKey("1"));

            Assert.IsTrue(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsTrue(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(1, value);

            dictionary.Remove("0");
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(1, dictionary["1"]);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsTrue(dictionary.ContainsKey("1"));

            Assert.IsFalse(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsTrue(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(1, value);

            dictionary.Clear();
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));
        }
示例#2
0
        public void HugeDictionary_LargeScale()
        {
            const int count = 10000000;

            HugeDictionary <int, int> dictionary;

            dictionary = new HugeDictionary <int, int>(100);

            for (int i = 0; i < count; i++)
            {
                dictionary.Add(i, -i);
            }

            Assert.AreEqual(count, dictionary.Count);
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(-i, dictionary[i]);
            }

            for (int i = 0; i < count; i++)
            {
                dictionary.Remove(i);
            }

            Assert.AreEqual(0, dictionary.Count);
        }
        public void TestHugeDictionaryEnumeration()
        {
            // create the huge dictionary.
            var hugeDictionary = new HugeDictionary <long, long>(100);

            for (long idx = 0; idx < 1000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            var items = new List <KeyValuePair <long, long> >(
                hugeDictionary);

            Assert.AreEqual(hugeDictionary.Count, items.Count);
        }
示例#4
0
        public void HugeDictionary_KeyComparer()
        {
            HugeDictionary <string, int> dictionary;

            dictionary = new HugeDictionary <string, int>(10, StringComparer.OrdinalIgnoreCase);
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("one"));
            Assert.IsFalse(dictionary.ContainsKey("two"));

            dictionary.Add("one", 0);
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(0, dictionary["one"]);
            Assert.AreEqual(0, dictionary["ONE"]);
            Assert.IsTrue(dictionary.ContainsKey("one"));
            Assert.IsTrue(dictionary.ContainsKey("One"));
        }
示例#5
0
        public void TestHugeDictionary()
        {
            // create the huge dictionary.
            var hugeDictionary = new HugeDictionary<long, long>();

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            Assert.AreEqual(10000, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Remove(idx);
            }

            Assert.AreEqual(0, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);

            hugeDictionary = new HugeDictionary<long, long>();

            for (long idx = 0; idx < 10000000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            Assert.AreEqual(10000000, hugeDictionary.Count);
            Assert.AreEqual(10, hugeDictionary.CountDictionaries);

            for (long idx = 0; idx < 10000000; idx++)
            {
                hugeDictionary.Remove(idx);
            }

            Assert.AreEqual(0, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);
        }
        public void TestHugeDictionary()
        {
            // create the huge dictionary.
            var hugeDictionary = new HugeDictionary <long, long>();

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            Assert.AreEqual(10000, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Remove(idx);
            }

            Assert.AreEqual(0, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);

            hugeDictionary = new HugeDictionary <long, long>(1000);

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            Assert.AreEqual(10000, hugeDictionary.Count);
            Assert.AreEqual(10, hugeDictionary.CountDictionaries);

            for (long idx = 0; idx < 10000; idx++)
            {
                hugeDictionary.Remove(idx);
            }

            Assert.AreEqual(0, hugeDictionary.Count);
            Assert.AreEqual(1, hugeDictionary.CountDictionaries);
        }
示例#7
0
        public void HugeDictionary_EnumerateEntries()
        {
            HugeDictionary <string, int> dictionary;
            Dictionary <string, bool>    enumerated;

            dictionary = new HugeDictionary <string, int>(10, 5000);
            enumerated = new Dictionary <string, bool>();

            for (int i = 0; i < 1000; i++)
            {
                dictionary.Add(i.ToString(), i);
            }

            foreach (var entry in dictionary)
            {
                Assert.AreEqual(entry.Key, entry.Value.ToString());
                enumerated[entry.Key] = true;
            }

            for (int i = 0; i < 1000; i++)
            {
                Assert.IsTrue(enumerated.ContainsKey(i.ToString()));
            }
        }
示例#8
0
        public void TestKeyAndValueCollections()
        {
            var dic = new HugeDictionary <int, string>(5);

            dic.Add(1, "1");
            dic.Add(2, "2");
            dic.Add(3, "3");
            dic.Add(4, "4");
            dic.Add(5, "5");
            dic.Add(6, "6");
            dic.Add(7, "7");

            var keys = dic.Keys;

            Assert.IsNotNull(keys);
            Assert.IsTrue(keys.IsReadOnly);
            Assert.AreEqual(7, keys.Count);
            Assert.IsTrue(keys.Contains(1));
            Assert.IsTrue(keys.Contains(2));
            Assert.IsTrue(keys.Contains(3));
            Assert.IsTrue(keys.Contains(4));
            Assert.IsTrue(keys.Contains(5));
            Assert.IsTrue(keys.Contains(6));
            Assert.IsTrue(keys.Contains(7));

            var values = dic.Values;

            Assert.IsNotNull(values);
            Assert.IsTrue(values.IsReadOnly);
            Assert.AreEqual(7, values.Count);
            Assert.IsTrue(values.Contains("1"));
            Assert.IsTrue(values.Contains("2"));
            Assert.IsTrue(values.Contains("3"));
            Assert.IsTrue(values.Contains("4"));
            Assert.IsTrue(values.Contains("5"));
            Assert.IsTrue(values.Contains("6"));
            Assert.IsTrue(values.Contains("7"));
        }
示例#9
0
        public void TestHugeDictionaryEnumeration()
        {
            // create the huge dictionary.
            var hugeDictionary = new HugeDictionary<long, long>(100);

            for (long idx = 0; idx < 1000; idx++)
            {
                hugeDictionary.Add(idx, idx);
            }

            var items = new List<KeyValuePair<long, long>>(
                hugeDictionary);
            Assert.AreEqual(hugeDictionary.Count, items.Count);
        }
示例#10
0
 /// <summary>
 /// Adds the given coordinate.
 /// </summary>
 /// <param name="idx"></param>
 /// <param name="coordinate"></param>
 public void Add(long idx, ICoordinate coordinate)
 {
     _coordinates.Add(idx, coordinate);
 }