Beispiel #1
0
        public virtual MruNode <V> Add(V item)
        {
            var node = new MruNode <V>(item, this);

            try
            {
                SlimLock.EnterWriteLock();
                node.Next = Head;
                Tail      = Tail ?? node;
                if (Head != null)
                {
                    Head.Previous = node;
                }
                Head = node;
                ItemCount++;

                if (ItemCount > Limit)
                {
                    var deleted = Tail;
                    if (Tail != null)
                    {
                        Tail = Tail.Previous;
                        deleted.Erase();
                    }
                    ItemCount--;
                }
            }
            finally
            {
                SlimLock.ExitWriteLock();
            }
            return(node);
        }
 public void Remove(TKey key)
 {
     try
     {
         SlimLock.EnterWriteLock();
         TValue value;
         Dictionary.TryRemove(key, out value);
     }
     finally
     {
         SlimLock.ExitWriteLock();
     }
 }
Beispiel #3
0
 public virtual void Clear()
 {
     try
     {
         SlimLock.EnterWriteLock();
         var node = Head;
         while (node != null)
         {
             var old = node;
             node = node.Next;
             old.Erase();
         }
         ItemCount = 0;
         Head      = null;
         Tail      = null;
     }
     finally
     {
         SlimLock.ExitWriteLock();
     }
 }