Esempio n. 1
0
        public uint Add(TKey key, TValue value)
        {
            uint i;
            ChainList <KeyValuePair <TKey, TValue> > chainList;

            var node = GetNode(key, out i, out chainList);

            if (node != null)
            {
                throw new DuplicateKeyException("Key \"" + node.element.Key + "\" 已经存在 。");
            }

            if (chainList == null)
            {
                chainList   = new ChainList <KeyValuePair <TKey, TValue> >();
                this.arr[i] = chainList;
            }

            var pair = new KeyValuePair <TKey, TValue>(key, value);

            chainList.Add(pair);

            node          = new ChainListNode <KeyValuePair <TKey, TValue> >(pair);
            pair.listNode = node;
            this.list.Add(node);

            return(i);
        }
Esempio n. 2
0
        bool System.Collections.IEnumerator.MoveNext()
        {
            if (this.current == null)
            {
                if (this.list.head == null)
                {
                    return(false);
                }

                this.current = this.list.head;

                return(true);
            }

            if (this.current.next == null)
            {
                return(false);
            }

            this.current = this.current.next;

            return(true);

            //throw new NotImplementedException();
        }
Esempio n. 3
0
        public void Remove(ChainListNode <T> node)
        {
            if (node == this.head && node == this.tail)
            {
                this.head = null;
                this.tail = null;

                this.count--;

                return;
            }

            if (node == this.tail)
            {
                this.tail = node.before;

                node.before.next = null;
                node.before      = null;

                this.count--;

                return;
            }

            if (node == this.head)
            {
                if (node.next == null)
                {
                    this.head = null;
                    this.tail = null;

                    this.count = 0;

                    return;
                }

                this.head = node.next;

                node.next.before = null;
                node.next        = null;

                this.count--;

                return;
            }

            node.before.next = node.next;
            node.next.before = node.before;
            node.before      = null;
            node.next        = null;

            this.count--;
        }
Esempio n. 4
0
        public void Add(ChainListNode <T> node)
        {
            if (this.count == 0)
            {
                this.head = node;
                this.tail = node;

                this.count++;

                return;
            }

            node.before    = this.tail;
            this.tail.next = node;
            this.tail      = node;

            this.count++;
        }
Esempio n. 5
0
        public void Add(T element)
        {
            var node = new ChainListNode <T>(element);

            Add(node);
        }
Esempio n. 6
0
 void System.Collections.IEnumerator.Reset()
 {
     this.current = null;
     //throw new NotImplementedException();
 }