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, [](int a, std::string b) { return a + b.size(); })),
14  m_index(idict.size(), 1) {
15  // sort (use index)
16  m_index[0] = 0;
17  std::partial_sum(m_index.begin(), m_index.end(), m_index.begin());
18  std::sort(m_index.begin(), m_index.end(), [&idict](unsigned int a, unsigned int b) {
19  return std::less<std::string>()(idict[a], idict[b]);
20  });
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  struct LessFrame {
32  bool operator()(SmallWORMDict::Frame const& rh, SmallWORMDict::Frame const& lh) const {
33  return std::lexicographical_compare(rh.b, rh.b + rh.l, lh.b, lh.b + lh.l);
34  }
35  };
36 
37  size_t SmallWORMDict::index(std::string const& s) const { return (*find(s)).ind; }
38 
39  size_t SmallWORMDict::index(char const* s) const { return (*find(s)).ind; }
40 
42  Frame sp(&s[0], s.size(), 0);
43  return std::lower_bound(begin(), end(), sp, LessFrame());
44  }
45 
47  Frame sp(s, ::strlen(s), 0);
48  return std::lower_bound(begin(), end(), sp, LessFrame());
49  }
50 
51  size_t SmallWORMDict::size() const { return m_index.size(); }
52 
53 } // namespace cond
const_iterator end() const
Definition: SmallWORMDict.h:70
size_t size() const
std::vector< unsigned int > m_index
Definition: SmallWORMDict.h:95
bool operator()(SmallWORMDict::Frame const &rh, SmallWORMDict::Frame const &lh) const
bool int lh
Definition: SIMDVec.h:20
const_iterator begin() const
Definition: SmallWORMDict.h:66
const_iterator find(std::string const &s) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:64
double b
Definition: hdecay.h:120
size_t index(std::string const &s) const
Definition: plugin.cc:23
double a
Definition: hdecay.h:121