Class: MemDB::Index::Any

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

Defined Under Namespace

Classes: Bucket

Instance Method Summary collapse

Methods included from MemDB::Index

compose

Constructor Details

#initialize(original) ⇒ Any

Returns a new instance of Any.

Raises:

  • (ArgumentError)


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

def initialize(original)
  raise ArgumentError, "original must be MemDB::Index, got: #{original.class}" unless original.is_a?(MemDB::Index)

  @original = original
end

Instance Method Details

#add(obj, value) ⇒ Object



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

def add(obj, value)
  addr = obj.idx_value(idx)
  if addr == MemDB::Idx::ANY
    @any ||= bucket.new
    @any.add(obj, value)
  else
    @original.add(obj, value)
  end
end

#bucketObject



39
40
41
# File 'lib/mem_db/index/any.rb', line 39

def bucket
  @original.bucket
end

#idxObject



35
36
37
# File 'lib/mem_db/index/any.rb', line 35

def idx
  @original.idx
end

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



53
54
55
56
57
# File 'lib/mem_db/index/any.rb', line 53

def query(query, out: MemDB::Out.new)
  @original.query(query, out: out)
  @any&.query(query, out: out)
  out
end