Class: VinaryTree::Libdictenstein::DynamicDawg

Inherits:
Dictionary
  • Object
show all
Defined in:
lib/vinary_tree/libdictenstein.rb

Instance Attribute Summary

Attributes inherited from Dictionary

#handle

Instance Method Summary collapse

Methods inherited from Dictionary

#capabilities, #close, #each, #entries, #entry_stream, finalizer, #get, #get_u64, #include?, #include_u64?, #keys, #kind, #length, #values, #with_resource

Constructor Details

#initialize(domain: UNICODE_SCALAR) ⇒ DynamicDawg

Returns a new instance of DynamicDawg.



388
389
390
# File 'lib/vinary_tree/libdictenstein.rb', line 388

def initialize(domain: UNICODE_SCALAR)
  output = Native.pointer_output; Libdictenstein.check(Native.ldict_dynamic_dawg_new(domain, output)); super(Native.read_pointer(output))
end

Instance Method Details

#clearObject



395
# File 'lib/vinary_tree/libdictenstein.rb', line 395

def clear = @handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_dictionary_clear(pointer)) }

#compactObject



396
397
398
# File 'lib/vinary_tree/libdictenstein.rb', line 396

def compact
  output = Native.size_output; @handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_dictionary_compact(pointer, output)) }; Native.read_size(output)
end

#put(term, value = nil) ⇒ Object



391
# File 'lib/vinary_tree/libdictenstein.rb', line 391

def put(term, value = nil) = put_text(term, value)

#put_all(entries) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/vinary_tree/libdictenstein.rb', line 399

def put_all(entries)
  terms = entries.map { |term, _value| term.b }
  memory = Fiddle::Pointer.malloc([1, entries.length * Native::TextEntry.size].max, Fiddle::RUBY_FREE)
  entries.each_with_index do |(_term, value), index|
    item = Native::TextEntry.new(memory + index * Native::TextEntry.size)
    item.data = Fiddle::Pointer[terms[index]]
    item.len = terms[index].bytesize
    item.value = value || 0
    item.has_value = value.nil? ? 0 : 1
  end
  output = Native.size_output
  @handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_dictionary_insert_text_batch(pointer, memory, entries.length, output)) }
  Native.read_size(output)
end

#put_u64(tokens, value = nil) ⇒ Object



393
# File 'lib/vinary_tree/libdictenstein.rb', line 393

def put_u64(tokens, value = nil) = put_tokens(tokens, value)

#remove(term) ⇒ Object



392
# File 'lib/vinary_tree/libdictenstein.rb', line 392

def remove(term) = remove_text(term)

#remove_u64(tokens) ⇒ Object



394
# File 'lib/vinary_tree/libdictenstein.rb', line 394

def remove_u64(tokens) = remove_tokens(tokens)