Class: Oink::Reports::PriorityQueue

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/oink/reports/priority_queue.rb

Instance Method Summary collapse

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

#eachObject



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

#sizeObject



25
26
27
# File 'lib/oink/reports/priority_queue.rb', line 25

def size
  @queue.size
end

#to_aObject



21
22
23
# File 'lib/oink/reports/priority_queue.rb', line 21

def to_a
  @queue
end