Class: HashTable::StringHashTraits

Inherits:
StringIdentityHashTraits show all
Defined in:
lib/hashtable/traits.rb

Overview

StringHashTraits

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StringIdentityHashTraits

#hash_lookup_key, #lookup_key_to_storage_key, #storage_key_to_lookup_key

Constructor Details

#initialize(&block) ⇒ StringHashTraits

Returns a new instance of StringHashTraits.



51
52
53
54
# File 'lib/hashtable/traits.rb', line 51

def initialize(&block)
  super
  @block = block
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



49
50
51
# File 'lib/hashtable/traits.rb', line 49

def buckets
  @buckets
end

#string_tableObject (readonly)

Returns the value of attribute string_table.



49
50
51
# File 'lib/hashtable/traits.rb', line 49

def string_table
  @string_table
end

Instance Method Details

#lookup_key_to_storage_value(key, values) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/hashtable/traits.rb', line 56

def lookup_key_to_storage_value(key, values)
  return if values.nil? || values.empty?

  bs = values.map { |v| lookup_key_to_storage_key(v) }.unshift(key)
  return bs if @block.nil?

  @block.call(bs)
end