Class: DataStructures101::ProbeHashTable
- Inherits:
-
Hash::BaseHashTable
- Object
- Hash::BaseHashTable
- DataStructures101::ProbeHashTable
- Defined in:
- lib/data_structures_101/probe_hash_table.rb
Instance Attribute Summary collapse
-
#probe_lambda ⇒ Object
readonly
Returns the value of attribute probe_lambda.
Attributes inherited from Hash::BaseHashTable
#capacity, #hash_lambda, #size
Instance Method Summary collapse
-
#initialize(capacity = 31, prime = 109345121, hash_lambda = nil, probe_lambda = nil) ⇒ ProbeHashTable
constructor
A new instance of ProbeHashTable.
Methods inherited from Hash::BaseHashTable
#[], #[]=, #delete, #each, #insert
Constructor Details
#initialize(capacity = 31, prime = 109345121, hash_lambda = nil, probe_lambda = nil) ⇒ ProbeHashTable
Returns a new instance of ProbeHashTable.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/data_structures_101/probe_hash_table.rb', line 8 def initialize(capacity = 31, prime = 109345121, hash_lambda = nil, probe_lambda = nil) super(capacity, prime, hash_lambda) @probe_lambda = if probe_lambda.nil? ->(h, i) { return (h + i) % @capacity } else probe_lambda end end |
Instance Attribute Details
#probe_lambda ⇒ Object (readonly)
Returns the value of attribute probe_lambda.
6 7 8 |
# File 'lib/data_structures_101/probe_hash_table.rb', line 6 def probe_lambda @probe_lambda end |