Module: CompTree

Defined in:
lib/comp_tree.rb,
lib/comp_tree/node.rb,
lib/comp_tree/error.rb,
lib/comp_tree/driver.rb,
lib/comp_tree/version.rb,
lib/comp_tree/algorithm.rb,
lib/comp_tree/queue/queue_18.rb,
lib/comp_tree/queue/queue_19.rb

Overview

CompTree – Parallel Computation Tree.

See README.rdoc.

Defined Under Namespace

Modules: Algorithm Classes: Driver, Error, NoFunctionError, NoNodeError, Node, NodeError, Queue, RedefinitionError

Constant Summary collapse

VERSION =
"1.1.3"

Class Method Summary collapse

Class Method Details

.build(opts = {}) {|Driver.new(opts)| ... } ⇒ Object

:call-seq:

build { |driver| ... }

Build a new computation tree. A Driver instance is passed to the given block.

Example:

CompTree.build do |driver|

  # Define a function named 'area' taking these two arguments.
  driver.define(:area, :width, :height) { |width, height|
    width*height
  }

  # Define a function 'width' which takes a 'border' argument.
  driver.define(:width, :border) { |border|
    7 + border
  }

  # Ditto for 'height'.
  driver.define(:height, :border) { |border|
    5 + border
  }

  #    
  # Define a constant function 'border'.
  driver.define(:border) {
    2
  }

  # Compute the area using up to four parallel threads.
  puts driver.compute(:area, 4)
  # => 63

  # We've done this computation.
  puts((7 + 2)*(5 + 2))
  # => 63
end

A custom CompTree::Node subclass may optionally be provided,

CompTree.build(:node_class => MyNode) { ... }

This will build the tree with MyNode instances.

Yields:



84
85
86
# File 'lib/comp_tree.rb', line 84

def self.build(opts = {})
  yield Driver.new(opts)
end