Class: MemDB::Index::PrefixTree

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

Defined Under Namespace

Classes: Bucket, Item, Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MemDB::Index

compose

Constructor Details

#initialize(idx:, bucket: MemDB::Bucket) ⇒ PrefixTree

Returns a new instance of PrefixTree.



93
94
95
96
97
# File 'lib/mem_db/index/prefix_tree.rb', line 93

def initialize(idx:, bucket: MemDB::Bucket)
  @idx = idx
  @bucket = bucket
  @root = Root.new(bucket: bucket)
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



91
92
93
# File 'lib/mem_db/index/prefix_tree.rb', line 91

def bucket
  @bucket
end

#idxObject (readonly)

Returns the value of attribute idx.



91
92
93
# File 'lib/mem_db/index/prefix_tree.rb', line 91

def idx
  @idx
end

Instance Method Details

#add(obj, value) ⇒ Object



99
100
101
# File 'lib/mem_db/index/prefix_tree.rb', line 99

def add(obj, value)
  @root.add(obj.idx_value(@idx), obj, value)
end

#query(query, out: MemDB::Out.new) ⇒ Object



103
104
105
106
107
# File 'lib/mem_db/index/prefix_tree.rb', line 103

def query(query, out: MemDB::Out.new)
  @root.get(query.idx_value(@idx), query: query, result: out)

  out
end