Class: MemDB::Index::SequenceMatch

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

Defined Under Namespace

Classes: Bucket, SequenceIndex

Instance Method Summary collapse

Methods included from MemDB::Index

#bucket, compose, #idx

Constructor Details

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

Returns a new instance of SequenceMatch.



111
112
113
114
115
116
# File 'lib/mem_db/index/sequence_match.rb', line 111

def initialize(idx:, bucket: MemDB::Bucket)
  @idx = idx
  @bucket = bucket
  @patterns = {}
  @matchers = {}
end

Instance Method Details

#add(obj, value) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/mem_db/index/sequence_match.rb', line 118

def add(obj, value)
  obj.idx_value(@idx).each do |pattern|
    @patterns[pattern] ||= @bucket.new
    @patterns[pattern].add(obj, value)

    @matchers[pattern] ||= SequenceIndex.new(pattern)
  end
end

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



127
128
129
130
131
132
133
# File 'lib/mem_db/index/sequence_match.rb', line 127

def query(query, out: MemDB::Out.new)
  query.idx_value(@idx).each do |seq|
    select_one(query, seq, out)
  end

  out
end