24 #ifndef COM_DAFER45_TBTK_TREE_NODE
25 #define COM_DAFER45_TBTK_TREE_NODE
54 const std::vector<unsigned int> &capacity
229 const std::vector<Index> &patterns
245 template<
bool isConstIterator>
250 typedef typename std::conditional<
254 >::type HoppingAmplitudeReferenceType;
260 HoppingAmplitudeReferenceType
operator*();
263 bool operator==(
const _Iterator &rhs)
const;
269 int getMinBasisIndex()
const;
272 int getMaxBasisIndex()
const;
275 int getNumBasisIndices()
const;
279 typedef typename std::conditional<
283 >::type HoppingAmplitudeTreePointerType;
286 HoppingAmplitudeTreePointerType tree;
289 std::vector<int> currentIndex;
293 int currentHoppingAmplitude;
300 _Iterator(HoppingAmplitudeTreePointerType tree,
bool end =
false);
306 HoppingAmplitudeTreePointerType hoppingAmplitudeTree,
318 ) : _Iterator<false>(hoppingAmplitudeTree,
end){};
332 ) : _Iterator<true>(hoppingAmplitudeTree,
end){};
349 ConstIterator
begin()
const;
355 ConstIterator
cbegin()
const;
367 ConstIterator
end()
const;
373 ConstIterator
cend()
const;
409 bool isPotentialBlockSeparator;
414 std::vector<HoppingAmplitude> hoppingAmplitudes;
418 std::vector<HoppingAmplitudeTree> children;
431 const Index &subspace,
432 unsigned int subindex
438 bool _isProperSubspace(
439 const Index &subspace,
440 unsigned int subindex
453 unsigned int subindex,
460 const std::vector<HoppingAmplitude>& _getHoppingAmplitudes(
462 unsigned int subindex
468 int _getBasisIndex(
const Index &index,
unsigned int subindex)
const;
473 void _getPhysicalIndex(
int basisIndex, std::vector<Subindex> &indices)
const;
476 int getMinIndex()
const;
479 int getMaxIndex()
const;
489 void print(
unsigned int subindex);
501 const Index &subspaceIndex
505 "HoppingAmplitudeTree::getFirstIndexInSubspace()",
506 "The index " << subspaceIndex.
toString() <<
" is not an Index"
507 <<
" of a proper subspace.",
513 return subspace->getMinIndex();
517 const Index &subspaceIndex
521 "HoppingAmplitudeTree::getLastIndexInSubspace()",
522 "The index " << subspaceIndex.
toString() <<
" is not an Index"
523 <<
" of a proper subspace.",
529 return subspace->getMaxIndex();
537 return ConstIterator(
this);
549 return ConstIterator(
this,
true);
557 unsigned int size = 0;
558 for(
unsigned int n = 0; n < hoppingAmplitudes.size(); n++)
560 for(
unsigned int n = 0; n < children.size(); n++)
564 hoppingAmplitudes.capacity() - hoppingAmplitudes.size()
568 children.capacity() - children.size()
574 template<
bool isConstIterator>
575 HoppingAmplitudeTree::_Iterator<isConstIterator>::_Iterator(
576 HoppingAmplitudeTreePointerType tree,
582 if(tree->children.size() == 0){
583 currentHoppingAmplitude = -1;
586 currentIndex.push_back(tree->children.size());
587 currentHoppingAmplitude = -1;
592 if(tree->children.size() == 0){
596 currentHoppingAmplitude = -1;
597 searchNext(tree, -1);
600 currentIndex.push_back(0);
601 currentHoppingAmplitude = -1;
607 template<
bool isConstIterator>
608 void HoppingAmplitudeTree::_Iterator<isConstIterator>::operator++(){
609 if(tree->children.size() == 0){
613 searchNext(tree, -1);
620 template<
bool isConstIterator>
621 bool HoppingAmplitudeTree::_Iterator<isConstIterator>::searchNext(
622 HoppingAmplitudeTreePointerType hoppingAmplitudeTree,
625 if(subindex+1 == (
int)currentIndex.size()){
629 if(currentHoppingAmplitude != -1){
633 currentHoppingAmplitude++;
634 if(currentHoppingAmplitude == (
int)hoppingAmplitudeTree->hoppingAmplitudes.size()){
639 currentHoppingAmplitude = -1;
653 if(hoppingAmplitudeTree->children.size() == 0){
658 if(hoppingAmplitudeTree->hoppingAmplitudes.size() != 0){
663 currentHoppingAmplitude = 0;
683 unsigned int n = currentIndex.at(subindex);
684 while(n < hoppingAmplitudeTree->children.size()){
685 if(subindex+1 == (
int)currentIndex.size()){
689 currentIndex.push_back(0);
691 if(searchNext(&hoppingAmplitudeTree->children.at(n), subindex+1)){
700 currentIndex.pop_back();
701 n = ++currentIndex.back();
709 template<
bool isConstIterator>
710 typename HoppingAmplitudeTree::_Iterator<
712 >::HoppingAmplitudeReferenceType HoppingAmplitudeTree::_Iterator<
715 if(currentIndex.size() == 0){
719 if(currentHoppingAmplitude == -1){
721 "HoppingAmplitudeTree::_Iterator::operator*()",
722 "Out of range access. Tried to access an"
723 <<
" element using an iterator that points"
724 <<
" beyond the last element.",
729 return tree->hoppingAmplitudes.at(currentHoppingAmplitude);
733 if(currentIndex.at(0) == (
int)tree->children.size()){
735 "HoppingAmplitudeTree::_Iterator::operator*()",
736 "Out of range access. Tried to access an"
737 <<
" element using an iterator that points"
738 <<
" beyond the last element.",
742 const HoppingAmplitudeTree *tn = this->tree;
743 for(
unsigned int n = 0; n < currentIndex.size()-1; n++){
744 tn = &tn->children.at(currentIndex.at(n));
747 return tn->hoppingAmplitudes.at(currentHoppingAmplitude);
750 template<
bool isConstIterator>
751 bool HoppingAmplitudeTree::_Iterator<isConstIterator>::operator==(
const _Iterator &rhs)
const{
753 this->tree == rhs.tree
754 && currentIndex.size() == rhs.currentIndex.size()
756 for(
unsigned int n = 0; n < currentIndex.size(); n++){
757 if(currentIndex[n] != rhs.currentIndex[n])
761 if(currentHoppingAmplitude == rhs.currentHoppingAmplitude)
771 template<
bool isConstIterator>
772 bool HoppingAmplitudeTree::_Iterator<isConstIterator>::operator!=(
775 return !operator==(rhs);
778 template<
bool isConstIterator>
779 int HoppingAmplitudeTree::_Iterator<isConstIterator>::getMinBasisIndex()
const{
780 return tree->getMinIndex();
783 template<
bool isConstIterator>
784 int HoppingAmplitudeTree::_Iterator<isConstIterator>::getMaxBasisIndex()
const{
785 return tree->getMaxIndex();
788 template<
bool isConstIterator>
789 int HoppingAmplitudeTree::_Iterator<isConstIterator>::getNumBasisIndices(
791 if(getMaxBasisIndex() == -1)
794 return 1 + getMaxBasisIndex() - getMinBasisIndex();