Class: UnifiedQueues::Single::Driver::CPriorityQueueDriver

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

Overview

Fibonacci heap queue driver. Uses the CPriorityQueue 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.

Instance Attribute Summary

Attributes inherited from UnifiedQueues::Single::Driver

#native

Instance Method Summary collapse

Methods inherited from UnifiedQueues::Single::Driver

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

Constructor Details

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

Instance Method Details

#empty?Boolean

Indicates queue is empty.

Parameters:

  • +true+ (Boolean)

    if it’s, false otherwise

Returns:

  • (Boolean)


65
66
67
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 65

def empty?
    @native.empty?
end

#lengthInteger

Returns length of the queue.

Returns:

  • (Integer)


75
76
77
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 75

def length
    @native.length
end

#pop(blocking = false) ⇒ Object

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

Parameters:

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

    true or timeout if it should block, false otherwise

Returns:

  • (Object)

    queued value



56
57
58
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 56

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



43
44
45
46
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 43

def push(value, key = value)
    key = (key.kind_of? Integer) ? key : 0
    @native.push(value, key)
end

#type:linear

Returs type of the queue.

Returns:

  • (:linear)


84
85
86
# File 'lib/unified-queues/single/driver/priority_queue.rb', line 84

def type
    :linear
end