|
| IndexTree () |
|
| IndexTree (const std::string &serialization, Mode mode) |
|
virtual | ~IndexTree () |
|
void | add (const Index &index) |
|
void | generateLinearMap () |
|
bool | getLinearMapIsGenerated () const |
|
int | getLinearIndex (const Index &index, SearchMode searchMode=SearchMode::StrictMatch, bool returnNegativeForMissingIndex=false) const |
|
Index | getPhysicalIndex (int linearIndex) const |
|
bool | contains (const Index &index) |
|
int | getSize () const |
|
std::vector< unsigned int > | getSubindicesMatching (int subindexValue, const Index &index, SearchMode searchMode) const |
|
std::vector< Index > | getIndexList (const Index &pattern) const |
|
bool | equals (const IndexTree &indexTree) const |
|
ConstIterator | begin () const |
|
ConstIterator | cbegin () const |
|
ConstIterator | end () const |
|
ConstIterator | cend () const |
|
virtual std::string | toString () const |
|
std::string | serialize (Mode mode) const |
|
template<> |
std::string | serialize (const bool &data, Mode mode) |
|
template<> |
std::string | serialize (const double &data, Mode mode) |
|
template<> |
std::string | serialize (const std::complex< double > &data, Mode mode) |
|
template<> |
std::string | serialize (const int &data, Mode mode) |
|
template<> |
std::string | serialize (const unsigned int &data, Mode mode) |
|
template<> |
std::string | serialize (const SpinMatrix &data, Mode mode) |
|
template<> |
std::string | serialize (const Statistics &data, Mode mode) |
|
template<> |
std::string | serialize (const std::vector< std::complex< double >> &data, Mode mode) |
|
template<> |
int | deserialize (const std::string &serialization, Mode mode) |
|
|
static bool | hasID (const std::string &serialization, Mode mode) |
|
static std::string | getID (const std::string &serialization, Mode mode) |
|
static std::string | extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode) |
|
static bool | validate (const std::string &serialization, const std::string &id, Mode mode) |
|
static std::string | getContent (const std::string &serialization, Mode mode) |
|
static std::vector< std::string > | split (const std::string &content, Mode mode) |
|
template<typename DataType > |
static std::enable_if<!std::is_pointer< DataType >::value, std::string >::type | serialize (const DataType &data, Mode mode) |
|
template<typename DataType > |
static std::enable_if< std::is_pointer< DataType >::value, std::string >::type | serialize (const DataType &data, Mode mode) |
|
template<typename DataType > |
static DataType | deserialize (const std::string &serialization, Mode mode) |
|
static std::string | extract (const std::string &serialization, Mode mode, std::string component) |
|
Data structure for mapping physical indices to linear indices.
void TBTK::IndexTree::add |
( |
const Index & |
index | ) |
|
Add index to the IndexTree. The IndexTree allows for Indices with both non-negative as well as negative subindices to be added to the tree. For Index Indices with non-negative subindices the IndexTree simply adds the suplied Indices . Negative subindices with the value IDX_SEPARATOR are similarly used to add Indices consisting of multiple Indices . All other negative subindices are interpreted as wildcards. What this means is that the corresponding subindex will be marked as a wildcard and the wildcard type (IDX_ALL, IDX_SPIN, etc) is saved in the Index structure, which allows for Indices with arbitrary values in the corresponding subindex to be searched for using SearchMode::MatchWildrcards.
Any wildcard subindex will be replaced by zero and the full Index then stored in the Index structure. This means that for example {1, IDX_ALL, 3} will be stored as {1, 0, 3} in the IndexTree and will count as one towards the size of the Index tree. {1, 0, 3} is therefore also the Index that is returned when matching against {1, IDX_ALL, 3}.
Also note that it is a fatal error to add two Indices with similar Index structure but different wildcard type to the IndexTree. For example, it is invalid to simultaneously add {1, IDX_ALL, 3} and {1, IDX_SPIN, 4} to the IndexTree. However, it is OK to add {1, IDX_ALL, 3} and {2, IDX_SPIN, 4} since the index structure of the later pair is differentiated already at the first subindex.
- Parameters
-
int TBTK::IndexTree::getLinearIndex |
( |
const Index & |
index, |
|
|
SearchMode |
searchMode = SearchMode::StrictMatch , |
|
|
bool |
returnNegativeForMissingIndex = false |
|
) |
| const |
Get the linear index corresponding to the given physical Index. The function can be executed in one of several different ways. First of all the function can be executed in one of the following modes.
StrictMatch:
A strict match between the suplied Index and the Index structure ecoded in the IndexTree is required. An Index added with a wildcard subindex must be retrieved with the same wildcard Index specified in the same subindex position. This is the standard mode of execution.
MatchWildcards:
Subindices marked as wildcard indices in the IndexTree are accepted independently of the subindex value in the Index passed to this function. For example, if {1, IDX_ALL, 3} has been added to the IndexTree, {1, 2, 3} will be accepted by the IndexTree as a valid Index. If a wildcard type is specified in the Index passed to this function, its type has to agree with that encoded in the IndexTree.
Second, the flag returnNegativeForMissingIndex can be set to true to make the function return -1 if an Index does not exists, or set to false to make the function throw an IndexException.
- Parameters
-
index | The Index to return the linear index for. |
searchMode | The mode to use when searching for Indices. |
returnNegativeForMissingIndex | If set to false, the request for a missing Index will result in an IndexException being thrown, but if set to true, a missing Index results in -1 being returned. |
- Returns
- The linear Index for the given physical Index. Returns -1 if the Index is not found and returnNegativeForMissingIndex is set to true.
- Exceptions
-
IndexException | If the requested Index does not exist and returnNegativeForMissingIndex is set to false. |
std::vector<unsigned int> TBTK::IndexTree::getSubindicesMatching |
( |
int |
subindexValue, |
|
|
const Index & |
index, |
|
|
SearchMode |
searchMode |
|
) |
| const |
First searches the IndexTree for a matching Index and then returns a list of subindiex positions that matches the given subindex value. If executed in SearchMode::StrictMatch, the function will simply return the matching subindices in the input Index itself. However, if executed in SearchMode::MatchWildcards, the IndexTree will be searched for an Index that is matching up to a wildcard, according to the specification of IndexTree::getLinearIndex(), and then perform the subindex matching on the resulting Index.
Example: If {1, IDX_ALL, 3, IDX_SPIN, 5, IDX_ALL} is stored in the IndexTree and the method is called as getSubindicesMatching( IDX_ALL, {1, 2, 3, 4, 5, 6}, IndexTree::SearchMode::MatchWildcards) then {1, IDX_ALL, 3, IDX_SPIN, 5, IDX_ALL} will first be found and then matched against the subindex value IDX_ALL, which results in a vector containing 1 and 5 being returned.
- Parameters
-
subindexValue | The subindex value to match against. |
index | The Index to match against. |
searchMode | Mode to use when matching 'index' against the Indices in the IndexTree. |
- Returns
- An std::vector<int> containing the subindex positions for which subindexValue has the same value as the matched Index.