Last active
January 21, 2021 01:33
-
-
Save RinniSwift/72dfd1b58c9f7979d9d39cc68fd17bf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LRUCache<T: Hashable, U> { | |
/// Total capacity of the LRU cache. | |
private(set) var capacity: UInt | |
/// LinkedList will store elements that are most accessed at the head and least accessed at the tail. | |
private(set) var linkedList = DoublyLinkedList<CachePayload<T, U>>() | |
/// Dictionary that will store the element, U, at the specified key. | |
private(set) var dictionary = [T: Node<CachePayload<T, U>>]() | |
/// LRUCache requires a capacity which must be greater than 0 | |
required init(capacity: UInt) { | |
self.capacity = capacity | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment