class KTree::KTree

Attributes

depth[R]
root[RW]
tuple[R]

Public Class Methods

new(vupper , vlower, depth, &block) click to toggle source
# File lib/k-tree/k-tree.rb, line 69
def initialize(vupper , vlower, depth, &block)
  @tuple = vupper.size
  @depth = depth
  @root = nil
  raise KTreeException.new('tuple mismatch') unless vlower.size == vupper.size
  create_tree(vupper, vlower, &block)
end

Public Instance Methods

create_tree(vupper, vlower, &block) click to toggle source

The block is passed node itself as parent and the vector midpoints of its children to be.

The block sets is own refob, and returns either true, in which case all the children are created, or it returns false, in which case none of the children will be created, in effect, marking itself as a leaf node.

# File lib/k-tree/k-tree.rb, line 84
def create_tree(vupper, vlower, &block)
  @root = Node.new(vupper, vlower, @depth)
  @root.create_children &block
end
each(&block) click to toggle source

Iterate through all nodes

# File lib/k-tree/k-tree.rb, line 90
def each(&block)
  root.each(&block)
end