37#define G_CONSTRUCTOR "GVectorSparse::GVectorSparse(int&)"
38#define G_OPERATOR "GVectorSparse::operator[](int&)"
108 for (
int i = 0, idst = 0; i < vector.
size(); ++i) {
109 if (vector[i] != 0.0) {
167 if (
this != &vector) {
286 #if defined(G_RANGE_CHECK)
287 if (index < 0 || index >=
size()) {
294 double* result = NULL;
301 if (
m_inx[i] == index) {
307 else if (
m_inx[i] > index) {
324 if (result == NULL) {
358 static double zero = 0.0;
361 #if defined(G_RANGE_CHECK)
362 if (index < 0 || index >=
size()) {
372 const double* result = (
inx != -1) ? &(
m_data[
inx]) : &zero;
394 result.append(
"=== GVectorSparse ===");
453 if (vector.
m_inx != NULL) {
461 if (vector.
m_data != NULL) {
510 m_inx =
new int[alloc];
511 m_data =
new double[alloc];
538 if (
m_inx[i] == index) {
568 int* new_inx =
m_inx;
569 double* new_data =
m_data;
581 new_data =
new double[
m_alloc];
587 for (
int i = 0; i < index; ++i) {
588 new_inx[i] =
m_inx[i];
597 new_inx[i] =
m_inx[i-1];
598 new_data[i] =
m_data[i-1];
602 new_inx[index] =
inx;
603 new_data[index] =
data;
Sparce vector class interface definition.
#define G_SPARSE_VECTOR_DEFAULT_MEM_BLOCK
Vector class interface definition.
int m_elements
Number of elements in vector.
void alloc_members(const int &alloc)
Allocate memory for elements.
void copy_members(const GVectorSparse &vector)
Copy class members.
GVectorSparse & operator=(const GVectorSparse &vector)
Assignment operator.
int m_alloc
Number of allocated elements.
void free_members(void)
Delete class members.
int index2inx(const int &index) const
Return inx for element index.
GVectorSparse(void)
Void sparse vector constructor.
double & operator[](const int &index)
Sparse vector element access with range checking.
void clear(void)
Clear sparse vector.
bool operator==(const GVectorSparse &vector) const
Equality operator.
const int & size(void) const
Return full size of sparse vector.
const int & inx(const int &index) const
Return inx for sparse vector element.
GVectorSparse * clone(void) const
Clone sparse vector.
const double & data(const int &index) const
Return value for sparse vector element.
bool operator!=(const GVectorSparse &vector) const
Non-equality operator.
virtual ~GVectorSparse(void)
Destructor.
void insert(const int &index, const int &inx, const double &data)
Insert one element into sparse vector.
void init_members(void)
Initialise class members.
double * m_data
Data array.
int m_colinx
Column index.
std::string print(const GChatter &chatter=NORMAL) const
Print sparse vector information.
const int & size(void) const
Return size of vector.
int non_zeros(void) const
Returns number of non-zero elements in vector.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.