TBTK
IndexTree.h
Go to the documentation of this file.
1 /* Copyright 2017 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_INDEX_TREE
24 #define COM_DAFER45_TBTK_INDEX_TREE
25 
26 #include "TBTK/Index.h"
27 #include "TBTK/Serializable.h"
28 
29 #include <vector>
30 
31 namespace TBTK{
32 
34 class IndexTree : public Serializable{
35 public:
37  IndexTree();
38 
41  IndexTree(const std::string &serialization, Mode mode);
42 
44  virtual ~IndexTree();
45 
47  void add(const Index &index);
48 
50  void generateLinearMap();
51 
54  enum class SearchMode{StrictMatch, IgnoreWildcards, MatchWildcards};
55 
57  int getLinearIndex(
58  const Index &index,
59  SearchMode searchMode = SearchMode::StrictMatch,
60  bool returnNegativeForMissingIndex = false
61  ) const;
62 
64  Index getPhysicalIndex(int linearIndex) const;
65 
67  int getSize() const;
68 
70  std::vector<unsigned int> getSubindicesMatching(
71  int i,
72  const Index &index,
73  SearchMode searchMode
74  ) const;
75 
77  std::vector<Index> getIndexList(const Index &pattern) const;
78 
81  class Iterator{
82  public:
84  void reset();
85 
87  void searchNext();
88 
90 // const Index* getIndex() const;
91  const Index getIndex() const;
92 
94  bool getHasReachedEnd() const;
95  private:
97  const IndexTree *indexTree;
98 
100  std::vector<int> currentIndex;
101 
107  bool skipNextIndex;
108 
110  bool hasReachedEnd;
111 
113  Iterator(const IndexTree *indexTree);
114 
118  bool searchNext(
119  const IndexTree *indexTree,
120  unsigned int subindex
121  );
122 
124  friend class IndexTree;
125  };
126 
128  Iterator begin() const;
129 
131  std::string serialize(Mode mode) const;
132 private:
134  std::vector<IndexTree> children;
135 
138  bool indexIncluded;
139 
142  bool wildcardIndex;
143 
146  int wildcardType;
147 
151  bool indexSeparator;
152 
154  int linearIndex;
155 
157  int size;
158 
161  void add(const Index& index, unsigned int subindex);
162 
165  int generateLinearMap(int i);
166 
169  int getLinearIndex(
170  const Index &index,
171  unsigned int subindex,
172  SearchMode searchMode,
173  bool returnNegativeForMissingIndex
174  ) const;
175 
178  void getPhysicalIndex(
179  int linearIndex,
180  std::vector<int> *indices
181  ) const;
182 
184  int getMinIndex() const;
185 
187  int getMaxIndex() const;
188 };
189 
190 inline int IndexTree::getSize() const{
191  return size;
192 }
193 
195  return hasReachedEnd;
196 }
197 
198 }; //End of namesapce TBTK
199 
200 #endif
int getSize() const
Definition: IndexTree.h:190
Flexible physical index.
virtual ~IndexTree()
bool getHasReachedEnd() const
Definition: IndexTree.h:194
Definition: Serializable.h:40
std::vector< unsigned int > getSubindicesMatching(int i, const Index &index, SearchMode searchMode) const
std::string serialize(Mode mode) const
SearchMode
Definition: IndexTree.h:54
void add(const Index &index)
Definition: IndexTree.h:81
Index getPhysicalIndex(int linearIndex) const
int getLinearIndex(const Index &index, SearchMode searchMode=SearchMode::StrictMatch, bool returnNegativeForMissingIndex=false) const
Data structure for mapping physical indices to a linear index.
Definition: IndexTree.h:34
Flexible physical index.
Definition: Index.h:70
void generateLinearMap()
Definition: ModelFactory.h:35
Mode
Definition: Serializable.h:44
Iterator begin() const
Abstract base class for serializable objects.
std::vector< Index > getIndexList(const Index &pattern) const