claw 1.9.0
 
Loading...
Searching...
No Matches
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@stuff-o-matic.com
24*/
31#ifndef __CLAW_KMP_HPP__
32#define __CLAW_KMP_HPP__
33
34#include <map>
35
36namespace claw
37{
38 namespace text
39 {
44 template <class RandomIterator>
45 class kmp
46 {
47 public:
48 template <class UnaryPredicate>
49 void operator()(const RandomIterator pattern_begin,
50 const RandomIterator pattern_end,
51 const RandomIterator text_begin,
52 const RandomIterator text_end,
53 UnaryPredicate& action) const;
54
55 private:
56 unsigned int common_prefix_length(const RandomIterator begin_1,
57 const RandomIterator begin_2,
58 const RandomIterator end_1,
59 const RandomIterator end_2) const;
60
61 void z_boxes(const RandomIterator begin, const RandomIterator end,
62 std::map<unsigned int, unsigned int>& out) const;
63
64 void spi_prime(const RandomIterator begin, const RandomIterator end,
65 std::map<unsigned int, unsigned int>& out) const;
66 }; // class kmp
67
68 }
69}
70
71#include <claw/kmp.tpp>
72
73#endif // __CLAW_KMP_HPP__
Exact pattern finding with the Knuth-Morris-Pratt's algorithm.
Definition kmp.hpp:46
Everything about text processing.
Definition claw.hpp:88
This is the main namespace.