Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Math\Combinatorics\Combination\CartesianProduct Class Reference
Inheritance diagram for Hoa\Math\Combinatorics\Combination\CartesianProduct:

Public Member Functions

 __construct ($set)
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Member Functions

 _current ()
 

Protected Attributes

 $_sets = []
 
 $_max = 0
 
 $_key = 0
 
 $_current = null
 
 $_break = true
 

Detailed Description

Class .

Cartesian n-ary product iterator: X = {1, 2} Y = {a, b} Z = {A, B, C} X × Y × Z = { (1, a, A), (2, a, A), (1, b, A), (2, b, A) (1, a, B), (2, a, B), (1, b, B), (2, b, B) (1, a, C), (2, a, C), (1, b, C), (2, b, C) }

Definition at line 55 of file CartesianProduct.php.

Constructor & Destructor Documentation

Hoa\Math\Combinatorics\Combination\CartesianProduct::__construct (   $set)

Constructor.

Parameters
\Traversable$setSet.
… …
Returns
void

Definition at line 101 of file CartesianProduct.php.

102  {
103  foreach (func_get_args() as $s) {
104  if (is_array($s)) {
105  $s = new Iterator\Map($s);
106  } else {
107  $s = new Iterator\IteratorIterator($s);
108  }
109 
110  $this->_sets[] = $s;
111  }
112 
113  $this->_max = count($this->_sets) - 1;
114  $this->_break = empty($this->_sets);
115 
116  return;
117  }

Member Function Documentation

Hoa\Math\Combinatorics\Combination\CartesianProduct::_current ( )
protected

Prepare the current value.

Returns
void

Definition at line 134 of file CartesianProduct.php.

135  {
136  $this->_current = [];
137 
138  foreach ($this->_sets as $set) {
139  $this->_current[] = $set->current();
140  }
141 
142  return;
143  }

Here is the caller graph for this function:

Hoa\Math\Combinatorics\Combination\CartesianProduct::current ( )

Get the current value.

Returns
array

Definition at line 124 of file CartesianProduct.php.

Here is the caller graph for this function:

Hoa\Math\Combinatorics\Combination\CartesianProduct::key ( )

Get the current key.

Returns
int

Definition at line 150 of file CartesianProduct.php.

Hoa\Math\Combinatorics\Combination\CartesianProduct::next ( )

Advance the internal collection pointer, and return the current value.

Returns
array

Definition at line 160 of file CartesianProduct.php.

161  {
162  for ($i = 0; $i <= $this->_max; ++$i) {
163  $this->_sets[$i]->next();
164 
165  if (false !== $this->_sets[$i]->valid()) {
166  break;
167  }
168 
169  $this->_sets[$i]->rewind();
170 
171  if ($i === $this->_max) {
172  $this->_break = true;
173 
174  break;
175  }
176  }
177 
178  ++$this->_key;
179  $this->_current();
180 
181  return $this->current();
182  }

Here is the call graph for this function:

Hoa\Math\Combinatorics\Combination\CartesianProduct::rewind ( )

Rewind the internal collection pointer, and return the first collection.

Returns
array

Definition at line 189 of file CartesianProduct.php.

190  {
191  $this->_break = empty($this->_sets);
192  $this->_key = 0;
193 
194  foreach ($this->_sets as $set) {
195  $set->rewind();
196  }
197 
198  $this->_current();
199 
200  return $this->current();
201  }

Here is the call graph for this function:

Hoa\Math\Combinatorics\Combination\CartesianProduct::valid ( )

Check if there is a current element after calls to the rewind() or the next() methods.

Returns
bool

Definition at line 209 of file CartesianProduct.php.

Here is the caller graph for this function:

Member Data Documentation

Hoa\Math\Combinatorics\Combination\CartesianProduct::$_break = true
protected

Definition at line 90 of file CartesianProduct.php.

Hoa\Math\Combinatorics\Combination\CartesianProduct::$_current = null
protected

Definition at line 83 of file CartesianProduct.php.

Hoa\Math\Combinatorics\Combination\CartesianProduct::$_key = 0
protected

Definition at line 76 of file CartesianProduct.php.

Hoa\Math\Combinatorics\Combination\CartesianProduct::$_max = 0
protected

Definition at line 69 of file CartesianProduct.php.

Hoa\Math\Combinatorics\Combination\CartesianProduct::$_sets = []
protected

Definition at line 62 of file CartesianProduct.php.


The documentation for this class was generated from the following file: