/// <summary> /// adds key value node to linked list /// </summary> /// <param name="key">key</param> /// <param name="value">value</param> public void Insert(string key, string value) { KVNode node = new KVNode(key, value); node.Next = Head; Head = node; }
/// <summary> /// checks if key is in linked list /// </summary> /// <param name="key">the key</param> /// <returns>true if found, false otherwise</returns> public bool Includes(string key) { Current = Head; if (Head == null) { return(false); } else { while (Current.Next != null) { if (Current.Key == key) { return(true); } Current = Current.Next; } if (Current.Key == key) { return(true); } return(false); } }
/// <summary> /// adds a node to the end of the linked list /// </summary> /// <param name="node">the node to add</param> public void Append(KVNode node) { Current = Head; while (Current.Next != null) { Current = Current.Next; } Current.Next = node; }
//methods /// <summary> /// Adds a new key value pair to hash table /// </summary> /// <param name="key">the key</param> /// <param name="value">the value</param> public void AddToHashTable(string key, string value) { int hashIndex = Hash(key); if (HashTableArray[hashIndex] == null) { KVNodeLinkList tempLL = new KVNodeLinkList(); HashTableArray[hashIndex] = tempLL; HashTableArray[hashIndex].Insert(key, value); } else { KVNode newNode = new KVNode(key, value); HashTableArray[hashIndex].Append(newNode); } }
public KVNode(string key, string value) { Key = key; Value = value; Next = null; }