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
341 342 343 |
# File 'lib/expanse.rb', line 341 def self.finalize(ptr) proc { Native.expanse_bytesmap_free(ptr) if ptr && !ptr.null? } end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
352 353 354 355 356 357 358 |
# File 'lib/expanse.rb', line 352 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
345 346 347 348 349 |
# File 'lib/expanse.rb', line 345 def []=(key, val) b = key.b Native.expanse_bytesmap_insert(@ptr, b, b.bytesize, val, nil) val end |
#clear ⇒ Object
377 378 379 380 |
# File 'lib/expanse.rb', line 377 def clear Native.expanse_bytesmap_clear(@ptr) self end |
#delete(key) ⇒ Object
361 362 363 364 365 366 367 |
# File 'lib/expanse.rb', line 361 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
369 370 371 |
# File 'lib/expanse.rb', line 369 def key?(key) !self[key].nil? end |
#size ⇒ Object
373 374 375 |
# File 'lib/expanse.rb', line 373 def size Native.expanse_bytesmap_len(@ptr) end |