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.



336
337
338
339
# File 'lib/expanse.rb', line 336

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

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

#clearObject



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

Returns:

  • (Boolean)


369
370
371
# File 'lib/expanse.rb', line 369

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

#sizeObject



373
374
375
# File 'lib/expanse.rb', line 373

def size
  Native.expanse_bytesmap_len(@ptr)
end