CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SmallWORMDict.cc
Go to the documentation of this file.
2 #include <cstring>
3 
4 namespace cond {
5 
8 
9  SmallWORMDict::SmallWORMDict(std::vector<std::string> const & idict) :
10  m_data(std::accumulate(idict.begin(),idict.end(),0,
11  boost::bind(std::plus<int>(),_1,boost::bind(&std::string::size,_2)))),
12  m_index(idict.size(),1) {
13 
14  // sort (use index)
15  m_index[0]=0; std::partial_sum(m_index.begin(),m_index.end(),m_index.begin());
16  std::sort(m_index.begin(),m_index.end(),
17  boost::bind(std::less<std::string>(),
18  boost::bind<const std::string&>(&std::vector<std::string>::operator[],boost::ref(idict),_1),
19  boost::bind<const std::string&>(&std::vector<std::string>::operator[],boost::ref(idict),_2)
20  )
21  );
22 
23  //copy
24  std::vector<char>::iterator p= m_data.begin();
25  for (size_t j=0; j<m_index.size(); j++) {
26  size_t i = m_index[j];
27  p=std::copy(idict[i].begin(),idict[i].end(),p);
28  m_index[j]=p-m_data.begin();
29  }
30 
31  }
32 
33 
34  struct LessFrame {
35  bool operator()(SmallWORMDict::Frame const & rh,SmallWORMDict::Frame const & lh) const {
36  return std::lexicographical_compare(rh.b,rh.b+rh.l,lh.b,lh.b+lh.l);
37  }
38 
39  };
40 
41  size_t SmallWORMDict::index(std::string const & s) const {
42  return (*find(s)).ind;
43  }
44 
45  size_t SmallWORMDict::index(char const * s) const {
46  return (*find(s)).ind;
47  }
48 
50  Frame sp(&s[0], s.size(),0);
51  return
52  std::lower_bound(begin(),end(),sp, LessFrame());
53  }
54 
56  Frame sp(s, ::strlen(s),0);
57  return
58  std::lower_bound(begin(),end(),sp, LessFrame());
59  }
60 
61 
62  size_t SmallWORMDict::size() const { return m_index.size(); }
63 
64 
65 
66 }
size_t index(std::string const &s) const
int i
Definition: DBlmapReader.cc:9
const_iterator end() const
Definition: SmallWORMDict.h:71
std::vector< unsigned int > m_index
Definition: SmallWORMDict.h:97
const_iterator begin() const
Definition: SmallWORMDict.h:66
bool int lh
Definition: SIMDVec.h:21
const_iterator find(std::string const &s) const
std::vector< char > m_data
Definition: SmallWORMDict.h:96
bool operator()(SmallWORMDict::Frame const &rh, SmallWORMDict::Frame const &lh) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:63
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
size_t size() const
tuple size
Write out results.