Example for a sparse array 2D
- Author
- MIP
#include <iostream>
#include <Base/Common/SparseArray2D.hh>
using namespace BIAS;
using namespace std;
class foo
{
public:
void set(const double d) { data=d; }
double get() const { return data; }
protected:
double data;
};
{
os << f.get();
return os;
}
{
cout << a << endl;
}
int main()
{
cout << "empty SparseArray2D: ";
print(array);
cout <<
"empty() = "<<boolalpha<<array.
empty()<<endl;
cout << "empty Array2D of size 2x2 : ";
print(array);
foo f;
f.set(2.0);
array(0,1) = f;
cout << "filled Array2D of size 2x2 : ";
print(array);
array(2,2) = f;
cout << "partially filled Array2D of size 3x3 : ";
print(array);
cout <<
"indices (4,0) are valid: "<<boolalpha<<array.
is_valid(4,0)<<endl;
cout <<
"indices (2,2) are valid: "<<boolalpha<<array.
is_valid(2,2)<<endl;
cout <<
"indices (2,1) are valid: "<<boolalpha<<array.
is_valid(2,1)<<endl;
int i=0;
for (it = array.
begin(); it!=array.
end(); it++, i++){
it->set((double)i);
}
cout << "partially filled Array2D of size 3x3 : ";
print(array);
unsigned c, r;
for (r=0; r<3; r++){
for (c=0; c<3; c++){
array(r,c).set(r*3+c);
}
}
cout << "filled Array2D of size 3x3 : ";
print(array);
cout << "array[1][1] = "<<array(1,1).get()<<endl;
return 0;
}