Class: Db::Core::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/root/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structure = 3) ⇒ Table

Returns a new instance of Table.



7
8
9
10
11
12
# File 'lib/root/table.rb', line 7

def initialize(structure=3)
  raise "Your node structure is less than 3 which is not good for BTree" if (structure < 3)
  @structure = structure
  @root_node = Tree.new(@structure)
  @first_node = @root_node
end

Instance Attribute Details

#first_nodeObject

Returns the value of attribute first_node.



5
6
7
# File 'lib/root/table.rb', line 5

def first_node
  @first_node
end

#root_nodeObject

Returns the value of attribute root_node.



5
6
7
# File 'lib/root/table.rb', line 5

def root_node
  @root_node
end

Instance Method Details

#insert(key, value) ⇒ Object



14
15
16
17
# File 'lib/root/table.rb', line 14

def insert(key, value)
  @root_node.insert(key, value)
  @root_node = @root_node.parent_node unless @root_node.parent_node.nil?
end

#search(key, operator = DB::Core::Common::Comparison::EQ) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/root/table.rb', line 19

def search(key, operator=DB::Core::Common::Comparison::EQ)
    case operator
      when DB::Core::Common::Comparison::NEQ
        @root_node.search(key, DB::Core::Common::Comparison::LT) + @root_node.search(key, DB::Core::Common::Comparison::GT)
      else
        @root_node.search(key, operator)
    end
end