(int key, int value)
| 55 | } |
| 56 | |
| 57 | public void Put(int key, int value) |
| 58 | { |
| 59 | // If a node with this key already exists, remove it from the linked list. |
| 60 | if (_hashMap.ContainsKey(key)) |
| 61 | removeNode(_hashMap[key]); |
| 62 | |
| 63 | DoublyLinkedListNode node = new DoublyLinkedListNode(key, value); |
| 64 | _hashMap[key] = node; |
| 65 | |
| 66 | // Remove the least recently used node from the cache if adding |
| 67 | // this new node will result in an overflow. |
| 68 | if (_hashMap.Count > _capacity) |
| 69 | { |
| 70 | _hashMap.Remove(_head.Next.Key); |
| 71 | removeNode(_head.Next); |
| 72 | } |
| 73 | |
| 74 | addToTail(node); |
| 75 | } |
| 76 | |
| 77 | private void addToTail(DoublyLinkedListNode node) |
| 78 | { |
nothing calls this directly
no outgoing calls
no test coverage detected