public void MoveToHeadTest() { LRUDoublyLinkedList dll = new LRUDoublyLinkedList(); Node n0 = new Node(null, null, new Element(new byte[0]), 0); dll.Insert(n0); dll.MoveToHead(n0); Assert.AreEqual(n0, dll.Get(0)); Assert.AreEqual(1, dll.Size); Node n1 = new Node(null, null, new Element(new byte[0]), 1); dll.Insert(n1); dll.MoveToHead(n0); Assert.AreEqual(n0, dll.Get(0)); Assert.AreEqual(2, dll.Size); Node n2 = new Node(null, null, new Element(new byte[0]), 2); dll.Insert(n2); dll.MoveToHead(n0); Assert.AreEqual(n0, dll.Get(0)); Assert.AreEqual(3, dll.Size); }
public void AddToCache(Element element, int elementIdx) { Node cachedNode; if (_index.TryGetValue(elementIdx, out cachedNode)) { cachedNode.SetElement(element); _cacheList.MoveToHead(cachedNode); } else { Node node = new Node(null, null, element, elementIdx); _cacheList.Insert(node); _index.Add(elementIdx, node); } if (_cacheList.Size > _cacheSize) { RemoveLast(); } }