Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Last active January 21, 2021 01:33
Show Gist options
  • Save RinniSwift/72dfd1b58c9f7979d9d39cc68fd17bf7 to your computer and use it in GitHub Desktop.
Save RinniSwift/72dfd1b58c9f7979d9d39cc68fd17bf7 to your computer and use it in GitHub Desktop.
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