Class: DataStructures101::ProbeHashTable

Inherits:
Hash::BaseHashTable show all
Defined in:
lib/data_structures_101/probe_hash_table.rb

Overview

HashTable implementation using probing strategy for collision-resolution It subclasses Hash::BaseHashTable

Author:

  • Rene Hernandez

Since:

  • 0.2

Instance Attribute Summary collapse

Attributes inherited from Hash::BaseHashTable

#capacity, #compression_lambda, #size

Instance Method Summary collapse

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.

Since:

  • 0.2



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_lambdaObject (readonly)

Since:

  • 0.2



11
12
13
# File 'lib/data_structures_101/probe_hash_table.rb', line 11

def probe_lambda
  @probe_lambda
end