eZ Publish  [4.0]
ezdiffmatrix.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZDiffMatrix class
00004 //
00005 // <05-Apr-2006 14:42:42>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezdiffmatrix.php
00032   eZDiffMatrix class
00033 */
00034 
00035 /*!
00036   \class eZDiffMatrix ezdiffmatrix.php
00037   \ingroup eZDiff
00038   \biref This class will store values concerned with diff data
00039 
00040   The eZDiffMatrix class will avoid storing 0, which for a large matrix will save
00041   memory.
00042 */
00043 
00044 class eZDiffMatrix
00045 {
00046 
00047     /*!
00048       Constructor
00049     */
00050     function eZDiffMatrix( $rows = null, $cols = null)
00051     {
00052         if ( isset( $rows ) && is_numeric( $rows ) )
00053             $this->Rows = $rows;
00054 
00055         if ( isset( $cols ) && is_numeric( $cols ) )
00056             $this->Cols = $cols;
00057     }
00058 
00059     /*!
00060       \public
00061       Sets the dimensions of the matrix
00062     */
00063     function setSize( $nRows, $nCols )
00064     {
00065         $this->Rows = $nRows;
00066         $this->Cols = $nCols;
00067     }
00068 
00069     /*!
00070       \public
00071       This method will set (\a $row, \a $col) in the matrix to \a $value, if
00072       it is not zero.
00073     */
00074     function set( $row, $col, $value )
00075     {
00076         if ( $value !== 0 )
00077         {
00078             $pos = $row * $this->Cols + $col;
00079             $pos = base_convert( $pos, 10, 36 );
00080             $this->Matrix["*$pos"] = $value;
00081         }
00082     }
00083 
00084     /*!
00085       \public
00086       This method will return the value at position (\a $row, \a $col)
00087     */
00088     function get( $row, $col )
00089     {
00090         $pos = $row * $this->Cols + $col;
00091         $pos = base_convert( $pos, 10, 36 );
00092         return isset( $this->Matrix["*$pos"] ) ? $this->Matrix["*$pos"] : 0;
00093     }
00094 
00095     ///\privatesection
00096     /// Internal array, holding necessary values.
00097     public $Matrix = array();
00098 
00099     /// Internal variable, width of the matrix.
00100     public $Cols;
00101 
00102     /// Internal variable, height of the matrix.
00103     public $Rows;
00104 }
00105 
00106 ?>