Module: Tree::UpTreeAlgorithms

Includes:
BranchesProperty, NodeProperty
Included in:
ArrayTree, PathAlgorithms
Defined in:
lib/modular_tree/algorithms.rb

Overview

A down tree can only be traversed bottom-up

TODO: Add FilteredUpTreeAlgorithms

Instance Method Summary collapse

Methods included from BranchesProperty

#bare?, #branches, #each_branch

Methods included from NodeProperty

#node, #node_value

Instance Method Details

#ancestorsObject

Bottom-up



13
14
15
16
17
18
# File 'lib/modular_tree/algorithms.rb', line 13

def ancestors # TODO: rename #parents
  curr = self
  a = []
  a.push curr.node while curr = curr.branch
  a
end

#ancestryObject

Top-down # TODO: rename #ancestors



21
22
23
24
25
26
# File 'lib/modular_tree/algorithms.rb', line 21

def ancestry
  curr = self
  a = []
  a.unshift curr.node while curr = curr.branch
  a
end

#depthObject



28
# File 'lib/modular_tree/algorithms.rb', line 28

def depth = @depth ||= ancestors.size