Class: Dynflow::Utils::PriorityQueue
- Inherits:
-
Object
- Object
- Dynflow::Utils::PriorityQueue
- Defined in:
- lib/dynflow/utils/priority_queue.rb
Overview
Heavily inspired by rubyworks/pqueue
Instance Method Summary collapse
-
#initialize(&block) ⇒ PriorityQueue
constructor
:yields: a, b.
- #pop ⇒ Object
- #push(element) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(&block) ⇒ PriorityQueue
:yields: a, b
6 7 8 9 |
# File 'lib/dynflow/utils/priority_queue.rb', line 6 def initialize(&block) # :yields: a, b @backing_store = [] @comparator = block || :<=>.to_proc end |
Instance Method Details
#pop ⇒ Object
24 25 26 |
# File 'lib/dynflow/utils/priority_queue.rb', line 24 def pop @backing_store.pop end |
#push(element) ⇒ Object
19 20 21 22 |
# File 'lib/dynflow/utils/priority_queue.rb', line 19 def push(element) @backing_store << element reposition_element(@backing_store.size - 1) end |
#size ⇒ Object
11 12 13 |
# File 'lib/dynflow/utils/priority_queue.rb', line 11 def size @backing_store.size end |
#to_a ⇒ Object
28 29 30 |
# File 'lib/dynflow/utils/priority_queue.rb', line 28 def to_a @backing_store end |
#top ⇒ Object
15 16 17 |
# File 'lib/dynflow/utils/priority_queue.rb', line 15 def top @backing_store.last end |