Class: MemDB

Inherits:
Object
  • Object
show all
Defined in:
lib/mem_db/index/bucket.rb,
lib/mem_db.rb,
lib/mem_db/idx.rb,
lib/mem_db/out.rb,
lib/mem_db/field.rb,
lib/mem_db/index.rb,
lib/mem_db/query.rb,
lib/mem_db/bucket.rb,
lib/mem_db/fields.rb,
lib/mem_db/version.rb,
lib/mem_db/idx/uniq.rb,
lib/mem_db/idx/bytes.rb,
lib/mem_db/idx/chars.rb,
lib/mem_db/index/any.rb,
lib/mem_db/field/enum.rb,
lib/mem_db/idx/itself.rb,
lib/mem_db/index/enum.rb,
lib/mem_db/indexation.rb,
lib/mem_db/idx/default.rb,
lib/mem_db/idx/pattern.rb,
lib/mem_db/idx/reverse.rb,
lib/mem_db/field/regexp.rb,
lib/mem_db/idx/downcase.rb,
lib/mem_db/field/pattern.rb,
lib/mem_db/field/downcase.rb,
lib/mem_db/field/matching.rb,
lib/mem_db/field/negative.rb,
lib/mem_db/indexing_object.rb,
lib/mem_db/field/may_missing.rb,
lib/mem_db/index/prefix_tree.rb,
lib/mem_db/regexp_engines/re2.rb,
lib/mem_db/regexp_engines/std.rb,
lib/mem_db/index/pattern_match.rb,
lib/mem_db/index/sequence_match.rb

Overview

TODO: move to mem_db/index.rb

Defined Under Namespace

Modules: Field, Idx, Index, RegexpEngines Classes: Bucket, Entries, Error, Fields, Indexation, IndexingObject, Out, Query

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Constructor Details

#initialize(fields, index) ⇒ MemDB

Returns a new instance of MemDB.


38
39
40
41
42
# File 'lib/mem_db.rb', line 38

def initialize(fields, index)
  @fields = fields
  @index = index
  @entries = Entries.new
end

Instance Method Details

#add(obj, value) ⇒ Object


48
49
50
51
52
53
# File 'lib/mem_db.rb', line 48

def add(obj, value)
  matching = @fields.new_matching(obj)
  entry_id = @entries.add(matching, value)

  @index.add(obj, entry_id)
end

#new_indexationObject


44
45
46
# File 'lib/mem_db.rb', line 44

def new_indexation
  MemDB::Indexation.new(self)
end

#query(query) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mem_db.rb', line 55

def query(query)
  checked = Set.new
  found = []

  @index.query(query).each do |entry_id|
    next if checked.include?(entry_id)

    checked.add(entry_id)

    entry = @entries[entry_id]

    found.push(entry.value) if entry.matching.match?(query)
  end

  found
end