MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / ~LRUCache

Method ~LRUCache

cpp/Linked Lists/lru_cache.cpp:31–41  ·  view source on GitHub ↗

Destructor: Cleans up dynamically allocated resources to prevent memory leaks. Implemented if time permits during an interview.

Source from the content-addressed store, hash-verified

29 // to prevent memory leaks. Implemented if time permits
30 // during an interview.
31 ~LRUCache() {
32 // Delete all nodes in the linked list.
33 DoublyLinkedListNode* current = head;
34 while (current != nullptr) {
35 DoublyLinkedListNode* nextNode = current->next;
36 delete current;
37 current = nextNode;
38 }
39 // Clear the hashmap.
40 hashmap.clear();
41 }
42
43 int get(int key) {
44 if (hashmap.find(key) == hashmap.end()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected