Claw  1.7.3
kmp.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #ifndef __CLAW_KMP_HPP__
32 #define __CLAW_KMP_HPP__
33 
34 #include <map>
35 
36 namespace claw
37 {
38  namespace text
39  {
44  template<class RandomIterator> class kmp
45  {
46  public:
47  template <class UnaryPredicate>
48  void operator()(const RandomIterator pattern_begin,
49  const RandomIterator pattern_end,
50  const RandomIterator text_begin,
51  const RandomIterator text_end,
52  UnaryPredicate& action) const;
53 
54  private:
55  unsigned int common_prefix_length( const RandomIterator begin_1,
56  const RandomIterator begin_2,
57  const RandomIterator end_1,
58  const RandomIterator end_2 ) const;
59 
60  void z_boxes(const RandomIterator begin, const RandomIterator end,
61  std::map<unsigned int, unsigned int>& out) const;
62 
63  void spi_prime(const RandomIterator begin, const RandomIterator end,
64  std::map<unsigned int, unsigned int>& out) const;
65  }; // class kmp
66 
67  } // namespace text
68 } // namespace claw
69 
70 #include <claw/impl/kmp.tpp>
71 
72 #endif // __CLAW_KMP_HPP__