Class: PEROBS::BTreeNodeLink
- Inherits:
-
Object
- Object
- PEROBS::BTreeNodeLink
- Defined in:
- lib/perobs/BTreeNodeLink.rb
Overview
This class is used to form the links between the in-memory BTreeNode objects. The link is based on the address of the node in the file. The class objects transparently convert the address into a corresponding BTreeNode object and pass on all method calls.
Instance Attribute Summary collapse
-
#node_address ⇒ Object
readonly
Returns the value of attribute node_address.
Instance Method Summary collapse
-
#!=(node) ⇒ Boolean
Compare this node to another node.
-
#==(node) ⇒ Boolean
Compare this node to another node.
-
#check_node_link(branch, stack) ⇒ Boolean
Check the link to a sub-node.
- #children ⇒ Object
- #get(key) ⇒ Object
- #get_node ⇒ Object
-
#initialize(tree, node_or_address) ⇒ BTreeNodeLink
constructor
Create a new BTreeNodeLink object.
- #insert_element(key, voc) ⇒ Object
- #is_leaf ⇒ Object
- #is_top? ⇒ Boolean
- #keys ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
All calls to a BTreeNodeLink object will be forwarded to the corresponding BTreeNode object.
-
#respond_to?(method, include_private = false) ⇒ Boolean
Make it properly introspectable.
- #search_key_index(key) ⇒ Object
-
#to_s ⇒ Object
Textual version of the BTreeNode.
- #values ⇒ Object
Constructor Details
#initialize(tree, node_or_address) ⇒ BTreeNodeLink
Create a new BTreeNodeLink object.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/perobs/BTreeNodeLink.rb', line 43 def initialize(tree, node_or_address) @tree = tree if node_or_address.is_a?(BTreeNode) || node_or_address.is_a?(BTreeNodeLink) @node_address = node_or_address.node_address elsif node_or_address.is_a?(Integer) @node_address = node_or_address else PEROBS.log.fatal "Unsupported argument type #{node_or_address.class}" end if @node_address == 0 PEROBS.log.fatal "Node address may not be 0" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
All calls to a BTreeNodeLink object will be forwarded to the corresponding BTreeNode object. If that
60 61 62 63 |
# File 'lib/perobs/BTreeNodeLink.rb', line 60 def method_missing(method, *args, &block) #$stderr.puts "Method missing: #{method}" get_node.send(method, *args, &block) end |
Instance Attribute Details
#node_address ⇒ Object (readonly)
Returns the value of attribute node_address.
36 37 38 |
# File 'lib/perobs/BTreeNodeLink.rb', line 36 def node_address @node_address end |
Instance Method Details
#!=(node) ⇒ Boolean
Compare this node to another node.
106 107 108 109 110 111 112 |
# File 'lib/perobs/BTreeNodeLink.rb', line 106 def !=(node) if node.nil? return !@node_address.nil? end @node_address != node.node_address end |
#==(node) ⇒ Boolean
Compare this node to another node.
100 101 102 |
# File 'lib/perobs/BTreeNodeLink.rb', line 100 def ==(node) @node_address == node.node_address end |
#check_node_link(branch, stack) ⇒ Boolean
Check the link to a sub-node. This method silently ignores all errors if the sub-node does not exist.
121 122 123 124 125 126 127 |
# File 'lib/perobs/BTreeNodeLink.rb', line 121 def check_node_link(branch, stack) begin return get_node.check_node_link(branch, stack) rescue return false end end |
#children ⇒ Object
82 83 84 |
# File 'lib/perobs/BTreeNodeLink.rb', line 82 def children get_node.children end |
#get(key) ⇒ Object
86 87 88 |
# File 'lib/perobs/BTreeNodeLink.rb', line 86 def get(key) get_node.get(key) end |
#get_node ⇒ Object
134 135 136 |
# File 'lib/perobs/BTreeNodeLink.rb', line 134 def get_node @tree.node_cache.get(@node_address) end |
#insert_element(key, voc) ⇒ Object
94 95 96 |
# File 'lib/perobs/BTreeNodeLink.rb', line 94 def insert_element(key, voc) get_node.insert_element(key, voc) end |
#is_leaf ⇒ Object
70 71 72 |
# File 'lib/perobs/BTreeNodeLink.rb', line 70 def is_leaf get_node.is_leaf end |
#is_top? ⇒ Boolean
114 115 116 |
# File 'lib/perobs/BTreeNodeLink.rb', line 114 def is_top? get_node.is_top? end |
#keys ⇒ Object
74 75 76 |
# File 'lib/perobs/BTreeNodeLink.rb', line 74 def keys get_node.keys end |
#respond_to?(method, include_private = false) ⇒ Boolean
Make it properly introspectable.
66 67 68 |
# File 'lib/perobs/BTreeNodeLink.rb', line 66 def respond_to?(method, include_private = false) get_node.respond_to?(method) end |
#search_key_index(key) ⇒ Object
90 91 92 |
# File 'lib/perobs/BTreeNodeLink.rb', line 90 def search_key_index(key) get_node.search_key_index(key) end |
#to_s ⇒ Object
Returns Textual version of the BTreeNode.
130 131 132 |
# File 'lib/perobs/BTreeNodeLink.rb', line 130 def to_s get_node.to_s end |
#values ⇒ Object
78 79 80 |
# File 'lib/perobs/BTreeNodeLink.rb', line 78 def values get_node.values end |