Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created Feb 28, 2013
Embed
What would you like to do?
Add to the LRU cache.
public void Add(TKey key, TValue value)
{
Prune();
if (_dict.ContainsKey(key))
{
_list.Remove(_dict[key]);
_dict.Remove(key);
}
var ts = new TimeStamped(value);
var kv = new KeyValuePair(key, ts);
var node = new LinkedListNode(ts);
_list.AddFirst(node);
_dict[key] = node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment