Class: UnifiedQueues::Single
- Inherits:
-
Object
- Object
- UnifiedQueues::Single
- Defined in:
- lib/unified-queues/single.rb,
lib/unified-queues/single/driver.rb,
lib/unified-queues/single/driver/depq.rb,
lib/unified-queues/single/driver/array.rb,
lib/unified-queues/single/driver/queue.rb,
lib/unified-queues/single/driver/algorithms.rb,
lib/unified-queues/single/driver/evented-queue.rb,
lib/unified-queues/single/driver/priority_queue.rb
Overview
Universal single queue interface.
Defined Under Namespace
Classes: Driver
Constant Summary collapse
- DRIVERS =
Contains assignment of classnames to drivers.
Hash[ :Queue => "queue", :Array => "array", :Depq => "depq", :"Containers::Heap" => "algorithms", :CPriorityQueue => "priority_queue", :PoorPriorityQueue => "priority_queue", :RubyPriorityQueue => "priority_queue", :EventedQueue => "evented-queue" ]
Instance Attribute Summary collapse
-
#driver ⇒ UnifiedQueues::Single::Driver
Contains driver for specific class instance.
Instance Method Summary collapse
-
#assign_driver(cls, args, block) ⇒ UnifiedQueues::Single::Driver
Assigns driver to interface according to given class name.
-
#clear!(&block) ⇒ Object
(also: #clear)
Clears the queue.
-
#empty?(&block) ⇒ Boolean
Indicates queue is empty.
-
#initialize(cls, *args, &block) ⇒ Single
constructor
Constructor.
-
#length(&block) ⇒ Integer
(also: #size)
Returns length of the queue.
-
#pop(blocking = false, &block) ⇒ Object
(also: #pop!)
Pops value out of the queue.
-
#push(value, key = value, &block) ⇒ Object
(also: #<<)
Pushes the value into the queue.
Constructor Details
#initialize(cls, *args, &block) ⇒ Single
Constructor.
51 52 53 54 55 56 57 |
# File 'lib/unified-queues/single.rb', line 51 def initialize(cls, *args, &block) if cls.kind_of? UnifiedQueues::Single::Driver @driver = cls else self.assign_driver(cls, args, block) end end |
Instance Attribute Details
#driver ⇒ UnifiedQueues::Single::Driver
Contains driver for specific class instance.
40 41 42 |
# File 'lib/unified-queues/single.rb', line 40 def driver @driver end |
Instance Method Details
#assign_driver(cls, args, block) ⇒ UnifiedQueues::Single::Driver
Assigns driver to interface according to given class name.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/unified-queues/single.rb', line 68 def assign_driver(cls, args, block) _cls = cls if not _cls.kind_of? Class _cls = cls.class end driver = nil name = nil self.class::DRIVERS.each_pair do |_name, _driver| begin _module = Module::get_module(_name.to_s) rescue NameError next end if _cls <= _module driver = _driver name = _name break end end ### require "unified-queues/single/driver/" << driver path = name.to_s.split("::") classname = path.shift << 'Driver::' << path.join('::') _module = Module::get_module("UnifiedQueues::Single::Driver::" << classname) args = [cls] + args @driver = _module::new(*args, &block) return @driver end |
#clear!(&block) ⇒ Object Also known as: clear
Clears the queue.
143 144 145 |
# File 'lib/unified-queues/single.rb', line 143 def clear!(&block) @driver.clear!(&block) end |
#empty?(&block) ⇒ Boolean
Indicates queue is empty.
135 136 137 |
# File 'lib/unified-queues/single.rb', line 135 def empty?(&block) @driver.empty?(&block) end |
#length(&block) ⇒ Integer Also known as: size
Returns length of the queue.
154 155 156 |
# File 'lib/unified-queues/single.rb', line 154 def length(&block) @driver.length(&block) end |
#pop(blocking = false, &block) ⇒ Object Also known as: pop!
Pops value out of the queue.
124 125 126 |
# File 'lib/unified-queues/single.rb', line 124 def pop(blocking = false, &block) @driver.pop(blocking, &block) end |
#push(value, key = value, &block) ⇒ Object Also known as: <<
Pushes the value into the queue.
111 112 113 |
# File 'lib/unified-queues/single.rb', line 111 def push(value, key = value, &block) @driver.push(value, key, &block) end |