1 #ifndef SPARSE_MATRIX_HH 2 #define SPARSE_MATRIX_HH 34 typedef std::pair<size_type,size_type>
key_t;
82 typename map_t::const_iterator it = m_->
the_map_.find(k_);
102 const_iterator it = m_->
the_map_.find(k_);
130 typename map_t::iterator it = m_->
the_map_.find(k_);
134 m_->
the_map_.insert(
typename map_t::value_type(k_,x));
175 const value_t &
operator() (size_type i, size_type j)
const {
176 const_iterator it = the_map_.find(
key_t(i,j));
177 if ( it == the_map_.end() )
197 set(size_type i, size_type j,
const value_t &val) {
198 typename map_t::iterator it = the_map_.find(
key_t(i,j));
199 if ( it != the_map_.end() ) {
202 the_map_.insert(
typename map_t::value_type(
key_t(i,j),val));
217 ref(size_type i, size_type j) {
218 typename map_t::iterator it = the_map_.find(
key_t(i,j));
219 if ( it == the_map_.end() ) {
220 the_map_.insert(
typename map_t::value_type(
key_t(i,j),def_));
221 it = the_map_.find(
key_t(i,j));
234 typename map_t::iterator it = the_map_.find(
key_t(i,j));
235 if ( it != the_map_.end() ) {
236 the_map_.erase(
key_t(i,j));
246 return the_map_.size();
256 return the_map_.empty();
276 return the_map_.begin();
287 return the_map_.end();
313 operator <<(std::ostream &out, const SparseMatrix<T> &m) {
317 out <<
"("<<it->first.first<<
","<<it->first.second <<
") " << it->second << std::endl;
324 #endif // SPARSE_MATRIX_HH element operator()(size_type i, size_type j)
Access to matrix element.
Definition: sparse_matrix.hh:163
const value_t & def() const
Default value.
Definition: sparse_matrix.hh:297
void reset(size_type i, size_type j)
Set matrix entry to default value.
Definition: sparse_matrix.hh:233
element operator+=(const value_t &x)
Operator for in place addition.
Definition: sparse_matrix.hh:101
T value_t
type of matrix entries
Definition: sparse_matrix.hh:30
void clear()
Clear the matrix.
Definition: sparse_matrix.hh:263
const_iterator begin() const
Begin const iterator over matrix entries.
Definition: sparse_matrix.hh:275
Definition: aligner.cc:17
value_t def_
default value of matrix entries
Definition: sparse_matrix.hh:40
size_type size() const
Size of sparse matrix.
Definition: sparse_matrix.hh:245
bool empty() const
Check for emptiness.
Definition: sparse_matrix.hh:255
size_t size_type
usual definition of size_type
Definition: sparse_matrix.hh:32
map_t::const_iterator const_iterator
Stl-compatible constant iterator over matrix elements.
Definition: sparse_matrix.hh:49
map_t the_map_
internal representation of sparse matrix
Definition: sparse_matrix.hh:39
const_iterator end() const
End const iterator over matrix entries.
Definition: sparse_matrix.hh:286
std::pair< size_type, size_type > key_t
type of matrix index pair
Definition: sparse_matrix.hh:34
Element of sparse matrix.
Definition: sparse_matrix.hh:60
SparseMatrix(const value_t &def)
Construct with default value.
Definition: sparse_matrix.hh:153
element(SparseMatrix< T > *m, key_t k)
Construct as proxy for specified element in given sparse matrix.
Definition: sparse_matrix.hh:72
SparseMatrix()
Empty constructor (with default default value)
Definition: sparse_matrix.hh:145
Represents a sparse 2D matrix.
Definition: sparse_matrix.hh:27
unordered_map< key_t, value_t, pair_of_size_t_hash >::type map_t
map type
Definition: sparse_matrix.hh:38
element & operator=(const value_t &x)
Assignment operator.
Definition: sparse_matrix.hh:123
value_t & ref(size_type i, size_type j)
Write access to matrix element of const matrix.
Definition: sparse_matrix.hh:217