Class: UnifiedQueues::Single::Driver::PoorPriorityQueueDriver

Inherits:
UnifiedQueues::Single::Driver show all
Defined in:
lib/unified-queues/single/driver/priority_queue.rb

Overview

Minimal priority queue driver. Uses the PoorPriorityQueue class from PriorityQueue gem. Priority is supported.

It isn’t implement equivalent of the #clear method, so it falls backs to naive “popping” style clearing.

Also note, it’s very minimalistic implementation, so both calls to PoorPriorityQueue#length and PoorPriorityQueue#empty? will throw an exception.

Instance Attribute Summary

Attributes inherited from UnifiedQueues::Single::Driver

#native

Instance Method Summary collapse

Methods inherited from UnifiedQueues::Single::Driver

#clear!, #evented?, #initialize, #linear?, #type

Constructor Details

This class inherits a constructor from UnifiedQueues::Single::Driver

Instance Method Details

#empty?Boolean

Indicates queue is empty. Note, it isn’t implemented in this implementation.

Parameters:

  • +true+ (Boolean)

    if it’s, false otherwise

Returns:

  • (Boolean)


134
135
136
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 134

def empty?
    not_implemented
end

#lengthInteger

Returns length of the queue. Note, it isn’t implemented in this implementation.

Returns:

  • (Integer)


145
146
147
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 145

def length
    not_implemented
end

#pop(blocking = false) ⇒ Object

Pops value out of the queue. Note, value with minimal priority will be popped out. Blocking isn’t supported.

Parameters:

  • blocking (Boolean|Integer) (defaults to: false)

    true or timeout if it should block, false otherwise

Returns:

  • (Object)

    queued value



123
124
125
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 123

def pop(blocking = false)
    @native.delete_min_return_key
end

#push(value, key = value) ⇒ Object

Pushes the value into the queue. Priority is supported.

Parameters:

  • value (Object)

    value for push

  • key (Object) (defaults to: value)

    key for priority queues



111
112
113
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 111

def push(value, key = value)
    @native.push(value, key)
end