Class: Oink::Reports::PriorityQueue
- Inherits:
-
Object
- Object
- Oink::Reports::PriorityQueue
- Includes:
- Enumerable
- Defined in:
- lib/oink/reports/priority_queue.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(size) ⇒ PriorityQueue
constructor
A new instance of PriorityQueue.
- #push(item) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(size) ⇒ PriorityQueue
Returns a new instance of PriorityQueue.
7 8 9 10 |
# File 'lib/oink/reports/priority_queue.rb', line 7 def initialize(size) @size = size @queue = [] end |
Instance Method Details
#each ⇒ Object
29 30 31 |
# File 'lib/oink/reports/priority_queue.rb', line 29 def each @queue.each { |i| yield i } end |
#push(item) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/oink/reports/priority_queue.rb', line 12 def push(item) if @queue.size < @size @queue << item elsif item > @queue.last @queue[@size - 1] = item end prioritize end |
#size ⇒ Object
25 26 27 |
# File 'lib/oink/reports/priority_queue.rb', line 25 def size @queue.size end |
#to_a ⇒ Object
21 22 23 |
# File 'lib/oink/reports/priority_queue.rb', line 21 def to_a @queue end |