MINT2
RememberAnythingFast.h
Go to the documentation of this file.
1 #ifndef REMEMBER_ANYTHINGFAST_HH
2 #define REMEMBER_ANYTHINGFAST_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:18:00 GMT
5 
6 #include <vector>
7 #include <utility>
8 
9 #include <iostream>
10 
11 // new: configNumber. The idea: It numbers the configuration/set of fit parameters. If it changed, you need to re-calculate the value. "Not set" corresponds to zero configNumber.
12 
13 template<typename T>
15  std::vector< std::pair< T, long int> > _anyVector;
16  public:
17 
18  unsigned int size(){
19  return _anyVector.size();
20  }
21 
22  void resize(unsigned int newSize){
23  if(newSize < this->size()) return;
24  std::pair< T, long int> empty(0, 0);
25  _anyVector.resize(newSize, empty);
26  }
27 
28  void set(unsigned int i, const T& value, long int configNumber=1){
29  //std::cout << "RememberAnythingFast called with "
30  // << value << ", " << configNumber << std::endl;
31  if(i >= _anyVector.size()){
32  resize(i+1);
33  }
34  std::pair< T, long int> trueValue(value, configNumber);
35  //std::cout << "trueValue = " << trueValue.first
36  // << ", " << trueValue.second << std::endl;
37  _anyVector[i] = trueValue;
38 
39  /*
40  std::cout << "my contents, now " << std::endl;
41  for(unsigned int i=0; i < _anyVector.size(); i++){
42  std::cout << _anyVector[i].first
43  << ", " << _anyVector[i].second << std::endl;
44  }
45  */
46  }
47 
48 
49 
51  _anyVector.clear();
52  }
54  : _anyVector(other._anyVector){
55  }
56 
58  _anyVector.clear();
59  }
60 
61  bool valid(long int i){
62  if(i < 0) return false;
63  if(i >= (long int) this->size()) return false;
64  if(!(_anyVector[i].second)) return false;
65  return true;
66  }
67  bool get(int i, T& value, long int configNumber=1){
68  /*std::cout << "my contents, now " << std::endl;
69  for(unsigned int i=0; i < _anyVector.size(); i++){
70  std::cout << _anyVector[i].first
71  << ", " << _anyVector[i].second << std::endl;
72 
73  }
74  std::cout << "called with: " << i << ", " << configNumber << std::endl;
75  */
76  if(! valid(i)) return false;
77  //std::cout << "I'm valid! " << std::endl;
78  if(_anyVector[i].second != configNumber) return false;
79  value = _anyVector[i].first;
80  //std::cout << "set value to " << value <<std::endl;
81  return true;
82  }
83 
84 };
85 
86 
87 #endif
88 //
89 
90 
91 
92 
void set(unsigned int i, const T &value, long int configNumber=1)
std::vector< std::pair< T, long int > > _anyVector
bool get(int i, T &value, long int configNumber=1)
void resize(unsigned int newSize)
static const double second
RememberAnythingFast(const RememberAnythingFast &other)