TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Index Class Reference

Physical index. More...

#include <Index.h>

Public Member Functions

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

Friends

std::ostream & operator<< (std::ostream &stream, const Index &index)
 
bool operator< (const Index &i1, const Index &i2)
 
bool operator> (const Index &i1, const Index &i2)
 

Detailed Description

Physical index.

An Index is a list of Subindices. For example, {x, y, spin}, {x, y, z, orbital, spin}, and {subsystem, x, y, z, orbital, spin}.

Example

#include "TBTK/Index.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace TBTK;
int main(){
Index index({1, 2, 3});
for(unsigned int n = 0; n < index.getSize(); n++)
Streams::out << index[n] << "\n";
}

Output

1
2
3

Constructor & Destructor Documentation

◆ Index() [1/10]

TBTK::Index::Index ( )
inline

Constructs an empty Index.

◆ Index() [2/10]

TBTK::Index::Index ( std::initializer_list< Subindex i)
inline

Constructs an Index from an initializer list.

Parameters
iInitializer list from which the Index is constructed.

◆ Index() [3/10]

TBTK::Index::Index ( std::vector< Subindex i)
inline

Constructs an Index from an initializer list.

Parameters
iInitializer list from which the Index is constructed. Constructs an Index from an std::vector<int>.
iVector from which the Index is constructed.

◆ Index() [4/10]

TBTK::Index::Index ( const Index index)
inline

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

Parameters
iVector from which the Index is constructed. Copy constructor.
indexIndex to copy.

◆ Index() [5/10]

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.

◆ Index() [6/10]

TBTK::Index::Index ( const std::vector< std::vector< Subindex >> &  indexList)

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

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

◆ Index() [7/10]

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.

◆ Index() [8/10]

TBTK::Index::Index ( std::vector< Index indexList)

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

Parameters
indexListList of indices.

◆ Index() [9/10]

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.

◆ Index() [10/10]

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

◆ at() [1/2]

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

Get subindex n.

Parameters
nSubindex.
Returns
Subindex at position n.

◆ at() [2/2]

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

Get subindex n. Constant version.

Parameters
nSubindex.
Returns
Subindex at position n.

◆ equals()

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.

◆ erase()

Subindex TBTK::Index::erase ( unsigned int  n)
inline

Remove and return the Subindex at a given position.

Parameters
nSubindex position to remove.
Returns
The value of the removed Subindex.

◆ getSize()

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).

◆ getSizeInBytes()

unsigned int TBTK::Index::getSizeInBytes ( ) const
inline

Get size in bytes.

Returns
Memory size required to store the Index.

◆ getSubIndex()

Index TBTK::Index::getSubIndex ( int  first,
int  last 
) const

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).

◆ getUnitRange()

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.

◆ insert()

void TBTK::Index::insert ( unsigned int  n,
Subindex  subindex 
)
inline

Insert a Subindex at a given position.

Parameters
nSubindex position to insert at.
subindexSubindex to insert.

◆ isPatternIndex()

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.

◆ operator[]() [1/2]

Subindex & TBTK::Index::operator[] ( unsigned int  subindex)
inline

Subscript operator.

Parameters
nSubindex.
Returns
Subindex at position n.

◆ operator[]() [2/2]

const Subindex & TBTK::Index::operator[] ( unsigned int  subindex) const
inline

Subscript operator.

Parameters
nSubindex.
Returns
Subindex at position n.

◆ popBack()

Subindex TBTK::Index::popBack ( )
inline

Removes and returns the last subindex.

Returns
The last subindex.

◆ popFront()

Subindex TBTK::Index::popFront ( )
inline

Removes and returns the first subindex.

Returns
The first subindex.

◆ print()

void TBTK::Index::print ( ) const
inline

Print index. Mainly for debuging.

◆ pushBack()

void TBTK::Index::pushBack ( Subindex  subindex)
inline

Push subindex at the back of the index.

Parameters
subindexSubindex to append to the Index.

◆ reserve()

void TBTK::Index::reserve ( unsigned int  size)
inline

Reserves memory for the Index.

Parameters
Numberof subindices to reserve space for.

◆ serialize()

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.

◆ split()

std::vector< Index > TBTK::Index::split ( ) const
inline

Split a compound Index into its components.

Returns
An std::vector<Index> containing the individual Indices .

◆ toString()

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

◆ operator<

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.

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const Index index 
)
friend

Writes the Index toString()-representation to a stream.

Parameters
streamThe stream to write to.
indexThe Index to write.
Returns
Reference to the output stream just written to.

◆ operator>

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: