Skip to content

Instantly share code, notes, and snippets.

@skv-headless
Created November 13, 2014 08:37
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 skv-headless/a399cbc8f02895f3062e to your computer and use it in GitHub Desktop.
Save skv-headless/a399cbc8f02895f3062e to your computer and use it in GitHub Desktop.
simple hash
class HashTable
def initialize
@bins = Array.new(11)
end
def [](key)
@bins[bin_num(key)]
end
def []=(key, value)
@bins[bin_num(key)] = value
end
def bin_num(key)
key.hash % @bins.length
end
end
hash = HashTable.new
hash[:hello] = 123
p hash[:hello]
p hash['hello']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment