Class: DataStructures101::ProbeHashTable
- Inherits:
-
Hash::BaseHashTable
- Object
- Hash::BaseHashTable
- DataStructures101::ProbeHashTable
- Defined in:
- lib/data_structures_101/probe_hash_table.rb
Overview
HashTable implementation using probing strategy for collision-resolution It subclasses Hash::BaseHashTable
Instance Attribute Summary collapse
- #probe_lambda ⇒ Object readonly
Attributes inherited from Hash::BaseHashTable
#capacity, #compression_lambda, #size
Instance Method Summary collapse
-
#initialize(capacity: 31, prime: 109_345_121, compression_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: 109_345_121, compression_lambda: nil, probe_lambda: nil) ⇒ ProbeHashTable
Returns a new instance of ProbeHashTable.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/data_structures_101/probe_hash_table.rb', line 13 def initialize(capacity: 31, prime: 109_345_121, compression_lambda: nil, probe_lambda: nil) super(capacity: capacity, prime: prime, compression_lambda: compression_lambda) @probe_lambda = probe_lambda return unless @probe_lambda.nil? @probe_lambda = ->(h, i, cap) { return (h + i) % cap } end |
Instance Attribute Details
#probe_lambda ⇒ Object (readonly)
11 12 13 |
# File 'lib/data_structures_101/probe_hash_table.rb', line 11 def probe_lambda @probe_lambda end |