Exemple #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;
            }
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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;
            }
        }
Exemple #6
0
 private void Helper(HashNode <TValue> newNode)
 {
     newNode.Next = Head;
     Head         = newNode;
 }