Exemplo n.º 1
0
        public override void Store(string name, object value)
        {
            int num = hash(name);

            if (vals[num] == null)
            {
                vals[num] = new Node(name, value);
            }
            else
            {
                Node temp = vals[num];
                Node prev = null;
                bool done = false;
                while (temp != null)
                {
                    if (temp.getKey() == name)
                    {
                        temp.setPair(name, value);
                        done = true;
                    }
                    prev = temp;
                    temp = temp.getNext();
                }
                if (!done)
                {
                    prev.setNext(new Node(name, value));
                }
            }
            count++;
        }
Exemplo n.º 2
0
 public override IEnumerator <KeyValuePair <string, object> > GetEnumerator()
 {
     for (Node temp = head; temp != null; temp = temp.getNext())
     {
         yield return(new KeyValuePair <string, object>(temp.getKey(), temp.getValue()));
     }
 }
Exemplo n.º 3
0
        public override object Lookup(string key)
        {
            Node temp = head;

            while (temp != null)
            {
                if (temp.getKey() == key)
                {
                    return(temp.getValue());
                }
                temp = temp.getNext();
            }
            throw new DictionaryKeyNotFoundException(key);
        }
Exemplo n.º 4
0
        public override object Lookup(string name)
        {
            int  num  = hash(name);
            Node temp = vals[num];

            while (temp != null)
            {
                if (temp.getKey() == name)
                {
                    return(temp.getValue());
                }
                temp = temp.getNext();
            }
            throw new DictionaryKeyNotFoundException(name);
        }
Exemplo n.º 5
0
        public override void Store(string key, object value)
        {
            Node temp = head;
            Node prev = temp;

            if (head == null)
            {
                head = new Node(key, value);
                length++;
                return;
            }
            while (temp != null)
            {
                if (temp.getKey() == key)
                {
                    temp.setPair(key, value);
                    return;
                }
                prev = temp;
                temp = temp.getNext();
            }
            prev.setNext(new Node(key, value));
            length++;
        }