Class: Vptree::FixedLengthQueue
- Inherits:
-
Containers::PriorityQueue
- Object
- Containers::PriorityQueue
- Vptree::FixedLengthQueue
- Defined in:
- lib/vptree.rb
Overview
Implementation of queue with fixed size. Will store elements with low priority
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(limit = 4) ⇒ FixedLengthQueue
constructor
4 for example.
- #max_priority ⇒ Object
- #push(value, priority) ⇒ Object
Constructor Details
#initialize(limit = 4) ⇒ FixedLengthQueue
4 for example
10 11 12 13 |
# File 'lib/vptree.rb', line 10 def initialize(limit = 4) # 4 for example super() @limit = limit end |
Instance Method Details
#dump ⇒ Object
30 31 32 |
# File 'lib/vptree.rb', line 30 def dump size.times.map { @heap.pop } end |
#max_priority ⇒ Object
15 16 17 |
# File 'lib/vptree.rb', line 15 def max_priority @heap.next_key end |
#push(value, priority) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vptree.rb', line 19 def push(value, priority) if size < @limit super(value, priority) else if priority < @heap.next_key pop super(value, priority) end end end |