TBTK
TBTK::Index Class Reference

Flexible physical index. More...

#include <Index.h>

Inheritance diagram for TBTK::Index:
TBTK::DualIndex

Public Member Functions

 Index ()
 
 Index (std::initializer_list< int > i)
 
 Index (std::vector< int > i)
 
 Index (const Index &index)
 
 Index (const Index &head, const Index &tail)
 
 Index (std::initializer_list< std::initializer_list< int >> indexList)
 
 Index (const std::vector< std::vector< int >> &indexList)
 
 Index (std::initializer_list< Index > indexList)
 
 Index (const std::string &indexString)
 
 Index (const std::string &serialization, Serializable::Mode mode)
 
bool equals (const Index &index, bool allowWildcard=false) const
 
int & at (unsigned int n)
 
const int & at (unsigned int n) const
 
unsigned int getSize () const
 
void reserve (unsigned int size)
 
void push_back (int subindex)
 
int popFront ()
 
int popBack ()
 
Index getUnitRange ()
 
Index getSubIndex (int first, int last)
 
bool isPatternIndex () const
 
void print () const
 
std::string toString () const
 
int & operator[] (unsigned int subindex)
 
const int & operator[] (unsigned int subindex) const
 
std::string serialize (Serializable::Mode mode) const
 
unsigned int getSizeInBytes () const
 

Friends

bool operator< (const Index &i1, const Index &i2)
 
bool operator> (const Index &i1, const Index &i2)
 

Detailed Description

Flexible physical index.

Flexible physical index for indexing arbitrary models. Each index can contain an arbitrary number of subindices. For example {x, y, spin}, {x, y, z, orbital, spin}, and {subsystem, x, y, z, orbital, spin}.

Constructor & Destructor Documentation

TBTK::Index::Index ( )
inline

Constructs an empty Index.

TBTK::Index::Index ( std::initializer_list< int >  i)
inline

Constructs an Index from an initializer list.

Parameters
iInitializer list from which the Index is constructed.
TBTK::Index::Index ( std::vector< int >  i)
inline

Constructs an Index from an std::vector<int>.

Parameters
iVector from which the Index is constructed.
TBTK::Index::Index ( const Index index)
inline

Copy constructor.

Parameters
indexIndex to copy.
TBTK::Index::Index ( const Index head,
const Index tail 
)

Constructs a new Index by concatenating two indices into one total index of the form {head, tail}.

Parameters
headFirst part of the compund Index.
tailSecond part of the compund Index.
TBTK::Index::Index ( std::initializer_list< std::initializer_list< int >>  indexList)

Constructs a compound Index by concatenating a list of indices, adding IDX_SEPARATOR between every index.

Parameters
indexListList of indices.
TBTK::Index::Index ( const std::vector< std::vector< int >> &  indexList)

Constructs a compund Index by concatenating a list of indices, adding IDX_SEPARATOR between every index.

Parameters
indexListList of indices.
TBTK::Index::Index ( std::initializer_list< Index indexList)

Constructs a compound Index by Concatenating a list of indices, adding IDX_SEPARATOR between every index.

Parameters
indexListList of indices.
TBTK::Index::Index ( const std::string &  indexString)

Constructs an Index from a string.

Parameters
indexStringString such as "{1, 2, 3} from which the Index is constructed.
TBTK::Index::Index ( const std::string &  serialization,
Serializable::Mode  mode 
)

Constructs an Index from a serialization string.

Parameters
serializationSerialization string from which to construct the Index.
modeMode with which the string has been serialized.

Member Function Documentation

int & TBTK::Index::at ( unsigned int  n)
inline

Get subindex n.

Parameters
nSubindex.
Returns
Subindex at position n.
const int & TBTK::Index::at ( unsigned int  n) const
inline

Get subindex n. Constant version.

Parameters
nSubindex.
Returns
Subindex at position n.
bool TBTK::Index::equals ( const Index index,
bool  allowWildcard = false 
) const
inline

Compare this index with another index. Returns true if the indices have the same number of subindices and all subindices are equal.

Parameters
indexIndex to compare with.
allowWildcardIDX_ALL is interpreted as wildcard.
Returns
True if the indices are equal, otherwise false.
unsigned int TBTK::Index::getSize ( ) const
inline

Get size.

Returns
Number of subindices for individual indices such as {1, 2, 3}. For compound indices such as {{1, 2}, {3,4}, {5, 6}}, the total number of subindices (here 6) plus the number of index separators (here 2) are returned (here 6+2=8).
unsigned int TBTK::Index::getSizeInBytes ( ) const
inline

Get size in bytes.

Returns
Memory size required to store the Index.
Index TBTK::Index::getSubIndex ( int  first,
int  last 
)

Returns an Index containing the subindices from position 'first' to 'last'.

first First index to include in range (inclusive). last Last index to include in range (inclusive).

Returns
An index containing the subindices in the range first to last (inclusive).
Index TBTK::Index::getUnitRange ( )

Returns an index with the same number or subindices, and each subindex set to 1.

Returns
Index with all subindices set to 1.
bool TBTK::Index::isPatternIndex ( ) const
inline

Returns true if the Index is a pattern index. That is, if it contains a negative subindex.

Returns
True if the Index is a pattern index, otherwise false.
int & TBTK::Index::operator[] ( unsigned int  subindex)
inline

Subscript operator.

Parameters
nSubindex.
Returns
Subindex at position n.
const int & TBTK::Index::operator[] ( unsigned int  subindex) const
inline

Subscript operator.

Parameters
nSubindex.
Returns
Subindex at position n.
int TBTK::Index::popBack ( )
inline

Removes and returns the last subindex.

Returns
The last subindex.
int TBTK::Index::popFront ( )
inline

Removes and returns the first subindex.

Returns
The first subindex.
void TBTK::Index::print ( ) const
inline

Print index. Mainly for debuging.

void TBTK::Index::push_back ( int  subindex)
inline

Push subindex at the back of the index.

Parameters
subindexSubindex to append to the Index.
void TBTK::Index::reserve ( unsigned int  size)
inline

Reserves memory for the Index.

Parameters
Numberof subindices to reserve space for.
std::string TBTK::Index::serialize ( Serializable::Mode  mode) const

Serialize Index. Note that Index is pseudo-Serializable in that it implements the Serializable interface, but does so non-virtually.

Parameters
modeSerialization mode to use.
Returns
Serialized string represenation of the Index.
std::string TBTK::Index::toString ( ) const
inline

Get string representation of the Index.

Returns
A string representation of the Index.

Friends And Related Function Documentation

bool operator< ( const Index i1,
const Index i2 
)
friend

Comparison operator. Returns false if the TreeNode structure would generate a smaller Hilbert space index for i1 than for i2.

Returns
True if i1 would generate a smaller Hilbert space index than i2.
bool operator> ( const Index i1,
const Index i2 
)
friend

Comparison operator. Returns false if the TreeNode structure would generate a larger Hilbert space index for i1 than for i2.

Returns
True if i1 would generate a larger Hilbert space index than i2.

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