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
-
#ancestors ⇒ Object
Bottom-up.
-
#ancestry ⇒ Object
Top-down # TODO: rename #ancestors.
- #depth ⇒ Object
Methods included from BranchesProperty
#bare?, #branches, #each_branch
Methods included from NodeProperty
Instance Method Details
#ancestors ⇒ Object
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 |
#ancestry ⇒ Object
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 |
#depth ⇒ Object
28 |
# File 'lib/modular_tree/algorithms.rb', line 28 def depth = @depth ||= ancestors.size |