Doxygen
1.9.1
|
Class that stores multi-indexes in sorted (lexicographical) order. More...
#include <tsgIndexSets.hpp>
Public Member Functions | |
MultiIndexSet () | |
Default constructor, makes an empty set. | |
MultiIndexSet (size_t cnum_dimensions, std::vector< int > &&new_indexes) | |
Constructor, makes a set by moving out of the vector, the vector must be already sorted. | |
MultiIndexSet (Data2D< int > const &data) | |
Copy a collection of unsorted indexes into a sorted multi-index set, sorts during the copy. | |
template<typename iomode > | |
MultiIndexSet (std::istream &is, iomode) | |
Read from stream constructor. | |
~MultiIndexSet ()=default | |
Default destructor. | |
template<bool useAscii> | |
void | write (std::ostream &os) const |
Write the set to ASCII or binary stream, use with std::ofstream and std::ifstream. More... | |
bool | empty () const |
Returns true if there are no multi-indexes in the set, false otherwise. | |
size_t | getNumDimensions () const |
Returns the number of dimensions. | |
int | getNumIndexes () const |
Returns the number of indexes. | |
void | addSortedIndexes (std::vector< int > const &addition) |
Add more indexes to a non-empty set, addition must be sorted and the set must be initialized. | |
MultiIndexSet & | operator+= (MultiIndexSet const &addition) |
If empty, copy addition, otherwise merge the indexes of addition into this set, i.e., set union. | |
std::vector< int >::const_iterator | begin () const |
Returns a const iterator to the beginning of the internal data. | |
std::vector< int >::const_iterator | end () const |
Returns a const iterator to the end of the internal data. | |
size_t | totalSize () const |
Returns the number of dimensions times the number of indexes. | |
std::vector< int > | release () |
Moves the index vector out of the class, this method invalidates the object. | |
int | getSlot (const int *p) const |
Returns the slot containing index p, returns -1 if not found. | |
int | getSlot (const std::vector< int > &p) const |
Returns the slot containing index p, returns -1 if not found. | |
bool | missing (const std::vector< int > &p) const |
Returns true if p is missing from the set, false otherwise. | |
const int * | getIndex (int i) const |
Returns the i-th index of the set, useful to loop over all indexes or to cross reference with values. | |
std::vector< int > | copyIndex (int i) const |
Returns a copy of the i-th index of the set. | |
MultiIndexSet | operator- (const MultiIndexSet &substract) const |
Return a new multi-index set that holds the indexed present in this set, but missing in substract. More... | |
void | removeIndex (const std::vector< int > &p) |
Removes p from the set (if exists). | |
int | getMaxIndex () const |
Returns the maximum single index in the set. | |
Class that stores multi-indexes in sorted (lexicographical) order.
At the core of each sparse grid, there are multiple multi-index sets. The organization of the data is similar to the Data2D class, but at any time the indexes are stored in a lexicographical order. The main functionality provided here is:
void TasGrid::MultiIndexSet::write | ( | std::ostream & | os | ) | const |
Write the set to ASCII or binary stream, use with std::ofstream and std::ifstream.
The format consists of two int
values corresponding to the number of dimensions and number of indexes, followed by all the entries of the array on a single line separated by a space, or dump of a single write command.
MultiIndexSet TasGrid::MultiIndexSet::operator- | ( | const MultiIndexSet & | substract | ) | const |
Return a new multi-index set that holds the indexed present in this set, but missing in substract.
Assumes that substract has the same dimension as this set. The implementation uses an algorithm similar to merge with complexity linear in the number of multi-indexes of the two sets, i.e., does not use missing() which would add a logarithmic factor.