Class: CompSci::ChildFlexNode
- Defined in:
- lib/compsci/flex_node.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from Node
Instance Method Summary collapse
- #add_child(node) ⇒ Object
- #add_parent(node) ⇒ Object
-
#gen ⇒ Object
O(log n) recursive.
-
#initialize(value, metadata: {}) ⇒ ChildFlexNode
constructor
A new instance of ChildFlexNode.
- #siblings ⇒ Object
Methods inherited from FlexNode
#bf_search, #df_search, #new_child, #open_parent, #open_parent?, #push
Methods inherited from Node
#[], #[]=, #display, display_line, #inspect, #to_s
Constructor Details
#initialize(value, metadata: {}) ⇒ ChildFlexNode
Returns a new instance of ChildFlexNode.
65 66 67 68 |
# File 'lib/compsci/flex_node.rb', line 65 def initialize(value, metadata: {}) super(value, metadata: ) @parent = nil end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
63 64 65 |
# File 'lib/compsci/flex_node.rb', line 63 def parent @parent end |
Instance Method Details
#add_child(node) ⇒ Object
79 80 81 82 83 |
# File 'lib/compsci/flex_node.rb', line 79 def add_child(node) node.parent ||= self raise "node has a parent: #{node.parent}" if node.parent != self @children << node end |
#add_parent(node) ⇒ Object
85 86 87 88 |
# File 'lib/compsci/flex_node.rb', line 85 def add_parent(node) @parent = node @parent.add_child(self) end |
#gen ⇒ Object
O(log n) recursive
71 72 73 |
# File 'lib/compsci/flex_node.rb', line 71 def gen @parent ? @parent.gen + 1 : 0 end |
#siblings ⇒ Object
75 76 77 |
# File 'lib/compsci/flex_node.rb', line 75 def siblings @parent ? @parent.children : [] end |