Class: RubyPriorityQueue::Node
- Defined in:
- lib/amp/dependencies/priority_queue/ruby_priority_queue.rb
Overview
Node class used internally
Instance Attribute Summary collapse
-
#child ⇒ Object
:nodoc:.
-
#degree ⇒ Object
:nodoc:.
-
#key ⇒ Object
:nodoc:.
-
#left ⇒ Object
:nodoc:.
-
#mark ⇒ Object
:nodoc:.
-
#parent ⇒ Object
:nodoc:.
-
#priority ⇒ Object
:nodoc:.
-
#right ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #dot_id ⇒ Object
-
#initialize(key, priority) ⇒ Node
constructor
A new instance of Node.
- #to_dot(only_down = false, known_nodes = []) ⇒ Object
Constructor Details
#initialize(key, priority) ⇒ Node
Returns a new instance of Node.
147 148 149 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 147 def initialize(key, priority) @key = key; @priority = priority; @degree = 0 end |
Instance Attribute Details
#child ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def child @child end |
#degree ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def degree @degree end |
#key ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def key @key end |
#left ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def left @left end |
#mark ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def mark @mark end |
#parent ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def parent @parent end |
#priority ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def priority @priority end |
#right ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108 def right @right end |
Instance Method Details
#dot_id ⇒ Object
143 144 145 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 143 def dot_id "N#{@key}" end |
#to_dot(only_down = false, known_nodes = []) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 117 def to_dot(only_down = false, known_nodes = []) # p known_nodes.map { | n | n.dot_id } # p self.dot_id result = [] if only_down raise "Circular #{caller.inspect}" if known_nodes.include?(self) known_nodes << self result << "#{dot_id} [label=\"#{@key}: #{@priority}\"];" l = " " #l << "#{@left.dot_id} <- #{dot_id}; " if @left l << "#{dot_id} -> #{@left.dot_id} [constraint=false]; " if @left and @left.dot_id < self.dot_id l << "#{dot_id} -> #{@right.dot_id} [constraint=false];\t\t\t\t/*neighbours*/" if @right and @right.dot_id <= self.dot_id result << l result << " #{dot_id} -> #{@child.dot_id}; //child" if @child result << @child.to_dot(false, known_nodes) if @child else n = self begin result.concat(n.to_dot(true, known_nodes)) n = n.right end while n != self end result.flatten.map{|r| " " << r} end |