public int Get(int key) { if (!map.ContainsKey(key)) return -1; LRUNode node = map[key]; doubleLinkedList.RemoveNode(node); doubleLinkedList.AddToTop(node); return node.Value; }
/// <summary> /// LRU - put least recently used - last one out /// </summary> /// <param name="key"></param> /// <returns></returns> public int Get(int key) { if (!map.ContainsKey(key)) { return(-1); } var node = map[key]; list.RemoveNode(node); list.AddToTail(node); // tip 1: node is still the same in map, no need to update return(node.Value); }