Esempio n. 1
0
        public void Add(string key, string value)
        {
            int hashKey = Hash(key, this.Map);

            if (Map[hashKey] == null)
            {
                Map[hashKey] = new DataStructures2.LinkedList <KeyValuePair <string, string> >();
            }

            KeyValuePair <string, string> entry = new KeyValuePair <string, string>(key, value);

            Map[hashKey].Insert(entry);
        }
        public void Test_Successfully_Handles_Collision()
        {
            HashMap testMap = new HashMap(2);

            string testKey1 = "key";
            string testVal1 = "val";
            string testKey2 = "key";
            string testVal2 = "otherVal";
            KeyValuePair <string, string> testKVP1 = new KeyValuePair <string, string>(testKey1, testVal1);
            KeyValuePair <string, string> testKVP2 = new KeyValuePair <string, string>(testKey2, testVal2);

            testMap.Add(testKey1, testVal1);

            testMap.Add(testKey2, testVal2);

            DataStructures2.LinkedList <KeyValuePair <string, string> > expectedList = new DataStructures2.LinkedList <KeyValuePair <string, string> >();
            expectedList.Insert(testKVP1);
            expectedList.Insert(testKVP2);

            Assert.Equal(testMap.Map[1], expectedList);
        }