Example #1
0
 public void LruList_RemoveOneItem()
 {
     var lruList = new LruList<string, string>();
     var item1 = new LruListItem<string, string>("key1", "value1");
     lruList.Add(item1);
     lruList.Remove(item1);
     AssertDisconnected(item1);
     AssertListState(lruList);
 }
Example #2
0
        public void LruList_RemoveOneItem()
        {
            var lruList = new LruList <string, string>();
            var item1   = new LruListItem <string, string>("key1", "value1");

            lruList.Add(item1);
            lruList.Remove(item1);
            AssertDisconnected(item1);
            AssertListState(lruList);
        }
Example #3
0
 public void LruList_RemoveTailTwoItems()
 {
     var lruList = new LruList<string, string>();
     var item1 = new LruListItem<string, string>("key1", "value1");
     var item2 = new LruListItem<string, string>("key2", "value2");
     lruList.Add(item1);
     lruList.Add(item2);
     lruList.Remove(item1);
     AssertDisconnected(item1);
     AssertListState(lruList, item2);
 }
Example #4
0
        public void LruList_RemoveTailTwoItems()
        {
            var lruList = new LruList <string, string>();
            var item1   = new LruListItem <string, string>("key1", "value1");
            var item2   = new LruListItem <string, string>("key2", "value2");

            lruList.Add(item1);
            lruList.Add(item2);
            lruList.Remove(item1);
            AssertDisconnected(item1);
            AssertListState(lruList, item2);
        }
        protected override void InsertCore(TKey key, LinkedListNode <KeyValuePair <TKey, TValue> > newNode)
        {
            base.InsertCore(key, newNode);
            var value = newNode.Value.Value;

            // if there was a node already with same distinct value we need to remove it
            if (_distinctDictionary.TryGetValue(value, out var oldNode))
            {
                LruList.Remove(oldNode);
                Remove(oldNode.Value.Key);
            }

            _distinctDictionary[value] = newNode;
        }