Class: Expanse::BytesMap

Inherits:
Object
  • Object
show all
Defined in:
lib/expanse.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBytesMap

Returns a new instance of BytesMap.



324
325
326
327
# File 'lib/expanse.rb', line 324

def initialize
  @ptr = Native.expanse_bytesmap_new
  ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
end

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

#clearObject



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

Returns:

  • (Boolean)


357
358
359
# File 'lib/expanse.rb', line 357

def key?(key)
  !self[key].nil?
end

#sizeObject



361
362
363
# File 'lib/expanse.rb', line 361

def size
  Native.expanse_bytesmap_len(@ptr)
end