Class: FibonacciHeap::Node
- Inherits:
-
Object
- Object
- FibonacciHeap::Node
- Defined in:
- lib/fibonacci_heap/node.rb
Overview
A single node in a Fibonacci Heap.
Contains a key and optional value that can be any arbitrary object. The key will be used to sort nodes so that the key of a node is greater than or equal to the key of its parent.
Defaults to storing the key as the value.
Instance Attribute Summary collapse
-
#child_list ⇒ Object
Return the list of child nodes for this node.
-
#degree ⇒ Object
Return the degree of this node.
-
#key ⇒ Object
Return the key of the node.
-
#mark ⇒ Object
Return whether this node is marked or not.
-
#next ⇒ Object
(also: #right)
Return the node next to this one.
-
#p ⇒ Object
Return the parent of this node or nil if there is none.
-
#prev ⇒ Object
(also: #left)
Return the node previous to this one.
-
#value ⇒ Object
Return the value of the node.
Instance Method Summary collapse
-
#initialize(key, value = key) ⇒ Node
constructor
Return a new node with the given key and optional value.
- #inspect ⇒ Object
Constructor Details
#initialize(key, value = key) ⇒ Node
Return a new node with the given key and optional value.
The key and value can be any arbitrary object.
The node’s next and previous pointers will default to itself.
Defaults the value to the key.
43 44 45 46 47 48 |
# File 'lib/fibonacci_heap/node.rb', line 43 def initialize(key, value = key) @key = key @value = value @next = self @prev = self end |
Instance Attribute Details
#child_list ⇒ Object
Return the list of child nodes for this node.
34 35 36 |
# File 'lib/fibonacci_heap/node.rb', line 34 def child_list @child_list end |
#degree ⇒ Object
Return the degree of this node.
25 26 27 |
# File 'lib/fibonacci_heap/node.rb', line 25 def degree @degree end |
#key ⇒ Object
Return the key of the node.
11 12 13 |
# File 'lib/fibonacci_heap/node.rb', line 11 def key @key end |
#mark ⇒ Object
Return whether this node is marked or not.
31 32 33 |
# File 'lib/fibonacci_heap/node.rb', line 31 def mark @mark end |
#next ⇒ Object Also known as: right
Return the node next to this one.
17 18 19 |
# File 'lib/fibonacci_heap/node.rb', line 17 def next @next end |
#p ⇒ Object
Return the parent of this node or nil if there is none.
28 29 30 |
# File 'lib/fibonacci_heap/node.rb', line 28 def p @p end |
#prev ⇒ Object Also known as: left
Return the node previous to this one.
21 22 23 |
# File 'lib/fibonacci_heap/node.rb', line 21 def prev @prev end |
#value ⇒ Object
Return the value of the node.
14 15 16 |
# File 'lib/fibonacci_heap/node.rb', line 14 def value @value end |
Instance Method Details
#inspect ⇒ Object
50 51 52 |
# File 'lib/fibonacci_heap/node.rb', line 50 def inspect %(#<#{self.class} key=#{key.inspect} value=#{value.inspect}>) end |