Ascending Ordered Sparse Matrix. More...

#include <rmaxmatrix.h>

Inheritance diagram for RMaxMatrix:
[legend]
Collaboration diagram for RMaxMatrix:
[legend]

Public Member Functions

virtual void Add (size_t i, size_t j, double val)
 
virtual void Clear (double val=NAN, bool clean=false)
 
int Compare (const RMaxMatrix &matrix) const
 
RCursor< RMaxVectorGetLines (void) const
 
size_t GetNbVectors (void) const
 
virtual tType GetType (void) const
 
RMaxVectorGetValue (size_t i) const
 
virtual void Init (double val)
 
bool IsIn (size_t i) const
 
virtual double operator() (size_t i, size_t j) const
 
virtual double & operator() (size_t i, size_t j)
 
RMaxMatrixoperator= (const RMaxMatrix &matrix)
 
const RMaxVectoroperator[] (size_t i) const
 
RMaxVectoroperator[] (size_t i)
 
 RMaxMatrix (size_t nblines, size_t nbcols, bool alllines=true, size_t init=20)
 
 RMaxMatrix (const RMaxMatrix &src)
 
virtual void VerifySize (size_t newlines, size_t newcols, bool fill=false, double val=NAN)
 
virtual ~RMaxMatrix (void)
 
- Public Member Functions inherited from RGenericMatrix
int Compare (const RGenericMatrix &matrix) const
 
size_t GetNbCols (void) const
 
size_t GetNbLines (void) const
 
RGenericMatrixoperator= (const RGenericMatrix &matrix)
 
template<class S >
void Print (S &stream, const RString &name, const char *format="%E", size_t colsize=12) const
 
 RGenericMatrix (size_t size)
 
 RGenericMatrix (size_t lines, size_t cols)
 
 RGenericMatrix (const RGenericMatrix &matrix)
 
virtual ~RGenericMatrix (void)
 

Protected Attributes

bool AllLines
 
size_t InitNbCols
 
- Protected Attributes inherited from RGenericMatrix
size_t NbCols
 
size_t NbLines
 
- Protected Attributes inherited from iRContainer< C >
size_t IncPtr
 
size_t LastPtr
 
size_t MaxPtr
 
size_t NbPtr
 
C ** Tab
 

Additional Inherited Members

- Public Types inherited from RGenericMatrix
enum  tType {
  tNormal, tDiagonal, tLowerTriangular, tUpperTriangular,
  tSymmetric, tSparse, tSparseSymmetric, tMax
}
 
- Protected Member Functions inherited from RContainer< RMaxVector, true, true >
void Clear (size_t m=0, size_t i=0, bool force=false)
 
int Compare (const RContainer< RMaxVector, true, true > &) const
 
void Copy (const RContainer< RMaxVector, a, true > &src)
 
void DeletePtr (const TUse &tag, bool sortkey, bool del, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, size_t min=0, size_t max=0)
 
void DeletePtrAt (size_t pos, bool shift, bool del)
 
void DeletePtrAt (size_t pos, bool shift)
 
void DeletePtrAt (size_t pos)
 
void Exchange (size_t pos1, size_t pos2)
 
size_t GetIncNb (void) const
 
size_t GetIndex (const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
RMaxVectorGetInsertPtr (const TUse &tag, size_t min=0, size_t max=0)
 
RMaxVectorGetInsertPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
RMaxVectorGetInsertPtrAt (const TUse &tag, size_t pos)
 
size_t GetMaxNb (void) const
 
size_t GetMaxPos (void) const
 
size_t GetNb (void) const
 
RMaxVectorGetPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
RMaxVectorGetPtr (const TUse &tag, size_t min=0, size_t max=0) const
 
const RMaxVectorGetPtrAt (size_t idx) const
 
RMaxVectorGetPtrAt (size_t idx)
 
RContainer< RMaxVector, false,
true > * 
GetPtrs (const TUse &tag, size_t min=0, size_t max=0) const
 
size_t GetTab (const void **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (void **tab, size_t min=0, size_t max=0)
 
size_t GetTab (const RMaxVector **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (RMaxVector **tab, size_t min=0, size_t max=0)
 
void InsertPtr (RMaxVector *ins, bool del=false, size_t min=0, size_t max=0)
 
void InsertPtrAt (RMaxVector *ins, size_t pos, bool del)
 
void InsertPtrAt (RMaxVector *ins, size_t pos)
 
void Inter (const iRContainer< RMaxVector > &src1, const iRContainer< RMaxVector > &src2)
 
bool IsIn (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
bool IsIn (const TUse &tag, size_t min=0, size_t max=0) const
 
RContaineroperator+= (const RContainer< RMaxVector, a, o > &src)
 
RContaineroperator= (const RContainer< RMaxVector, true, true > &src)
 
RContaineroperator= (const RContainer< RMaxVector, false, true > &src)
 
const RMaxVectoroperator[] (size_t idx) const
 
RMaxVectoroperator[] (size_t idx)
 
 RContainer (const RContainer< RMaxVector, true, true > &src)
 
 RContainer (const RContainer< RMaxVector, false, true > &src)
 
 RContainer (size_t m, size_t i=0)
 
void ReOrder (int sortOrder(const void *, const void *))
 
void ReOrder (int sortOrder(const void *, const void *), size_t min, size_t max)
 
void ReOrder (void)
 
void Shift (size_t idx, bool reverse)
 
void Transfer (RContainer< RMaxVector, a, o > &src)
 
void Union (const iRContainer< RMaxVector > &src1, const iRContainer< RMaxVector > &src2)
 
bool VerifyIndex (size_t idx) const
 
void VerifyTab (size_t max=0)
 
virtual ~RContainer (void)
 
- Protected Member Functions inherited from iRContainer< C >
iRContainerAdd (const iRContainer< C > &src)
 
void Create (const iRContainer< C > &src)
 
void DeepCopy (const iRContainer< C > &src)
 
iRContainerNormalCopy (const iRContainer< C > &src)
 
void Clear (size_t m=0, size_t i=0, bool force=false)
 
void Copy (const iRContainer< C > &src)
 
void DeletePtr (const TUse &tag, bool sortkey, bool del, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
void DeletePtr (const TUse &tag, size_t min=0, size_t max=0)
 
void DeletePtrAt (size_t pos, bool shift)
 
void DeletePtrAt (size_t pos)
 
void DeletePtrAt (size_t pos, bool shift, bool del)
 
void Exchange (size_t pos1, size_t pos2)
 
size_t GetIncNb (void) const
 
size_t GetIndex (const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
size_t GetIndex (bool order, const TUse &tag, bool &find, size_t min=0, size_t max=0) const
 
C * GetInsertPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0)
 
C * GetInsertPtr (const TUse &tag, size_t min=0, size_t max=0)
 
C * GetInsertPtrAt (const TUse &tag, size_t pos)
 
size_t GetMaxNb (void) const
 
size_t GetMaxPos (void) const
 
size_t GetNb (void) const
 
C * GetPtr (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
C * GetPtr (const TUse &tag, size_t min=0, size_t max=0) const
 
const C * GetPtrAt (size_t idx) const
 
C * GetPtrAt (size_t idx)
 
size_t GetTab (const C **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (C **tab, size_t min=0, size_t max=0)
 
size_t GetTab (const void **tab, size_t min=0, size_t max=0) const
 
size_t GetTab (void **tab, size_t min=0, size_t max=0)
 
void InsertPtr (C *ins, bool del=false, size_t min=0, size_t max=0)
 
void InsertPtrAt (C *ins, size_t pos, bool del)
 
void InsertPtrAt (C *ins, size_t pos)
 
void Inter (const iRContainer< C > &src1, const iRContainer< C > &src2)
 
bool IsIn (const TUse &tag, size_t min=0, size_t max=0) const
 
bool IsIn (const TUse &tag, bool sortkey, size_t min=0, size_t max=0) const
 
iRContaineroperator+= (const iRContainer< C > &src)
 
iRContaineroperator= (const iRContainer< C > &src)
 
const C * operator[] (size_t idx) const
 
C * operator[] (size_t idx)
 
void ReOrder (int sortOrder(const void *, const void *), size_t min, size_t max)
 
void ReOrder (int sortOrder(const void *, const void *))
 
void ReOrder (void)
 
void Shift (size_t idx, bool reverse)
 
void Transfer (iRContainer< C > &src)
 
void Union (const iRContainer< C > &src1, const iRContainer< C > &src2)
 
bool VerifyIndex (size_t idx) const
 
void VerifyTab (size_t max=0)
 
virtual ~iRContainer (void)
 
- Static Protected Member Functions inherited from RContainer< RMaxVector, true, true >
static int SortOrder (const void *a, const void *b)
 
- Static Protected Member Functions inherited from iRContainer< C >
static int SortOrder (const void *a, const void *b)
 

Detailed Description

Ascending Ordered Sparse Matrix.

The RMaxMatrix provides a representation for a sparse ordered matrix. The matrix is coded as a container of RMaxVector. To speed up the access, a vector can be build for every line of the matrix.

Here is an example of code:

RMaxMatrix a(2,2); // Matrix initially contains 2 lines and 2 values per line.
a.Add(0,1,0.2); // First element of line 0 is (0,1)
a.Add(0,2,1.5); // Second element of line 0 is (0,2)
a.Add(1,2,1.0); // First element of line 1 is (1,2)
a.Add(1,3,5.1); // Second element of line 1 is (1,3)
for(size_t i=0;i<2;i++)
{
for(size_t j=0;j<a[i]->GetNb();j++)
cout<<static_cast<const RMaxMatrix&>(a)(i,j)<<"\t";
cout<<endl;
}

The number of of the columns of the matrix is fixed (but can be changed). It represents the maximal number of elements per line. Of course, an identifier can be greater than a column index (see example). The following code will generate an exception since the matrix a is of size $2 \cdot 2$.

cout<<static_cast<const RMaxMatrix&>(a)(1,3)<<endl; // There are already two elements in the matrix at line 1

An important aspect is the use of static_cast<const RMaxMatrix&> to ensure the call of the const version of the operator(). If static_cast<const RMaxMatrix&> is not used, the different elements are created with uninitialized values.

Constructor & Destructor Documentation

RMaxMatrix ( size_t  nblines,
size_t  nbcols,
bool  alllines = true,
size_t  init = 20 
)

Construct a sparse matrix.

Parameters
nblinesNumber of lines (not the number of vectors).
nbcolsMaximal number of values for each line.
alllinesAll lines have a vector.
initInitial number of elements to reserve for each line.
RMaxMatrix ( const RMaxMatrix src)

Copy constructor of a sparse matrix.

Parameters
srcSparse matrix used as source.
virtual ~RMaxMatrix ( void  )
virtual

Destruct the sparse matrix.

Member Function Documentation

int Compare ( const RMaxMatrix matrix) const

Compare method used by RContainer.

Parameters
matrixMatrix to compare with.
Returns
always -1.
virtual void Clear ( double  val = NAN,
bool  clean = false 
)
virtual

Clear the matrix. All the elements are removed.

Parameters
valValue eventually used to assign to the elements (not used for sparse matrix).
cleanClean eventually only the memory.

Reimplemented from RGenericMatrix.

virtual void Init ( double  val)
virtual

Initialize the matrix with a given value. It uses the operator(i,j) to initialize the different elements.

Parameters
valValue to assign.

Reimplemented from RGenericMatrix.

virtual void VerifySize ( size_t  newlines,
size_t  newcols,
bool  fill = false,
double  val = NAN 
)
virtual

Verify if the matrix has a given size, and increase them if necessary.

Parameters
newlinesNew line number.
newcolsNew column number.
fillElements must be filled with a value (Not used for sparse matrix).
valValue used eventually to fill the elements created (Not used for sparse matrix).

Implements RGenericMatrix.

virtual tType GetType ( void  ) const
virtual

Get the type of the matrix.

Implements RGenericMatrix.

size_t GetNbVectors ( void  ) const

Get the number of vectors contained in the matrix. If the matrix does not create a vector for each line, the number of vectors does not correspond to the number of lines of the matrix.

RCursor<RMaxVector> GetLines ( void  ) const

Get a cursor over the vectors of the matrix.

RMaxMatrix& operator= ( const RMaxMatrix matrix)

The assignment operator.

Parameters
matrixSparse Matrix used as source.
virtual double operator() ( size_t  i,
size_t  j 
) const
virtual

Return a specific element of the matrix (const version).

Parameters
iLine number of the element.
jIndex of the element.

Implements RGenericMatrix.

virtual double& operator() ( size_t  i,
size_t  j 
)
virtual

Return a specific element of the matrix. This function cannot be used with RMaxMatrix.

Parameters
iLine number of the element.
jIndex of the element.

Implements RGenericMatrix.

virtual void Add ( size_t  i,
size_t  j,
double  val 
)
virtual

Add a value associated to a given line and identifier into the matrix. If the number of elements for that line equals the size of the matrix, the value is only inserted if another value of that line is smaller (this latest value will then be removed).

Parameters
iLine number of the element.
jIdentifier of the element.
valValue to add.

Reimplemented from RGenericMatrix.

const RMaxVector* operator[] ( size_t  i) const

Return the vector at a given line from the matrix (const version).

Parameters
iLine number of the vector.
RMaxVector* operator[] ( size_t  i)

Return the vector at a given line from the matrix.

Parameters
iLine number of the vector.
bool IsIn ( size_t  i) const

Verify if a given identifier has a vector defined in the matrix.

Parameters
iIdentifier.
Returns
true or false.
RMaxVector* GetValue ( size_t  i) const

Get a pointer over the vector associated with a given identifier.

Parameters
iIdentifier.
Returns
Pointer or null if the identifier hasn't no vector.

Member Data Documentation

bool AllLines
protected

All lines have an entry.

size_t InitNbCols
protected

Initial number of values to reserve for each line.