/// <summary> /// Adds the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Add(K key, V value) { // Get the index of key using hashcode int index = GetArrayPosition(key); // Get the linkedlist of respective index LinkedList <MyMapNode <K, V> > linkedList = GetLinkedList(index); // Add the element MyMapNode <K, V> item = new MyMapNode <K, V>() { Key = key, Value = value }; linkedList.AddLast(item); Console.WriteLine(item.Key + " " + item.Value); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { Function function = new Function(); string paragraph = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; //Split converts paragraph into array of sub strings string[] para = paragraph.Split(" "); MyMapNode <int, string> hash = new MyMapNode <int, string>(para.Length); MyMapNode <int, string> hash1 = new MyMapNode <int, string>(para.Length); int key = 0; //Loop iterates on paragraph and adds key and value of each substing //To hash foreach (string word in para) { hash.Add(key, word); hash1.Add(key, word); key++; } //Removes specific word function.Remove(hash, "paranoid"); }
public void Remove(K key) { // Get the index of key using hashcode int index = GetArrayPosition(key); // Get the linkedlist of respective index LinkedList <MyMapNode <K, V> > linkedList = GetLinkedList(index); bool itemFound = false; MyMapNode <K, V> foundItem = default(MyMapNode <K, V>); // Search for item to be removed foreach (MyMapNode <K, V> item in linkedList) { if (item.Key.Equals(key)) { itemFound = true; foundItem = item; } } if (itemFound) { linkedList.Remove(foundItem); } }