CMS 3D CMS Logo

SmallWORMDict.cc
Go to the documentation of this file.
2 #include <string>
3 #include <functional>
4 #include <numeric>
5 
6 namespace cond {
7  using namespace std::placeholders;
8 
11 
12  SmallWORMDict::SmallWORMDict(std::vector<std::string> const & idict) :
13  m_data(std::accumulate(idict.begin(), idict.end(), 0,
14  [](int a, std::string b) { return a + b.size(); })),
15  m_index(idict.size(),1) {
16 
17  // sort (use index)
18  m_index[0]=0; std::partial_sum(m_index.begin(),m_index.end(),m_index.begin());
19  std::sort(m_index.begin(), m_index.end(),
20  [&idict](unsigned int a, unsigned int b) { return std::less<std::string>()(idict[a], idict[b]); });
21 
22  //copy
23  std::vector<char>::iterator p= m_data.begin();
24  for (size_t j=0; j<m_index.size(); j++) {
25  size_t i = m_index[j];
26  p=std::copy(idict[i].begin(),idict[i].end(),p);
27  m_index[j]=p-m_data.begin();
28  }
29 
30  }
31 
32 
33  struct LessFrame {
34  bool operator()(SmallWORMDict::Frame const & rh,SmallWORMDict::Frame const & lh) const {
35  return std::lexicographical_compare(rh.b,rh.b+rh.l,lh.b,lh.b+lh.l);
36  }
37 
38  };
39 
40  size_t SmallWORMDict::index(std::string const & s) const {
41  return (*find(s)).ind;
42  }
43 
44  size_t SmallWORMDict::index(char const * s) const {
45  return (*find(s)).ind;
46  }
47 
49  Frame sp(&s[0], s.size(),0);
50  return
51  std::lower_bound(begin(),end(),sp, LessFrame());
52  }
53 
55  Frame sp(s, ::strlen(s),0);
56  return
57  std::lower_bound(begin(),end(),sp, LessFrame());
58  }
59 
60 
61  size_t SmallWORMDict::size() const { return m_index.size(); }
62 
63 
64 
65 }
size_t index(std::string const &s) const
const_iterator end() const
Definition: SmallWORMDict.h:75
std::vector< unsigned int > m_index
const_iterator begin() const
Definition: SmallWORMDict.h:70
bool int lh
Definition: SIMDVec.h:21
const_iterator find(std::string const &s) const
std::vector< char > m_data
bool operator()(SmallWORMDict::Frame const &rh, SmallWORMDict::Frame const &lh) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:67
#define end
Definition: vmac.h:39
double b
Definition: hdecay.h:120
Definition: plugin.cc:24
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
size_t size() const