Class: VinaryTree::Libdictenstein::DoubleArrayTrie
- Inherits:
-
Dictionary
- Object
- Dictionary
- VinaryTree::Libdictenstein::DoubleArrayTrie
- Defined in:
- lib/vinary_tree/libdictenstein.rb
Instance Attribute Summary
Attributes inherited from Dictionary
Instance Method Summary collapse
-
#initialize(entries, domain: UNICODE_SCALAR) ⇒ DoubleArrayTrie
constructor
A new instance of DoubleArrayTrie.
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(entries, domain: UNICODE_SCALAR) ⇒ DoubleArrayTrie
Returns a new instance of DoubleArrayTrie.
416 417 418 419 420 421 422 423 424 |
# File 'lib/vinary_tree/libdictenstein.rb', line 416 def initialize(entries, domain: UNICODE_SCALAR) 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.pointer_output; Libdictenstein.check(Native.ldict_double_array_trie_new(domain, memory, entries.length, output)); super(Native.read_pointer(output)) end |