Class: KTree::KTree
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#root ⇒ Object
Returns the value of attribute root.
-
#tuple ⇒ Object
readonly
Returns the value of attribute tuple.
Instance Method Summary collapse
-
#create_tree(vupper, vlower, &block) ⇒ Object
The block is passed node itself as parent and the vector midpoints of its children to be.
-
#each(&block) ⇒ Object
Iterate through all nodes.
-
#initialize(vupper, vlower, depth, &block) ⇒ KTree
constructor
A new instance of KTree.
Constructor Details
#initialize(vupper, vlower, depth, &block) ⇒ KTree
Returns a new instance of KTree.
69 70 71 72 73 74 75 |
# 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 |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
19 20 21 |
# File 'lib/k-tree/k-tree.rb', line 19 def depth @depth end |
#root ⇒ Object
Returns the value of attribute root.
20 21 22 |
# File 'lib/k-tree/k-tree.rb', line 20 def root @root end |
#tuple ⇒ Object (readonly)
Returns the value of attribute tuple.
19 20 21 |
# File 'lib/k-tree/k-tree.rb', line 19 def tuple @tuple end |
Instance Method Details
#create_tree(vupper, vlower, &block) ⇒ Object
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.
84 85 86 87 |
# 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) ⇒ Object
Iterate through all nodes
90 91 92 |
# File 'lib/k-tree/k-tree.rb', line 90 def each(&block) root.each(&block) end |