Module: VinaryTree::Liblevenshtein::Native

Extended by:
Fiddle::Importer
Defined in:
lib/vinary_tree/liblevenshtein/native.rb

Constant Summary collapse

VtResource =
struct ["void* context", "void* vtable"]
Match =
struct [
  "void* term_data", "size_t term_len", "size_t byte_len",
  "size_t distance", "uint64_t id", "uint32_t unit_domain",
  "uint8_t has_id", "uint8_t reserved[3]"
]
Batch =
struct ["void* matches", "size_t len", "uint64_t generation"]
OwnedString =
struct ["void* data", "size_t len"]

Class Method Summary collapse

Class Method Details

.library_candidatesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vinary_tree/liblevenshtein/native.rb', line 9

def self.library_candidates
  explicit = ENV["LIBLEVENSHTEIN_LIBRARY"]
  os, extension, filename = case RbConfig::CONFIG["host_os"]
                            when /darwin/ then ["darwin", "dylib", "libliblevenshtein.dylib"]
                            when /mswin|mingw/ then ["windows", "dll", "liblevenshtein.dll"]
                            else ["linux", "so", "libliblevenshtein.so"]
                            end
  cpu = case RbConfig::CONFIG["host_cpu"]
        when /x86_64|amd64/ then "x64"
        when /aarch64|arm64/ then "arm64"
        else RbConfig::CONFIG["host_cpu"]
        end
  platform = "#{os}-#{cpu}"
  bundled = File.expand_path("native/#{platform}/#{filename}", __dir__)
  [explicit, bundled, filename, "liblevenshtein.#{extension}"].compact
end

.pointer_outputObject



75
76
77
# File 'lib/vinary_tree/liblevenshtein/native.rb', line 75

def pointer_output
  Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
end

.read_pointer(output) ⇒ Object



79
80
81
# File 'lib/vinary_tree/liblevenshtein/native.rb', line 79

def read_pointer(output)
  output[0, Fiddle::SIZEOF_VOIDP].unpack1("J")
end

.read_size(output) ⇒ Object



87
88
89
# File 'lib/vinary_tree/liblevenshtein/native.rb', line 87

def read_size(output)
  output[0, Fiddle::SIZEOF_SIZE_T].unpack1("J")
end

.size_outputObject



83
84
85
# File 'lib/vinary_tree/liblevenshtein/native.rb', line 83

def size_output
  Fiddle::Pointer.malloc(Fiddle::SIZEOF_SIZE_T, Fiddle::RUBY_FREE)
end