コード例 #1
0
 internal bool Contains(long key, object value)
 {
     if (_index.Contains(key))
     {
         EvictionIndexEntry indexEntry = _index[key] as EvictionIndexEntry;
         return(indexEntry.Contains(value));
     }
     return(false);
 }
コード例 #2
0
        internal void Add(long key, object value)
        {
            if (_index.Count == 0)
            {
                _head = key;
            }

            int  add = 0, remove = 0;
            bool incrementKeyCount = true;

            if (_index.Contains(key))
            {
                EvictionIndexEntry indexEntry = (EvictionIndexEntry)_index[key];
                if (indexEntry != null)
                {
                    remove = indexEntry.InMemorySize;

                    if (indexEntry.Contains(value))
                    {
                        incrementKeyCount = false;
                    }


                    indexEntry.Insert(value);

                    add = indexEntry.InMemorySize;
                }
            }
            else
            {
                EvictionIndexEntry indexEntry = new EvictionIndexEntry();
                indexEntry.Insert(value);

                add = indexEntry.InMemorySize;

                _index[key] = indexEntry;

                EvictionIndexEntry prevEntry = _index[_tail] as EvictionIndexEntry;

                if (prevEntry != null)
                {
                    prevEntry.Next = key;
                }
                indexEntry.Previous = _tail;
                _tail = key;
            }

            _evictionIndexEntriesSize -= remove;
            _evictionIndexEntriesSize += add;

            if (incrementKeyCount)
            {
                _keysCount++;
            }
        }
コード例 #3
0
        internal void Remove(long key, object value, ref long currentEntry)
        {
            EvictionIndexEntry previousEntry = null;
            EvictionIndexEntry nextEntry     = null;

            int addSize = 0, removeSize = 0;

            if (_index.Contains(key))
            {
                EvictionIndexEntry indexEntry = (EvictionIndexEntry)_index[key];

                removeSize = indexEntry.InMemorySize;

                if (indexEntry.Previous != -1)
                {
                    previousEntry = (EvictionIndexEntry)_index[indexEntry.Previous];
                }
                if (indexEntry.Next != -1)
                {
                    nextEntry = (EvictionIndexEntry)_index[indexEntry.Next];
                }

                bool decrementKeyCount = indexEntry.Contains(value);

                if (indexEntry.Remove(value))
                {
                    currentEntry = indexEntry.Previous;

                    if (previousEntry != null && nextEntry != null)
                    {
                        previousEntry.Next = indexEntry.Next;
                        nextEntry.Previous = indexEntry.Previous;
                    }
                    else if (previousEntry != null)
                    {
                        previousEntry.Next = indexEntry.Next;
                        _tail = indexEntry.Previous;
                    }
                    else if (nextEntry != null)
                    {
                        nextEntry.Previous = indexEntry.Previous;
                        _head = indexEntry.Next;
                    }
                    else
                    {
                        _tail = _head = -1;
                    }
                    _index.Remove(key);
                }
                else
                {
                    currentEntry = key;
                    addSize      = indexEntry.InMemorySize;
                }

                if (decrementKeyCount)
                {
                    _keysCount--;
                }
            }

            _evictionIndexEntriesSize -= removeSize;
            _evictionIndexEntriesSize += addSize;
        }
コード例 #4
0
        /// <summary>
        /// Add method only adds the new node at the tail...
        /// Insert method can add the new nodes in between also....
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        internal void Insert(long key, object value, long currentKey)
        {
            int  addSize = 0, removeSize = 0;
            bool incrementKeyCount = true;


            if (_index.Contains(key))
            {
                EvictionIndexEntry indexEntry = (EvictionIndexEntry)_index[key];
                if (indexEntry != null)
                {
                    removeSize = indexEntry.InMemorySize;

                    if (indexEntry.Contains(value))
                    {
                        incrementKeyCount = false;
                    }

                    indexEntry.Insert(value);

                    addSize = indexEntry.InMemorySize;
                }
            }
            else
            {
                EvictionIndexEntry currentEntry = (EvictionIndexEntry)_index[currentKey];
                EvictionIndexEntry indexEntry   = new EvictionIndexEntry();
                indexEntry.Insert(value);

                addSize = indexEntry.InMemorySize;

                _index[key] = indexEntry;

                if (currentEntry != null)
                {
                    EvictionIndexEntry nextEntry = _index[currentEntry.Next] as EvictionIndexEntry;

                    if (nextEntry != null)
                    {
                        indexEntry.Next     = currentEntry.Next;
                        indexEntry.Previous = currentKey;

                        currentEntry.Next  = key;
                        nextEntry.Previous = key;
                    }
                    else
                    {
                        currentEntry.Next   = key;
                        indexEntry.Previous = currentKey;

                        if (currentKey == _tail)
                        {
                            _tail = key;
                        }
                    }
                }
                else
                {
                    if (_head == -1)
                    {
                        _head = key;

                        if (_tail == -1)
                        {
                            _tail = key;
                        }
                    }
                    else
                    {
                        EvictionIndexEntry headEntry = (EvictionIndexEntry)_index[_head];

                        indexEntry.Next    = _head;
                        headEntry.Previous = key;
                        _head = key;
                    }
                }
            }

            _evictionIndexEntriesSize -= removeSize;
            _evictionIndexEntriesSize += addSize;

            if (incrementKeyCount)
            {
                _keysCount++;
            }
        }