TBTK
TBTK::IndexTree Class Reference

Data structure for mapping physical indices to linear indices. More...

#include <IndexTree.h>

Inheritance diagram for TBTK::IndexTree:
TBTK::Serializable

Classes

class  ConstIterator
 

Public Types

enum  SearchMode { StrictMatch, MatchWildcards }
 
- Public Types inherited from TBTK::Serializable
enum  Mode { Debug, Binary, XML, JSON }
 

Public Member Functions

 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
 
int getSize () const
 
std::vector< unsigned int > getSubindicesMatching (int subindexValue, const Index &index, SearchMode searchMode) const
 
std::vector< IndexgetIndexList (const Index &pattern) const
 
bool equals (const IndexTree &indexTree) const
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
ConstIterator end () const
 
ConstIterator cend () const
 
std::string serialize (Mode mode) const
 

Additional Inherited Members

- Static Public Member Functions inherited from TBTK::Serializable
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 Protected Member Functions inherited from TBTK::Serializable
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)
 
static std::string serialize (bool b, Mode mode)
 
static void deserialize (const std::string &serialization, bool *b, Mode mode)
 
static std::string serialize (int i, Mode mode)
 
static void deserialize (const std::string &serialization, int *i, Mode mode)
 
static std::string serialize (unsigned int u, Mode mode)
 
static void deserialize (const std::string &serialization, unsigned int *u, Mode mode)
 
static std::string serialize (double d, Mode mode)
 
static void deserialize (const std::string &serialization, double *d, Mode mode)
 
static std::string serialize (std::complex< double > c, Mode mode)
 
static void deserialize (const std::string &serialization, std::complex< double > *c, Mode mode)
 
static std::string serialize (Statistics s, Mode mode)
 
static void deserialize (const std::string &serialization, Statistics *s, Mode mode)
 
static std::string extract (const std::string &serialization, Mode mode, std::string component)
 

Detailed Description

Data structure for mapping physical indices to linear indices.

Member Enumeration Documentation

Enum class for selecting mode used to search indices with getLinearIndex().

Constructor & Destructor Documentation

TBTK::IndexTree::IndexTree ( )

Constructors an IndexTree.

TBTK::IndexTree::IndexTree ( const std::string &  serialization,
Mode  mode 
)

Constructor. Constructs the IndexTree from a serialization string.

Parameters
serializationSerialization string from which to construct the IndexTree.
modeMode with which the string has been serialized.
virtual TBTK::IndexTree::~IndexTree ( )
virtual

Destructor.

Member Function Documentation

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
indexIndex to add.
IndexTree::ConstIterator TBTK::IndexTree::begin ( ) const
inline

Get ConstIterator.

Returns
ConstIterator initialized to point at the first Index.
IndexTree::ConstIterator TBTK::IndexTree::cbegin ( ) const
inline

Get ConstIterator.

Returns
ConstIterator initialized to point at the first Index.
IndexTree::ConstIterator TBTK::IndexTree::cend ( ) const
inline

Create ConstIterator pointing to the end.

Returns
ConstIterator pointing to the end of the IndexTree.
IndexTree::ConstIterator TBTK::IndexTree::end ( ) const
inline

Create ConstIterator pointing to the end.

Returns
ConstIterator pointing to the end of the IndexTree.
bool TBTK::IndexTree::equals ( const IndexTree indexTree) const

Returns true if the two IndexTrees contain the same Indices .

Parameters
indexTreeIndexTree to compare to.
Returns
True if the two IndexTrees contain the same Indices .
void TBTK::IndexTree::generateLinearMap ( )

Generate a linear map from the Indices that has been added to the non-negative numbers.

Note that Indices that have been added with a wildcard subindex have the wildcards replaced by zero and the resulting Index is treated as a normal Index.

std::vector<Index> TBTK::IndexTree::getIndexList ( const Index pattern) const

Generate a list containing all the Indices in the IndexTree that satisfies the specified pattern.

Parameters
patternPattern to match against.
Returns
An std::vector<Index> containing all the Indices in the IndexTree that matches the specified pattern.
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
indexThe Index to return the linear index for.
searchModeThe mode to use when searching for Indices.
returnNegativeForMissingIndexIf 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
IndexExceptionIf the requested Index does not exist and returnNegativeForMissingIndex is set to false.
bool TBTK::IndexTree::getLinearMapIsGenerated ( ) const
inline

Get whether the linear map has been generated.

Returns
True if the linear map has been generated.
Index TBTK::IndexTree::getPhysicalIndex ( int  linearIndex) const

Get physical index corresponding to given linear index.

Parameters
linearIndexLinear index.
Returns
The physical Index that corresponds to the given linear Index.
int TBTK::IndexTree::getSize ( ) const
inline

Get size.

Returns
The number of Indices stored in the IndexTree. Returns -1 if IndexTree::generateLinearMap() has not yet been called.
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
subindexValueThe subindex value to match against.
indexThe Index to match against.
searchModeMode 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.
std::string TBTK::IndexTree::serialize ( Mode  mode) const
virtual

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