TBTK
LookupTableMap.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_LOOKUP_TABLE_MAP
24 #define COM_DAFER45_TBTK_LOOKUP_TABLE_MAP
25 
26 #include "TBTK/FockStateMap.h"
27 #include "TBTK/BitRegister.h"
29 
30 namespace TBTK{
31 namespace FockStateMap{
32 
33 template<typename BIT_REGISTER>
34 class LookupTableMap : public FockStateMap<BIT_REGISTER>{
35 public:
37  LookupTableMap(unsigned int exponentialDimension);
38 
40  virtual ~LookupTableMap();
41 
43  virtual unsigned int getBasisSize() const;
44 
46  virtual unsigned int getBasisIndex(
47  const FockState<BIT_REGISTER> &fockState
48  ) const;
49 
51  virtual FockState<BIT_REGISTER> getFockState(unsigned int index) const;
52 
54  void addState(const FockState<BIT_REGISTER> &fockState);
55 private:
57  std::vector<FockState<BIT_REGISTER>> states;
58 };
59 
60 template<typename BIT_REGISTER>
62  unsigned int exponentialDimension
63 ) :
64  FockStateMap<BIT_REGISTER>(exponentialDimension)
65 {
66 }
67 
68 template<typename BIT_REGISTER>
70 }
71 
72 template<typename BIT_REGISTER>
74  return states.size();
75 }
76 
77 template<typename BIT_REGISTER>
79  const FockState<BIT_REGISTER> &fockState
80 ) const{
81  unsigned int min = 0;
82  unsigned int max = states.size()-1;
83  while(min <= max){
84  unsigned int currentState = (min+max)/2;
85  if(fockState.getBitRegister() > states.at(currentState).getBitRegister())
86  min = currentState + 1;
87  else if(fockState.getBitRegister() < states.at(currentState).getBitRegister())
88  max = currentState - 1;
89  else if(fockState.getBitRegister() == states.at(currentState).getBitRegister())
90  return currentState;
91  }
92  TBTKExit(
93  "LookupTableFockStateMap<BIT_REGISTER>::getBasisIndex()",
94  "FockState not found.",
95  ""
96  );
97 }
98 
99 template<typename BIT_REGISTER>
101  unsigned int index
102 ) const{
103  return states.at(index);
104 }
105 
106 template<typename BIT_REGISTER>
108  const FockState<BIT_REGISTER> &fockState
109 ){
110  states.push_back(fockState);
111 }
112 
113 }; //End of namespace FockStateMap
114 }; //End of namespace TBTK
115 
116 #endif
Register of bits.
virtual ~LookupTableMap()
Definition: LookupTableMap.h:69
FockStateMap.
LookupTableMap(unsigned int exponentialDimension)
Definition: LookupTableMap.h:61
void addState(const FockState< BIT_REGISTER > &fockState)
Definition: LookupTableMap.h:107
Definition: FockStateMap.h:32
const BIT_REGISTER & getBitRegister() const
Definition: FockState.h:107
Register of bits.
Definition: LookupTableMap.h:34
Definition: ModelFactory.h:35
virtual unsigned int getBasisSize() const
Definition: LookupTableMap.h:73
Definition: FockState.h:37
virtual unsigned int getBasisIndex(const FockState< BIT_REGISTER > &fockState) const
Definition: LookupTableMap.h:78
virtual FockState< BIT_REGISTER > getFockState(unsigned int index) const
Definition: LookupTableMap.h:100