protected void MoveToTail(NuGenCacheEntry e) { // tail element if (e == tail) { return; } // head element if (e == head) { head = head.next; tail.next = e; e.prev = tail; e.next = null; tail = e; return; } // inner element e.prev.next = e.next; e.next.prev = e.prev; tail.next = e; e.prev = tail; e.next = null; tail = e; }
public object Get(object key) { if (!hashtable.ContainsKey(key)) { return(null); } NuGenCacheEntry e = (NuGenCacheEntry)hashtable[key]; MoveToTail(e); return(e.val); }
public void Insert(object key, object val) { // if key exists replace it and return if (hashtable.ContainsKey(key)) { ((NuGenCacheEntry)hashtable[key]).val = val; return; } // remove lru entry if element count equals capacity if (size == capacity) RemoveFromHead(); NuGenCacheEntry e = new NuGenCacheEntry(key, val); AddToTail(e); hashtable[key] = e; }
protected void AddToTail(NuGenCacheEntry e) { size++; if (tail == null) { head = tail = e; e.prev = null; e.next = null; return; } tail.next = e; e.prev = tail; e.next = null; tail = e; }
public void Insert(object key, object val) { // if key exists replace it and return if (hashtable.ContainsKey(key)) { ((NuGenCacheEntry)hashtable[key]).val = val; return; } // remove lru entry if element count equals capacity if (size == capacity) { RemoveFromHead(); } NuGenCacheEntry e = new NuGenCacheEntry(key, val); AddToTail(e); hashtable[key] = e; }
protected void MoveToTail(NuGenCacheEntry e) { // tail element if (e == tail) return; // head element if (e == head) { head = head.next; tail.next = e; e.prev = tail; e.next = null; tail = e; return; } // inner element e.prev.next = e.next; e.next.prev = e.prev; tail.next = e; e.prev = tail; e.next = null; tail = e; }