Class: OklahomaMixer::HashMap
- Inherits:
-
Object
- Object
- OklahomaMixer::HashMap
- Defined in:
- lib/oklahoma_mixer/hash_map.rb,
lib/oklahoma_mixer/hash_map/c.rb
Overview
:nodoc:
Defined Under Namespace
Modules: C
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Instance Method Summary collapse
- #each ⇒ Object
- #free ⇒ Object
-
#initialize(pointer = C.new) ⇒ HashMap
constructor
A new instance of HashMap.
- #replace(pairs, &cast) ⇒ Object
- #to_hash ⇒ Object
- #update(pairs) ⇒ Object
Constructor Details
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
9 10 11 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 9 def pointer @pointer end |
Instance Method Details
#each ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 17 def each C.iterinit(@pointer) loop do return self unless key = C.read_from_func(:iternext, :no_free, @pointer) yield [key, C.read_from_func(:get, :no_free, @pointer, key, key.size)] end end |
#free ⇒ Object
38 39 40 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 38 def free C.del(@pointer) end |
#replace(pairs, &cast) ⇒ Object
33 34 35 36 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 33 def replace(pairs, &cast) C.clear(@pointer) update(pairs, &cast) end |
#to_hash ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 25 def to_hash hash = { } each do |key, value| hash[yield(key)] = yield(value) end hash end |
#update(pairs) ⇒ Object
11 12 13 14 15 |
# File 'lib/oklahoma_mixer/hash_map.rb', line 11 def update(pairs) pairs.each do |key, value| C.put(@pointer, *[yield(key), yield(value)].flatten) end end |