Skip to content

Instantly share code, notes, and snippets.

@the-spectator
Created October 29, 2020 18:16
Show Gist options
  • Save the-spectator/d4218e355d2ad894feaf8ce66b7b6b9f to your computer and use it in GitHub Desktop.
Save the-spectator/d4218e355d2ad894feaf8ce66b7b6b9f to your computer and use it in GitHub Desktop.
class LRUCache
attr_reader :lookup, :size
def initialize(size)
@lookup = {}
@size = size
end
def get(key)
return unless lookup[key]
lookup[key] = lookup.delete(key)
end
def set(key, value)
lookup.shift if lookup.size > size
lookup.delete(key)
lookup[key] = value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment