Example #1
0
 public LinkMap()
 {
     this.head      = new LinkMapNode <K, V>();
     this.tail      = new LinkMapNode <K, V>();
     this.head.prev = this.head.next = tail;
     this.tail.prev = this.tail.next = head;
 }
Example #2
0
        public Collection <V> values()
        {
            Collection <V>     vs   = new Collection <V>();
            LinkMapNode <K, V> temp = head.next;

            for (; ;)
            {
                if (temp == tail)
                {
                    return(vs);
                }
                vs.Add(temp.getV());
                temp = temp.next;
            }
        }
Example #3
0
        public Collection <K> keys()
        {
            Collection <K>     ks   = new Collection <K>();
            LinkMapNode <K, V> temp = head.next;

            for (; ;)
            {
                if (temp == tail)
                {
                    return(ks);
                }
                ks.Add(temp.getK());
                temp = temp.next;
            }
        }
Example #4
0
        public IEnumerable <LinkMapNode <K, V> > getNodeOneByOne()
        {
            LinkMapNode <K, V> temp = tail.prev;

            for (; ;)
            {
                if (temp == head)
                {
                    break;
                }
                yield return(temp);

                temp = temp.prev;
            }
        }
Example #5
0
        public LinkMapNode <K, V> getNode(K key)
        {
            LinkMapNode <K, V> temp = tail.prev;

            for (; ;)
            {
                if (temp == head)
                {
                    return(null);
                }
                if (key.Equals(temp.getK()))
                {
                    return(temp);
                }
                temp = temp.prev;
            }
        }
Example #6
0
        public V get(K key)
        {
            LinkMapNode <K, V> temp = head.next;

            for (; ;)
            {
                if (temp == tail)
                {
                    return(default(V));
                }
                if (key.Equals(temp.getK()) && temp != tail && temp != head)
                {
                    return(temp.getV());
                }
                temp = temp.next;
            }
        }
Example #7
0
        public bool containsValue(V value)
        {
            LinkMapNode <K, V> temp = head.next;

            for (; ;)
            {
                if (temp == tail)
                {
                    return(false);
                }
                if (value.Equals(temp.getV()))
                {
                    return(true);
                }
                temp = temp.next;
            }
        }
Example #8
0
        public bool containsKey(K key)
        {
            LinkMapNode <K, V> temp = head.next;

            for (; ;)
            {
                if (temp == tail)
                {
                    return(false);
                }
                if (key.Equals(temp.getK()))
                {
                    return(true);
                }
                temp = temp.next;
            }
        }
Example #9
0
        public V remove(K key)
        {
            V v = default(V);

            if (containsKey(key))
            {
                lock (tail)
                {
                    LinkMapNode <K, V> temp = getNode(key);
                    if (null != temp)
                    {
                        temp.prev.next = temp.next;
                        temp.next.prev = temp.prev;
                        //lock (sizeLock)
                        //{
                        size--;
                        //}
                    }
                }
            }
            return(v);
        }
Example #10
0
        public V put(K key, V value)
        {
            V v = default(V);
            LinkMapNode <K, V> temp = getNode(key);

            if (null == temp)
            {
                LinkMapNode <K, V> node = new LinkMapNode <K, V>(key, value);
                lock (tail.prev)
                {
                    temp = getNode(key);
                    if (null == temp)
                    {
                        node.next      = tail;
                        tail.prev.next = node;
                        node.prev      = tail.prev;
                        tail.prev      = node;
                        //lock (sizeLock)
                        //{
                        size++;
                        //}
                    }
                    else
                    {
                        v = temp.setV(value);
                    }
                }
            }
            else
            {
                ///保证后赢者赢
                lock (temp)
                {
                    v = temp.setV(value);
                }
            }
            return(v);
        }