class PEROBS::BTreeNodeLink

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.

Attributes

node_address[R]

Public Class Methods

new(tree, node_or_address) click to toggle source

Create a new BTreeNodeLink object. @param tree [BTree] The BTree that holds the nodes. @param node_or_address [BTreeNode or BTreeNodeLink or Integer] a

BTreeNode, BTreeNodeLink reference or the node
address in the file.
# 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

Public Instance Methods

!=(node) click to toggle source

Compare this node to another node. @return [Boolean] true if node address is not identical, false otherwise

# File lib/perobs/BTreeNodeLink.rb, line 116
def !=(node)
  if node.nil?
    return !@node_address.nil?
  end

  @node_address != node.node_address
end
==(node) click to toggle source

Compare this node to another node. @return [Boolean] true if node address is identical, false otherwise

# File lib/perobs/BTreeNodeLink.rb, line 110
def ==(node)
  @node_address == node.node_address
end
children() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 84
def children
  get_node.children
end
get(key) click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 88
def get(key)
  get_node.get(key)
end
get_node() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 144
def get_node
  @tree.node_cache.get(@node_address)
end
insert(key, value) click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 96
def insert(key, value)
  get_node.insert(key, value)
end
insert_element(key, voc) click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 100
def insert_element(key, voc)
  get_node.insert_element(key, voc)
end
is_leaf() click to toggle source

Directly define some commonly used methods to avoid the method_missing overhead.

# File lib/perobs/BTreeNodeLink.rb, line 72
def is_leaf
  get_node.is_leaf
end
is_top?() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 124
def is_top?
  get_node.is_top?
end
keys() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 76
def keys
  get_node.keys
end
method_missing(method, *args, &block) click to toggle source

All calls to a BTreeNodeLink object will be forwarded to the corresponding BTreeNode object. If that

# 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
respond_to?(method, include_private = false) click to toggle source

Make it properly introspectable.

# File lib/perobs/BTreeNodeLink.rb, line 66
def respond_to?(method, include_private = false)
  get_node.respond_to?(method)
end
search_key_index(key) click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 92
def search_key_index(key)
  get_node.search_key_index(key)
end
split_node() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 104
def split_node
  get_node.split_node
end
to_s() click to toggle source

@return Textual version of the BTreeNode

# File lib/perobs/BTreeNodeLink.rb, line 140
def to_s
  get_node.to_s
end
values() click to toggle source
# File lib/perobs/BTreeNodeLink.rb, line 80
def values
  get_node.values
end