Class: Expanse::BytesMap
- Inherits:
-
Object
- Object
- Expanse::BytesMap
- 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 ⇒ BytesMap
constructor
A new instance of BytesMap.
- #key?(key) ⇒ Boolean
- #size ⇒ Object
Constructor Details
Class Method Details
.finalize(ptr) ⇒ Object
329 330 331 |
# File 'lib/expanse.rb', line 329 def self.finalize(ptr) proc { Native.expanse_bytesmap_free(ptr) if ptr && !ptr.null? } end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
340 341 342 343 344 345 346 |
# File 'lib/expanse.rb', line 340 def [](key) b = key.b buf = Fiddle::Pointer.malloc(8) if Native.expanse_bytesmap_get(@ptr, b, b.bytesize, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#[]=(key, val) ⇒ Object Also known as: set
333 334 335 336 337 |
# File 'lib/expanse.rb', line 333 def []=(key, val) b = key.b Native.expanse_bytesmap_insert(@ptr, b, b.bytesize, val, nil) val end |
#clear ⇒ Object
365 366 367 368 |
# File 'lib/expanse.rb', line 365 def clear Native.expanse_bytesmap_clear(@ptr) self end |
#delete(key) ⇒ Object
349 350 351 352 353 354 355 |
# File 'lib/expanse.rb', line 349 def delete(key) b = key.b buf = Fiddle::Pointer.malloc(8) if Native.expanse_bytesmap_remove(@ptr, b, b.bytesize, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#key?(key) ⇒ Boolean
357 358 359 |
# File 'lib/expanse.rb', line 357 def key?(key) !self[key].nil? end |
#size ⇒ Object
361 362 363 |
# File 'lib/expanse.rb', line 361 def size Native.expanse_bytesmap_len(@ptr) end |