Beispiel #1
0
        public LRUCache(int _capacity)
        {
            this.capacity = _capacity;

            //useful nodes between head and tail
            this.head      = new DLinkedNode(0, 0);
            this.tail      = new DLinkedNode(0, 0);
            this.head.next = tail;
            this.tail.prev = head;
        }
Beispiel #2
0
        private void insert(DLinkedNode node)
        {
            //insert to next of head
            map.Add(node.key, node);
            var headNext = head.next;

            head.next     = node;
            node.prev     = head;
            headNext.prev = node;
            node.next     = headNext;
        }
Beispiel #3
0
 private void remove(DLinkedNode node)
 {
     map.Remove(node.key);
     node.prev.next = node.next;
     node.next.prev = node.prev;
 }