Class: Db::Core::InternalNode
- Inherits:
-
Object
- Object
- Db::Core::InternalNode
- Defined in:
- lib/root/internal_node.rb
Instance Attribute Summary collapse
-
#infinity_node ⇒ Object
readonly
Returns the value of attribute infinity_node.
-
#keys_and_node_pointers ⇒ Object
readonly
Returns the value of attribute keys_and_node_pointers.
-
#parent_node ⇒ Object
Returns the value of attribute parent_node.
Instance Method Summary collapse
- #datas ⇒ Object
-
#initialize(order = 3, infinity_node = nil) ⇒ InternalNode
constructor
A new instance of InternalNode.
- #insert(key, value) ⇒ Object
- #insert_node_pointer(key_and_node) ⇒ Object
- #keys ⇒ Object
- #max_key_value ⇒ Object
- #search(key, operator = DB::Core::Common::Comparison::EQ) ⇒ Object
Constructor Details
#initialize(order = 3, infinity_node = nil) ⇒ InternalNode
Returns a new instance of InternalNode.
7 8 9 10 11 12 13 14 |
# File 'lib/root/internal_node.rb', line 7 def initialize(order=3, infinity_node=nil) @order=order @max_capacity=@order-1 @keys_and_node_pointers=[] @infinity_node=infinity_node @infinity_node.parent_node=self @parent_node=nil end |
Instance Attribute Details
#infinity_node ⇒ Object (readonly)
Returns the value of attribute infinity_node.
4 5 6 |
# File 'lib/root/internal_node.rb', line 4 def infinity_node @infinity_node end |
#keys_and_node_pointers ⇒ Object (readonly)
Returns the value of attribute keys_and_node_pointers.
4 5 6 |
# File 'lib/root/internal_node.rb', line 4 def keys_and_node_pointers @keys_and_node_pointers end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
5 6 7 |
# File 'lib/root/internal_node.rb', line 5 def parent_node @parent_node end |
Instance Method Details
#datas ⇒ Object
22 23 24 |
# File 'lib/root/internal_node.rb', line 22 def datas end |
#insert(key, value) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/root/internal_node.rb', line 38 def insert(key, value) case when key > max_key_value @infinity_node.insert(key, value) else @keys_and_node_pointers.each do |key_node| if key <= key_node[0] key_node[1].insert(key, value) break; end end end end |
#insert_node_pointer(key_and_node) ⇒ Object
31 32 33 34 35 |
# File 'lib/root/internal_node.rb', line 31 def insert_node_pointer(key_and_node) @keys_and_node_pointers << key_and_node sort_keys split if @keys_and_node_pointers.size > @max_capacity end |
#keys ⇒ Object
16 17 18 19 20 |
# File 'lib/root/internal_node.rb', line 16 def keys keys=[] @keys_and_node_pointers.each {|key_data| keys << key_data[0]} keys end |
#max_key_value ⇒ Object
27 28 29 |
# File 'lib/root/internal_node.rb', line 27 def max_key_value @keys_and_node_pointers[-1][0] end |
#search(key, operator = DB::Core::Common::Comparison::EQ) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/root/internal_node.rb', line 52 def search(key, operator=DB::Core::Common::Comparison::EQ) match=nil case when key > max_key_value match=@infinity_node.search(key, operator) else @keys_and_node_pointers.each do |key_node| if key <= key_node[0] match=key_node[1].search(key, operator) break; end end end return match end |