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.



45
46
47
48
49
50
# File 'lib/fibonacci_heap/node.rb', line 45

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.



36
37
38
# File 'lib/fibonacci_heap/node.rb', line 36

def child_list
  @child_list
end

#degreeObject

Return the degree of this node.



27
28
29
# File 'lib/fibonacci_heap/node.rb', line 27

def degree
  @degree
end

#keyObject

Return the key of the node.



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

def key
  @key
end

#markObject

Return whether this node is marked or not.



33
34
35
# File 'lib/fibonacci_heap/node.rb', line 33

def mark
  @mark
end

#nextObject Also known as: right

Return the node next to this one.



19
20
21
# File 'lib/fibonacci_heap/node.rb', line 19

def next
  @next
end

#pObject

Return the parent of this node or nil if there is none.



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

def p
  @p
end

#prevObject Also known as: left

Return the node previous to this one.



23
24
25
# File 'lib/fibonacci_heap/node.rb', line 23

def prev
  @prev
end

#valueObject

Return the value of the node.



16
17
18
# File 'lib/fibonacci_heap/node.rb', line 16

def value
  @value
end

Instance Method Details

#inspectObject



52
53
54
# File 'lib/fibonacci_heap/node.rb', line 52

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