forked from Altiscale/burstingsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_stream.rb
executable file
·60 lines (47 loc) · 1.01 KB
/
events_stream.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require_relative 'pqueue'
require_relative 'events/input_log_event'
# The stream of events. Contains a priority queue with events ordered by their timestamps.
# It's interface provides decorators over the priority queue implementation
class EventsStream
attr_accessor :queue
def initialize
@queue = PQueue.new([]) { |a, b| b <=> a } # Smaller timestamp -> Highest priority
end
def pop_and_print_all
@queue.each_pop { |e| puts e.print }
end
def clear
@queue.clear
end
def top
@queue.top
end
def push_without_reheap(v)
@queue.push_without_reheap(v)
end
def pop
@queue.pop
end
# Returns the element with the lowest priority
def bottom
@queue.bottom
end
def init_with_sorted_array(elements)
@queue.init_with_sorted_array(elements)
end
def concat(elements)
@queue.concat(elements)
end
def push(element)
@queue.push(element)
end
def inspect
@queue.inspect
end
def size
@queue.size
end
def empty?
@queue.empty?
end
end