Class: FibonacciHeap::Node

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_listObject

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

#degreeObject

Return the degree of this node.



25
26
27
# File 'lib/fibonacci_heap/node.rb', line 25

def degree
  @degree
end

#keyObject

Return the key of the node.



11
12
13
# File 'lib/fibonacci_heap/node.rb', line 11

def key
  @key
end

#markObject

Return whether this node is marked or not.



31
32
33
# File 'lib/fibonacci_heap/node.rb', line 31

def mark
  @mark
end

#nextObject 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

#pObject

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

#prevObject 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

#valueObject

Return the value of the node.



14
15
16
# File 'lib/fibonacci_heap/node.rb', line 14

def value
  @value
end

Instance Method Details

#inspectObject



50
51
52
# File 'lib/fibonacci_heap/node.rb', line 50

def inspect
  %(#<#{self.class} key=#{key.inspect} value=#{value.inspect}>)
end