Example #1
0
        public IEnumerator <KeyValuePair <string, TValue> > GetEnumerator()
        {
            HashNode <TValue> current = Head;

            while (current != null)
            {
                yield return(new KeyValuePair <string, TValue>(current.Key, current.Value));

                current = current.Next;
            }
        }
Example #2
0
        public TValue KeyValue(string key)
        {
            HashNode <TValue> current = Head;

            while (current != null)
            {
                if (current.Key == key)
                {
                    return(current.Value);
                }
                current = current.Next;
            }
            throw new KeyNotFoundException();
        }
Example #3
0
        public bool Includes(string key)
        {
            HashNode <TValue> current = Head;

            while (current != null)
            {
                if (current.Key == key)
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Example #4
0
        public void Insert(string key, int hash, TValue value)
        {
            HashNode <TValue> newNode = new HashNode <TValue>(Bucket, key, hash, value);

            if (Head != null)
            {
                Helper(newNode);
                newNode.Next.Last = newNode;
            }
            else
            {
                Helper(newNode);
            }
        }
Example #5
0
        public void Remove(string key)
        {
            HashNode <TValue> current = Head;

            while (current != null)
            {
                if (current.Key == key && Head != current)
                {
                    current.Last.Next = current.Next;
                    current.Next.Last = current.Last;
                    Head = current.Next;
                }
                if (current.Key == key && Head == current)
                {
                    Head = current.Next;
                }
                current = current.Next;
            }
        }
Example #6
0
 private void Helper(HashNode <TValue> newNode)
 {
     newNode.Next = Head;
     Head         = newNode;
 }