Пример #1
0
 public KeyCollection(HashMap <WeakKey <TKey>, TValue> dict)
 {
     _internalDict = dict;
 }
Пример #2
0
 public LinkedHashMap(int capacity, IEqualityComparer <TKey> comparer)
 {
     dict = new HashMap <TKey, LinkedListNode <KeyValuePair <TKey, TValue> > >(capacity, comparer);
     list = new LinkedList <KeyValuePair <TKey, TValue> >();
 }
Пример #3
0
        public void TestEqualityDictionary()
        {
            var control = new Dictionary <string, IDictionary <HashMap <long, double>, string> >
            {
                { "a", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 123, 9.87 }, { 80, 88 }
                        }, "qwerty" }
                  } },
                { "z", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 456, 9.86 }, { 81, 88 }
                        }, "hexagon" }
                  } },
                { "r", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 789, 9.85 }, { 82, 88 }
                        }, "parasite" }
                  } },
                { "t", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 101, 9.84 }, { 83, 88 }
                        }, "octopus" }
                  } },
            };
            var equal = new Dictionary <string, IDictionary <HashMap <long, double>, string> >
            {
                { "a", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 123, 9.87 }, { 80, 88 }
                        }, "qwerty" }
                  } },
                { "z", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 456, 9.86 }, { 81, 88 }
                        }, "hexagon" }
                  } },
                { "r", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 789, 9.85 }, { 82, 88 }
                        }, "parasite" }
                  } },
                { "t", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 101, 9.84 }, { 83, 88 }
                        }, "octopus" }
                  } },
            };
            var equalDifferentType = new HashMap <string, IDictionary <HashMap <long, double>, string> >
            {
                { "a", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 123, 9.87 }, { 80, 88 }
                        }, "qwerty" }
                  } },
                { "z", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 456, 9.86 }, { 81, 88 }
                        }, "hexagon" }
                  } },
                { "r", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 789, 9.85 }, { 82, 88 }
                        }, "parasite" }
                  } },
                { "t", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 101, 9.84 }, { 83, 88 }
                        }, "octopus" }
                  } },
            };
            var equalDifferentOrder = new Dictionary <string, IDictionary <HashMap <long, double>, string> >
            {
                { "r", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 789, 9.85 }, { 82, 88 }
                        }, "parasite" }
                  } },
                { "t", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 101, 9.84 }, { 83, 88 }
                        }, "octopus" }
                  } },
                { "a", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 123, 9.87 }, { 80, 88 }
                        }, "qwerty" }
                  } },
                { "z", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 456, 9.86 }, { 81, 88 }
                        }, "hexagon" }
                  } },
            };

            var level1EqualLevel2EqualLevel3Unequal = new Dictionary <string, IDictionary <HashMap <long, double>, string> >
            {
                { "a", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 123, 9.87 }, { 80, 88.1 }
                        }, "qwerty" }
                  } },
                { "z", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 456, 9.86 }, { 81, 88 }
                        }, "hexagon" }
                  } },
                { "r", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 789, 9.85 }, { 82, 88 }
                        }, "parasite" }
                  } },
                { "t", new Dictionary <HashMap <long, double>, string> {
                      { new HashMap <long, double> {
                            { 101, 9.84 }, { 83, 88 }
                        }, "octopus" }
                  } },
            };

            Assert.AreEqual(Collections.GetHashCode(control), Collections.GetHashCode(control));
            Assert.IsTrue(Collections.Equals(control, control));

            Assert.AreEqual(Collections.GetHashCode(control), Collections.GetHashCode(equal));
            Assert.IsTrue(Collections.Equals(control, equal));

            Assert.AreEqual(Collections.GetHashCode(control), Collections.GetHashCode(equalDifferentType));
            Assert.IsTrue(Collections.Equals(control, equalDifferentType));

            Assert.AreEqual(Collections.GetHashCode(control), Collections.GetHashCode(equalDifferentOrder));
            Assert.IsTrue(Collections.Equals(control, equalDifferentOrder));

            Assert.AreNotEqual(Collections.GetHashCode(control), Collections.GetHashCode(level1EqualLevel2EqualLevel3Unequal));
            Assert.IsFalse(Collections.Equals(control, level1EqualLevel2EqualLevel3Unequal));
        }
Пример #4
0
 public LinkedHashMap(int capacity)
 {
     dict = new HashMap <TKey, LinkedListNode <KeyValuePair <TKey, TValue> > >(capacity);
     list = new LinkedList <KeyValuePair <TKey, TValue> >();
 }