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<
282 HoppingAmplitudeTree*
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){};
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();
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.",
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();
int getFirstIndexInSubspace(const Index &subspaceIndex) const
Definition: HoppingAmplitudeTree.h:500
std::vector< Index > getIndexList(const Index &pattern) const
Node in tree used by HoppingAmplitudeSet to store HoppingAmplitudes .
Definition: HoppingAmplitudeTree.h:40
unsigned int getSizeInBytes() const
Definition: HoppingAmplitudeTree.h:556
const std::vector< HoppingAmplitude > & getHoppingAmplitudes(Index index) const
Hopping amplitude from state 'from' to state 'to'.
Definition: Serializable.h:43
int getLastIndexInSubspace(const Index &subspaceIndex) const
Definition: HoppingAmplitudeTree.h:516
int getBasisSize() const
Definition: HoppingAmplitudeTree.h:496
virtual ~HoppingAmplitudeTree()
Data structure for mapping physical indices to a linear index.
virtual std::string serialize(Mode mode) const
void add(HoppingAmplitude ha)
std::string toString() const
Definition: Index.h:349
Index getSubspaceIndex(const Index &index) const
ConstIterator cbegin() const
Definition: HoppingAmplitudeTree.h:540
std::vector< Index > getIndexListMultiplePatterns(const std::vector< Index > &patterns) const
int getBasisIndex(const Index &index) const
ConstIterator cend() const
Definition: HoppingAmplitudeTree.h:552
HoppingAmplitudeTree * getSubTree(const Index &subspace)
Definition: HoppingAmplitudeTree.h:313
bool isProperSubspace(const Index &subspace) const
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
Iterator begin()
Definition: HoppingAmplitudeTree.h:532
Data structure for mapping physical indices to linear indices.
Definition: IndexTree.h:35
Physical index.
Definition: Index.h:44
Iterator end()
Definition: HoppingAmplitudeTree.h:544
Definition: HoppingAmplitudeTree.h:327
void sort(HoppingAmplitudeTree *rootNode)
const Vector2d operator*(double lhs, const Vector2d &rhs)
Definition: Vector2d.h:129
Mode
Definition: Serializable.h:47
IndexTree getSubspaceIndices() const
void generateBasisIndices()
Index getPhysicalIndex(int basisIndex) const
Abstract base class for serializable objects.
bool operator!=(const IndexTree &lhs, const IndexTree &rhs)
Definition: IndexTree.h:391