Class: MemDB::Index::Enum

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

Defined Under Namespace

Classes: Bucket

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MemDB::Index

compose

Constructor Details

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

Returns a new instance of Enum.



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

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

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



26
27
28
# File 'lib/mem_db/index/enum.rb', line 26

def bucket
  @bucket
end

#idxObject (readonly)

Returns the value of attribute idx.



26
27
28
# File 'lib/mem_db/index/enum.rb', line 26

def idx
  @idx
end

Instance Method Details

#add(obj, value) ⇒ Object



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

def add(obj, value)
  enums = obj.idx_value(@idx)
  enums.each do |enum|
    b = @hash[enum] ||= @bucket.new
    b.add(obj, value)
  end
end

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



42
43
44
45
46
47
48
49
50
51
# File 'lib/mem_db/index/enum.rb', line 42

def query(query, out: MemDB::Out.new)
  enums = query.idx_value(@idx)
  enums.each do |enum|
    if (b = @hash[enum])
      b.query(query, out: out)
    end
  end

  out
end