smatrixn.h

来自「basic mathematic classes used for math p」· C头文件 代码 · 共 99 行

H
99
字号
//// Sparse Matrix:	Aug 11, 1998//#ifndef	_SPARSE_MATRIX_H_#define	_SPARSE_MATRIX_H_#define	HEAD_ENTITY	-1#define	MEANINGLESS	0struct	entity
{
	int		id;
	m_real	value;
	entity*	next;
};class	vectorN;

class   SparseMatrixN{ // More general sparse matrix  and assume the max matrix dimension is 65535*65535


	public:
	SparseMatrixN(int n)	{ allocate(n); }
	SparseMatrixN();
	~SparseMatrixN()	{ deallocate(); }

	void setSize(int n);

	int		size() const	{ return n; }
	int		getSize() const	{ return n; }

	void	allocate(int n);
	void	deallocate();

	m_real	setValue(int row, int col, m_real value, entity** e = NULL);
	m_real	getValue(int row, int col) const;

	entity  getRows( int i ) const { return rows[i]; }
    int     getColNum(int row);

	m_real	add(int row, int col, m_real increment);
	m_real	sub(int row, int col, m_real decrement);
	m_real  deleteEntity(int row, int col);
	m_real  sumRow(int row);
	int     deleteSmallValEntity(int row, m_real valthres);
	int  multiplyRow(int row, m_real val);
	bool  isRowEmpty(int row);


	SparseMatrixN& add( SparseMatrixN& a, SparseMatrixN& b);

	friend ostream& operator<<(ostream& os, SparseMatrixN& A);
	friend istream& operator>>(istream& is, SparseMatrixN& A);

protected:
	int		n;		// n x n sparse matrix

	int		nnze;	// number of non-zero entity
	entity*	rows;


};
class	smatrixN   // This one is assumed to be symmetric, will be changed to be the derived class of 
// SparseMatrixN{public:	smatrixN(int n)	{ allocate(n); }	~smatrixN()	{ deallocate(); }	int		size() const	{ return n; }	int		getSize() const	{ return n; }	void	allocate(int n);	void	deallocate();	m_real	setValue(int row, int col, m_real value, entity** e = NULL);	m_real	getValue(int row, int col) const;	entity  getRows( int i ) const { return rows[i]; }	m_real	add(int row, int col, m_real increment);	m_real	sub(int row, int col, m_real decrement);	smatrixN& add( smatrixN& a, smatrixN& b);	friend ostream& operator<<(ostream& os, smatrixN& A);	friend istream& operator>>(istream& is, smatrixN& A);private:	int		n;		// n x n sparse matrix	int		nnze;	// number of non-zero entity	entity*	rows;};#endif	// _SPARSE_MATRIX_H_

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?