Source for file Tuple.php
Documentation is available at Tuple.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
// +----------------------------------------------------------------------+
// $Id: Tuple.php 304045 2010-10-05 00:16:53Z clockwerx $
* A Tuple represents a general unidimensional list of n numeric elements
* Originally this class was part of NumPHP (Numeric PHP package)
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* array of numeric elements
* Constructor of Math_Tuple
* @param array $data array of numbers
* @return object Math_Tuple (or PEAR_Error on error)
new PEAR_Error ("An unidimensional array is needed to initialize a Tuple",
* Squeezes out holes in the tuple sequence
* Returns the size (number of elements) in the tuple
return count($this->data);
* Sets the value of an element
* @param integer $elindex element index
* @param numeric $elvalue element value
* @return mixed true if successful, PEAR_Error object otherwise
if ($elindex >= $this->getSize()) {
return PEAR ::raiseError (" Wrong index: $elindex for element: $elvalue" );
$this->data[$elindex] = $elvalue;
* Appends an element to the tuple
* @param numeric $elvalue element value
* @return mixed index of appended element on success, PEAR_Error object otherwise
return PEAR ::raiseError (" Error, a numeric value is needed. You used: $elvalue" );
$this->data[$this->getSize()] = $elvalue;
* Remove an element from the tuple
* @param integer $elindex element index
* @return mixed true on success, PEAR_Error object otherwise
if ($elindex >= $this->getSize()) {
return PEAR ::raiseError (" Wrong index: $elindex, element not deleted" );
unset ($this->data[$elindex]);
* Returns the value of an element in the tuple
* @param integer $elindex element index
* @return mixed numeric on success, PEAR_Error otherwise
if ($elindex >= $this->getSize()) {
return PEAR ::raiseError (" Wrong index: $elindex, Tuple size is: ". $this->getSize());
return $this->data[$elindex];
* Returns an array with all the elements of the tuple
* Returns the minimum value of the tuple
* Returns the maximum value of the tuple
* Returns an array of the minimum and maximum values of the tuple
* @return array of the minimum and maximum values
* Gets the position of the given value in the tuple
* @param numeric $val value for which the index is requested
for ($i=0; $i < $this->getSize(); $i++ )
if ($this->data[$i] == $val)
* Gets the position of the minimum value in the tuple
* Gets the position of the maximum value in the tuple
* Gets an array of the positions of the minimum and maximum values in the tuple
* @return array of integers indexes
* Checks if the tuple is a a Zero tuple
for ($i=0; $i < $this->getSize(); $i++ )
if ($this->data[$i] != 0 )
* Returns an string representation of the tuple
return "{ ". implode(", ",$this->data). " }";
* Returns an HTML representation of the tuple
$out = "<table border>\n\t<caption align=\"top\"><b>Vector</b></caption>\n";
$out .= "\t<tr align=\"center\">\n\t\t<th>i</th><th>value</th>\n\t</tr>\n";
for ($i=0; $i < $this->getSize(); $i++ ) {
$out .= "\t<tr align=\"center\">\n\t\t<th>". $i. "</th>";
$out .= "<td bgcolor=\"#dddddd\">". $this->data[$i]. "</td>\n\t</tr>\n";
return $out. "\n</table>\n";
} /* end of Tuple class */
Documentation generated on Mon, 11 Mar 2019 15:39:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|