Created
May 23, 2019 16:41
-
-
Save chelseatroy/a9c81183c9124c8370b315b28f4b61ad to your computer and use it in GitHub Desktop.
Deletion Implementation
This file contains 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 Database | |
def initialize | |
@count = Hash.new(0) | |
@db = Hash.new() | |
end | |
# CRUD COMMANDS | |
def set(key, value) | |
@db[key] = value | |
@count[value] += 1 | |
return nil | |
end | |
def get(key) | |
@db.fetch(key, "NULL") | |
end | |
def count(value) | |
@count.fetch(value, 0) | |
end | |
def delete(key) | |
value = @db[key] | |
if value | |
@db.delete(key) | |
@count[value] -= 1 | |
return nil | |
else | |
return "That key isn't in the database!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment