SDPSL
Semidefinite Programming Specification Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Pages
sdp::MatrixMask Class Reference

Implements a matrix bit-mask. More...

#include <matrixmask.h>

Classes

struct  Position
 A position in the mask. More...
 

Public Types

typedef std::list< Position >
::const_iterator 
const_iterator
 Constant iterator.
 

Public Member Functions

 MatrixMask (int nn)
 Constructs an nn by nn mask with all entries off.
 
 MatrixMask (int mm, int nn)
 Constructs an mm by nn mask with all entries off.
 
 MatrixMask (const MatrixMask &other)
 Copy constructor.
 
MatrixMaskoperator= (const MatrixMask &)=delete
 Assignment is not implemented.
 
int on_count () const
 Returns number of on positions.
 
int num_rows () const
 Returns number of rows.
 
int num_cols () const
 Returns number of columns.
 
bool is_on (int i, int j) const
 Returns true if entry (i, j) of the mask is on.
 
void turn_on (int i, int j)
 Turns on entry (i, j) of the mask.
 
void turn_off (int i, int j)
 Turns off entry (i, j) of the mask.
 
void clear ()
 Clears the whole mask, turning off all entries.
 
const_iterator begin () const
 Returns iterator to the beginning of the list of on positions.
 
const_iterator end () const
 Returns past-the-end iterator to the list of on positions.
 

Friends

class shared_ref< MatrixMask >
 
class const_shared_ref< MatrixMask >
 

Detailed Description

Implements a matrix bit-mask.

A MatrixMask contains an m by n matrix of bits. It can be used, for instance, to store the nonzero positions of a matrix. Some functions use a MatrixMask in order to efficiently deal with sparse matrices.

A MatrixMask also contains a list of the entries that are on. So it is efficient to iterate over all the entries turned on.

Each entry of the mask occupies only one bit, so that even large masks do not use up too much space. So it is efficient to use masks of large size. Notice however that, if too many positions are on, then the list of positions that are turned on might come to occupy a large amount of memory. So masks are better kept sparse.

MatrixMask implements the shared reference mechanism. To understand how it works, see the documentation of shared_ref, const_shared_ref, and Matrix for an example.

Complexity
Turning a position on and checking whether a position is on or off takes constant time. Turning a position off takes at the moment time linear time on the number of positions that are on. Iteration through the list of positions that are on takes constant time per position turned on.

Iteration

MatrixMask supports both C++ and C++11 style iteration. One iterates over a list of positions, i.e., instances of struct MatrixMask::Position, containing the nonzero entries of the mask.

Todo:
In the future, it might be wise to change the list of positions on_pos to a vector. This might save memory.

The documentation for this class was generated from the following file: