Class: Dynflow::Director::QueueHash
- Inherits:
-
Object
- Object
- Dynflow::Director::QueueHash
- Includes:
- Algebrick::TypeCheck
- Defined in:
- lib/dynflow/director/queue_hash.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #empty?(key) ⇒ Boolean
- #first(key) ⇒ Object
-
#initialize(key_type = Object, value_type = Object) ⇒ QueueHash
constructor
A new instance of QueueHash.
- #present?(key) ⇒ Boolean
- #push(key, value) ⇒ Object
- #shift(key) ⇒ Object
- #size(key) ⇒ Object
Constructor Details
#initialize(key_type = Object, value_type = Object) ⇒ QueueHash
Returns a new instance of QueueHash.
7 8 9 10 11 |
# File 'lib/dynflow/director/queue_hash.rb', line 7 def initialize(key_type = Object, value_type = Object) @key_type = key_type @value_type = value_type @stash = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#clear ⇒ Object
32 33 34 35 36 |
# File 'lib/dynflow/director/queue_hash.rb', line 32 def clear ret = @stash.dup @stash.clear ret end |
#empty?(key) ⇒ Boolean
28 29 30 |
# File 'lib/dynflow/director/queue_hash.rb', line 28 def empty?(key) !present?(key) end |
#first(key) ⇒ Object
43 44 45 46 |
# File 'lib/dynflow/director/queue_hash.rb', line 43 def first(key) return nil if empty?(key) @stash[key].first end |
#present?(key) ⇒ Boolean
24 25 26 |
# File 'lib/dynflow/director/queue_hash.rb', line 24 def present?(key) @stash.key?(key) end |
#push(key, value) ⇒ Object
13 14 15 16 17 |
# File 'lib/dynflow/director/queue_hash.rb', line 13 def push(key, value) Type! key, @key_type Type! value, @value_type @stash[key].push value end |
#shift(key) ⇒ Object
19 20 21 22 |
# File 'lib/dynflow/director/queue_hash.rb', line 19 def shift(key) return nil unless present? key @stash[key].shift.tap { @stash.delete(key) if @stash[key].empty? } end |
#size(key) ⇒ Object
38 39 40 41 |
# File 'lib/dynflow/director/queue_hash.rb', line 38 def size(key) return 0 if empty?(key) @stash[key].size end |