23 #ifndef COM_DAFER45_TBTK_INDEX_TREE 24 #define COM_DAFER45_TBTK_INDEX_TREE 156 SearchMode searchMode = SearchMode::StrictMatch,
157 bool returnNegativeForMissingIndex =
false 235 template<
bool isConstIterator>
240 typedef typename std::conditional<
260 typedef typename std::conditional<
264 >::type IndexTreePointerType;
267 IndexTreePointerType indexTree;
270 std::vector<int> currentIndex;
280 _Iterator(IndexTreePointerType indexTree,
bool end =
false);
286 const IndexTree *indexTree,
287 unsigned int subindex
291 friend class Iterator;
302 ) : _Iterator<true>(indexTree,
end){}
329 virtual std::string
toString()
const;
335 std::vector<IndexTree> children;
362 void add(
const Index& index,
unsigned int subindex);
372 unsigned int subindex,
374 bool returnNegativeForMissingIndex
381 std::vector<Subindex> &indices
385 int getMinIndex()
const;
388 int getMaxIndex()
const;
392 return !(lhs == rhs);
422 template<
bool isConstIterator>
423 IndexTree::_Iterator<isConstIterator>::_Iterator(IndexTreePointerType indexTree,
bool end){
425 this->indexTree = indexTree;
426 currentIndex.push_back(indexTree->children.size());
429 this->indexTree = indexTree;
430 currentIndex.push_back(0);
431 skipNextIndex =
false;
432 searchNext(this->indexTree, 0);
436 template<
bool isConstIterator>
437 void IndexTree::_Iterator<isConstIterator>::operator++(){
438 skipNextIndex =
true;
439 searchNext(indexTree, 0);
442 template<
bool isConstIterator>
443 bool IndexTree::_Iterator<isConstIterator>::searchNext(
445 unsigned int subindex
447 if(indexTree->children.size() == 0){
448 if(indexTree->indexIncluded){
450 skipNextIndex =
false;
456 unsigned int n = currentIndex.at(subindex);
457 while(n < indexTree->children.size()){
458 if(subindex+1 == currentIndex.size())
459 currentIndex.push_back(0);
460 if(searchNext(&indexTree->children.at(n), subindex+1))
463 currentIndex.pop_back();
464 n = ++currentIndex.back();
470 template<
bool isConstIterator>
471 typename IndexTree::_Iterator<isConstIterator>::IndexType IndexTree::_Iterator<isConstIterator>::operator*(){
472 if(currentIndex.at(0) == (int)indexTree->children.size()){
474 "IndexTree::_Iterator<isConstIterator>::operator*()",
475 "Out of range access. Tried to access an element using" 476 <<
" an Iterator that points beyond the last element.",
483 const IndexTree *indexTreeBranch = this->indexTree;
484 for(
unsigned int n = 0; n < currentIndex.size()-1; n++){
485 if(indexTreeBranch->indexSeparator)
488 if(indexTreeBranch->wildcardIndex)
489 index.
pushBack(indexTreeBranch->wildcardType);
493 if(n < currentIndex.size()-1)
494 indexTreeBranch = &indexTreeBranch->children.at(currentIndex.at(n));
500 template<
bool isConstIterator>
501 bool IndexTree::_Iterator<isConstIterator>::operator==(
const _Iterator &rhs)
const{
502 if(indexTree != rhs.indexTree)
505 if(currentIndex.size() != rhs.currentIndex.size())
508 for(
unsigned int n = 0; n < currentIndex.size(); n++)
509 if(currentIndex[n] != rhs.currentIndex[n])
515 template<
bool isConstIterator>
516 bool IndexTree::_Iterator<isConstIterator>::operator!=(
const _Iterator &rhs)
const{
Abstract base class for classes that can be written to a stream.
Definition: Streamable.h:30
bool contains(const Index &index)
void pushBack(Subindex subindex)
Definition: Index.h:490
ConstIterator cend() const
Definition: IndexTree.h:414
int getSize() const
Definition: IndexTree.h:418
ConstIterator cbegin() const
Definition: IndexTree.h:406
std::vector< Index > getIndexList(const Index &pattern) const
Definition: Serializable.h:43
ConstIterator begin() const
Definition: IndexTree.h:402
virtual std::string toString() const
friend class Index
Definition: Serializable.h:200
int getLinearIndex(const Index &index, SearchMode searchMode=SearchMode::StrictMatch, bool returnNegativeForMissingIndex=false) const
Index getPhysicalIndex(int linearIndex) const
SearchMode
Definition: IndexTree.h:116
void add(const Index &index)
bool equals(const IndexTree &indexTree) const
ConstIterator end() const
Definition: IndexTree.h:410
Data structure for mapping physical indices to linear indices.
Definition: IndexTree.h:35
Physical index.
Definition: Index.h:44
Definition: IndexTree.h:297
bool getLinearMapIsGenerated() const
Definition: IndexTree.h:395
friend bool operator==(const IndexTree &lhs, const IndexTree &rhs)
const Vector2d operator*(double lhs, const Vector2d &rhs)
Definition: Vector2d.h:129
Mode
Definition: Serializable.h:47
friend bool operator!=(const IndexTree &lhs, const IndexTree &rhs)
Definition: IndexTree.h:391
std::vector< unsigned int > getSubindicesMatching(int subindexValue, const Index &index, SearchMode searchMode) const
std::string serialize(Mode mode) const
Abstract base class for serializable objects.