Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created May 23, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/a9c81183c9124c8370b315b28f4b61ad to your computer and use it in GitHub Desktop.
Save chelseatroy/a9c81183c9124c8370b315b28f4b61ad to your computer and use it in GitHub Desktop.
Deletion Implementation
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