Class: MemDB::Index::PrefixTree::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/mem_db/index/prefix_tree.rb

Constant Summary collapse

MAX_LENGTH_DEFAULT =
2 ^ 64

Instance Method Summary collapse

Constructor Details

#initialize(bucket:) ⇒ Root

Returns a new instance of Root.



29
30
31
32
# File 'lib/mem_db/index/prefix_tree.rb', line 29

def initialize(bucket:)
  @item = Item.new(bucket: bucket)
  @min_length = MAX_LENGTH_DEFAULT
end

Instance Method Details

#add(prefixes, obj, value) ⇒ Object



44
45
46
47
48
49
# File 'lib/mem_db/index/prefix_tree.rb', line 44

def add(prefixes, obj, value)
  prefixes.each do |prefix|
    @min_length = prefix.length if @min_length > prefix.length
    @item.add(prefix, 0, obj, value)
  end
end

#get(contents, query:, result:) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/mem_db/index/prefix_tree.rb', line 34

def get(contents, query:, result:)
  contents.each do |content|
    next if @min_length > content.length

    @item.select_values(content, 0, query: query, out: result)
  end

  result
end