Class: RubyPriorityQueue::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/amp/dependencies/priority_queue/ruby_priority_queue.rb

Overview

Node class used internally

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def child
  @child
end

#degreeObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def degree
  @degree
end

#keyObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def key
  @key
end

#leftObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def left
  @left
end

#markObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def mark
  @mark
end

#parentObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def parent
  @parent
end

#priorityObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def priority
  @priority
end

#rightObject

:nodoc:



108
109
110
# File 'lib/amp/dependencies/priority_queue/ruby_priority_queue.rb', line 108

def right
  @right
end

Instance Method Details

#dot_idObject



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