aboutsummaryrefslogtreecommitdiffstats
path: root/core/sorted_data_set.hpp
blob: f825b6c5594d28c8aabc56c94781f40a366c897f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef SORTED_DATA_SET
#define SORTED_DATA_SET
#include "fitter.hpp"
#include <vector>
#include <algorithm>

namespace opt_utilities
{
  
  template <typename Ty,typename Tx>
  bool comp_data(const data<Ty,Tx>& d1,const data<Ty,Tx>& d2)
  {
    return d1.get_x()<d2.get_x();
  }


template <typename Ty,typename Tx>
class sorted_data_set
  :public data_set<Ty,Tx>
{
private:
  std::vector<data<Ty,Tx> > data_vec;

  data_set<Ty,Tx>* do_clone()const
  {
    return new sorted_data_set<Ty,Tx>(*this);
  }


  const data<Ty,Tx>& do_get_data(size_t i)const
  {
    return data_vec.at(i);
  }
  
  size_t do_size()const
  {
    return data_vec.size();
  }
  
  void do_add_data(const data<Ty,Tx>& d)
  {
    typename std::vector<data<Ty,Tx> >::iterator p
      =std::lower_bound(data_vec.begin(),data_vec.end(),d,comp_data<Ty,Tx>);
    //data_vec.push_back(d);
    data_vec.insert(p,d);
  }
  
  void do_clear()
  {
    data_vec.clear();
  }
  
};
}

#endif
//EOF