public void evictNode(KeyValuePair <K, T> pairToEvict, CacheNode <K, T> newNode) { int evictionSetIndex = hashKey(pairToEvict.key); T evictedValue = pairToEvict.value; CacheNode <K, T> head = setHeads[evictionSetIndex]; CacheNode <K, T> currentNode = head; while (currentNode.value != null) { if (currentNode.value.Equals(evictedValue)) { head.prev = newNode; newNode.next = head; currentNode.removeNode(); setHeads[evictionSetIndex] = newNode; } currentNode = currentNode.next; } }
public T get(K key) { int placementSet = hashKey(key); CacheNode <K, T> head = setHeads[placementSet]; CacheNode <K, T> currentNode = head; // The following loop checks the nodes in the set that the key // hashes to. On a hit, the node matching the key is set as the new // head and removed from its former placement. while (currentNode.key != null) { if (currentNode.key.Equals(key)) { head.prev = currentNode; setHeads[placementSet] = currentNode; currentNode.removeNode(); return(currentNode.value); } currentNode = currentNode.next; } // On a miss, the cache returns null. return(default(T)); }