An Entry has a priority and an item
The item stored in an Entry of the queue
The priority of an Entry of the queue
The priority must be set first.
# File hack_priority_queue.rb, line 17 def initialize(priority) raise ArgumentError unless priority.is_a? Numeric @priority = priority @item = nil end
This is the only way to set the item.
# File hack_priority_queue.rb, line 24 def <<(item) raise "item already set" unless @item == nil @item = item end
Comparison of priority values.
# File hack_priority_queue.rb, line 30 def <=>(rhs) @priority <=> rhs.priority end