Class: MapReduce::PriorityQueue
- Inherits:
-
Object
- Object
- MapReduce::PriorityQueue
- Defined in:
- lib/map_reduce/priority_queue.rb
Overview
The MapReduce::PriorityQueue implements a min priority queue using a binomial heap.
Instance Method Summary collapse
-
#initialize ⇒ PriorityQueue
constructor
Initializes the priority queue.
-
#pop ⇒ Object
Pops the min item from the queue.
-
#push(object, key) ⇒ Object
Adds a new item to the priority queue while the key is used for sorting.
Constructor Details
#initialize ⇒ PriorityQueue
Initializes the priority queue.
33 34 35 36 |
# File 'lib/map_reduce/priority_queue.rb', line 33 def initialize @queue = MinPriorityQueue.new @sequence_number = 0 end |
Instance Method Details
#pop ⇒ Object
Pops the min item from the queue.
65 66 67 68 69 |
# File 'lib/map_reduce/priority_queue.rb', line 65 def pop _, object = @queue.pop object end |
#push(object, key) ⇒ Object
Adds a new item to the priority queue while the key is used for sorting. The object and key can basically be everything, but the key must be some comparable object.
49 50 51 52 53 |
# File 'lib/map_reduce/priority_queue.rb', line 49 def push(object, key) @queue.push([@sequence_number, object], SortKey.new(key)) @sequence_number += 1 end |