Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
 /// <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);
            }
        }
Esempio n. 5
0
 public KVNode(string key, string value)
 {
     Key   = key;
     Value = value;
     Next  = null;
 }