Class: Expanse::StrMap
- Inherits:
-
Object
- Object
- Expanse::StrMap
- Defined in:
- lib/expanse.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #get)
- #[]=(key, val) ⇒ Object (also: #set)
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize ⇒ StrMap
constructor
A new instance of StrMap.
- #key?(key) ⇒ Boolean
- #size ⇒ Object
Constructor Details
Class Method Details
.finalize(ptr) ⇒ Object
281 282 283 |
# File 'lib/expanse.rb', line 281 def self.finalize(ptr) proc { Native.expanse_strmap_free(ptr) if ptr && !ptr.null? } end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
292 293 294 295 296 297 298 |
# File 'lib/expanse.rb', line 292 def [](key) s = key.to_s buf = Fiddle::Pointer.malloc(8) if Native.expanse_strmap_get(@ptr, s, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#[]=(key, val) ⇒ Object Also known as: set
285 286 287 288 289 |
# File 'lib/expanse.rb', line 285 def []=(key, val) s = key.to_s Native.expanse_strmap_insert(@ptr, s, val, nil) val end |
#clear ⇒ Object
317 318 319 320 |
# File 'lib/expanse.rb', line 317 def clear Native.expanse_strmap_clear(@ptr) self end |
#delete(key) ⇒ Object
301 302 303 304 305 306 307 |
# File 'lib/expanse.rb', line 301 def delete(key) s = key.to_s buf = Fiddle::Pointer.malloc(8) if Native.expanse_strmap_remove(@ptr, s, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#key?(key) ⇒ Boolean
309 310 311 |
# File 'lib/expanse.rb', line 309 def key?(key) !self[key].nil? end |
#size ⇒ Object
313 314 315 |
# File 'lib/expanse.rb', line 313 def size Native.expanse_strmap_len(@ptr) end |