Class: Vptree::FixedLengthQueue

Inherits:
Containers::PriorityQueue
  • Object
show all
Defined in:
lib/vptree.rb

Overview

Implementation of queue with fixed size. Will store elements with low priority

Instance Method Summary collapse

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

#dumpObject



30
31
32
# File 'lib/vptree.rb', line 30

def dump
  size.times.map { @heap.pop }
end

#max_priorityObject



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