class PriorityQueue::Entry

An Entry has a priority and an item

Attributes

item[R]

The item stored in an Entry of the queue

priority[R]

The priority of an Entry of the queue

Public Class Methods

new(priority) click to toggle source

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

Public Instance Methods

<<(item) click to toggle source

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
<=>(rhs) click to toggle source

Comparison of priority values.

# File hack_priority_queue.rb, line 30
def <=>(rhs)
    @priority <=> rhs.priority
end