예제 #1
0
        public virtual object Purge(object key)
        {
            long longKey = (((long)key));

            LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Remove(longKey);
            if (entry == null)
            {
                return(null);
            }
            _size--;
            if (_first == entry)
            {
                _first = entry._next;
            }
            if (_last == entry)
            {
                _last = entry._previous;
            }
            if (entry._previous != null)
            {
                entry._previous._next = entry._next;
            }
            if (entry._next != null)
            {
                entry._next._previous = entry._previous;
            }
            return((object)entry._value);
        }
예제 #2
0
 public bool MoveNext()
 {
     if (this._cursor == null)
     {
         this._current = null;
         return(false);
     }
     this._current = this._cursor;
     this._cursor  = this._cursor._next;
     return(true);
 }
예제 #3
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			long longKey = (((long)key));
			if (_last == null)
			{
				object lastValue = producer.Apply(((long)key));
				if (lastValue == null)
				{
					return null;
				}
				_size = 1;
				LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue);
				_slots.Put(longKey, lastEntry);
				_first = lastEntry;
				_last = lastEntry;
				return lastValue;
			}
			LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey);
			if (entry == null)
			{
				if (_size >= _maxSize)
				{
					LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key);
					_last = oldEntry._previous;
					_last._next = null;
					if (null != finalizer)
					{
						finalizer.Apply((object)oldEntry._value);
					}
					_size--;
				}
				object newValue = producer.Apply(((long)key));
				if (newValue == null)
				{
					return null;
				}
				_size++;
				LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue);
				_slots.Put(longKey, newEntry);
				_first._previous = newEntry;
				newEntry._next = _first;
				_first = newEntry;
				return newValue;
			}
			if (_first == entry)
			{
				return ((object)entry._value);
			}
			LRULongCache.Entry previous = entry._previous;
			entry._previous = null;
			if (_last == entry)
			{
				_last = previous;
			}
			previous._next = entry._next;
			if (previous._next != null)
			{
				previous._next._previous = previous;
			}
			_first._previous = entry;
			entry._next = _first;
			_first = entry;
			return ((object)entry._value);
		}
예제 #4
0
		public virtual object Purge(object key)
		{
			long longKey = (((long)key));
			LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Remove(longKey);
			if (entry == null)
			{
				return null;
			}
			_size--;
			if (_first == entry)
			{
				_first = entry._next;
			}
			if (_last == entry)
			{
				_last = entry._previous;
			}
			if (entry._previous != null)
			{
				entry._previous._next = entry._next;
			}
			if (entry._next != null)
			{
				entry._next._previous = entry._previous;
			}
			return ((object)entry._value);
		}
예제 #5
0
			public void Reset()
			{
				this._cursor = this._enclosing._first;
				this._current = null;
			}
예제 #6
0
			public bool MoveNext()
			{
				if (this._cursor == null)
				{
					this._current = null;
					return false;
				}
				this._current = this._cursor;
				this._cursor = this._cursor._next;
				return true;
			}
예제 #7
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            long longKey = (((long)key));

            if (_last == null)
            {
                object lastValue = producer.Apply(((long)key));
                if (lastValue == null)
                {
                    return(null);
                }
                _size = 1;
                LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue);
                _slots.Put(longKey, lastEntry);
                _first = lastEntry;
                _last  = lastEntry;
                return(lastValue);
            }
            LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey);
            if (entry == null)
            {
                if (_size >= _maxSize)
                {
                    LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key);
                    _last       = oldEntry._previous;
                    _last._next = null;
                    if (null != finalizer)
                    {
                        finalizer.Apply((object)oldEntry._value);
                    }
                    _size--;
                }
                object newValue = producer.Apply(((long)key));
                if (newValue == null)
                {
                    return(null);
                }
                _size++;
                LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue);
                _slots.Put(longKey, newEntry);
                _first._previous = newEntry;
                newEntry._next   = _first;
                _first           = newEntry;
                return(newValue);
            }
            if (_first == entry)
            {
                return((object)entry._value);
            }
            LRULongCache.Entry previous = entry._previous;
            entry._previous = null;
            if (_last == entry)
            {
                _last = previous;
            }
            previous._next = entry._next;
            if (previous._next != null)
            {
                previous._next._previous = previous;
            }
            _first._previous = entry;
            entry._next      = _first;
            _first           = entry;
            return((object)entry._value);
        }
예제 #8
0
 public void Reset()
 {
     this._cursor  = this._enclosing._first;
     this._current = null;
 }