Class: Duke::Iterator
- Inherits:
-
RecursiveAction
- Object
- RecursiveAction
- Duke::Iterator
- Defined in:
- lib/duke/iterator.rb
Overview
The iterator is a recursive action that executes in parallel on a ForkJoinPool.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
- #block The block to execute on each object.(Theblocktoexecuteoneachobject.) ⇒ Object readonly
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
- #objects The array to process.(Thearraytoprocess.) ⇒ Object readonly
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
- #threshold The single process threshold count.(Thesingleprocessthresholdcount.) ⇒ Object readonly
Instance Method Summary collapse
-
#compute ⇒ nil
Splits the work into the appropriate chunks and executes in parallel.
-
#initialize(objects, threshold, block) ⇒ Duke::Iterator
constructor
Instantiate the new iterator.
-
#invoke_all(*args) ⇒ nil
Convenience method for invoking against the class.
Constructor Details
#initialize(objects, threshold, block) ⇒ Duke::Iterator
Instantiate the new iterator.
48 49 50 51 |
# File 'lib/duke/iterator.rb', line 48 def initialize(objects, threshold, block) super() @objects, @threshold, @block = objects, threshold, block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
13 14 15 |
# File 'lib/duke/iterator.rb', line 13 def block @block end |
#block The block to execute on each object.(Theblocktoexecuteoneachobject.) ⇒ Object (readonly)
13 |
# File 'lib/duke/iterator.rb', line 13 attr_reader :block, :objects, :threshold |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
13 14 15 |
# File 'lib/duke/iterator.rb', line 13 def objects @objects end |
#objects The array to process.(Thearraytoprocess.) ⇒ Object (readonly)
13 |
# File 'lib/duke/iterator.rb', line 13 attr_reader :block, :objects, :threshold |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
13 14 15 |
# File 'lib/duke/iterator.rb', line 13 def threshold @threshold end |
#threshold The single process threshold count.(Thesingleprocessthresholdcount.) ⇒ Object (readonly)
13 |
# File 'lib/duke/iterator.rb', line 13 attr_reader :block, :objects, :threshold |
Instance Method Details
#compute ⇒ nil
Splits the work into the appropriate chunks and executes in parallel.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/duke/iterator.rb', line 23 def compute if objects.size <= threshold objects.each do |object| block.call(object) end else midpoint = objects.size / 2 invoke_all( Iterator.new(objects[0, midpoint], threshold, block), Iterator.new(objects[midpoint, objects.size], threshold, block) ) end end |
#invoke_all(*args) ⇒ nil
Convenience method for invoking against the class.
63 64 65 |
# File 'lib/duke/iterator.rb', line 63 def invoke_all(*args) self.class.invoke_all(*args) end |