nlib
AhoCorasick.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
4 #define INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
5 
6 #include "nn/nlib/Swap.h"
7 #include "nn/nlib/succinct/Bp.h"
8 #include "nn/nlib/succinct/Sbv.h"
9 
10 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
11 #undef NLIB_VIS_PUBLIC
12 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
13 #endif
14 
15 NLIB_NAMESPACE_BEGIN
16 namespace succinct {
17 
19  public:
20  static const size_t LABEL_WIDTH = 8; // 1,2,4,8
21  static const int LABEL_MASK = (1 << LABEL_WIDTH) - 1;
22  static const int NUMLABEL_PER_BYTE = 8 / LABEL_WIDTH;
23 
24  public:
25  AhoCorasick() NLIB_NOEXCEPT : prv_(NULL) {}
27  NLIB_MOVE_MEMBER_HELPER_1(AhoCorasick, prv_);
29  AhoCorasickPrivate* tmp = prv_;
30  prv_ = rhs.prv_;
31  rhs.prv_ = tmp;
32  }
33  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
34  void* user_obj);
35  void Match(const char* doc, MatchCallback callback, void* userobj) NLIB_NOEXCEPT {
36  this->Match(doc, nlib_strlen(doc), callback, userobj);
37  }
38  void Match(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
39  this->Match(doc, nlib_strlen(doc), callback, NULL);
40  }
41  void Match(const void* data, size_t n, MatchCallback callback, void* userobj) NLIB_NOEXCEPT;
42  void Match(const void* data, size_t n, MatchCallback callback) NLIB_NOEXCEPT {
43  Match(data, n, callback, NULL);
44  }
45  size_t MemSize() const NLIB_NOEXCEPT;
46 
47  void MemSize(size_t* len_store, size_t* goto_arc, size_t* report_arc,
48  size_t* failure_arc) const NLIB_NOEXCEPT;
49  void Reset() NLIB_NOEXCEPT;
50  bool Export(BinaryWriter* w) const NLIB_NOEXCEPT;
51  bool Import(BinaryReader* r) NLIB_NOEXCEPT;
52 
53  private:
54  struct AhoCorasickPrivate;
55  AhoCorasickPrivate* prv_;
56  friend class AhoCorasickBuilder;
58 };
59 
60 } // namespace succinct
61 NLIB_NAMESPACE_END
62 
63 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::AhoCorasick)
64 
65 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
66 #undef NLIB_VIS_PUBLIC
67 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
68 #endif
69 
70 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
Defines the basic classes that form the basis to Rank and Select operations.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
void Match(const char *doc, MatchCallback callback, void *userobj) noexcept
Inspects the string to detect the target string.
Definition: AhoCorasick.h:35
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
void swap(AhoCorasick &rhs) noexcept
Swaps the contents of an object.
Definition: AhoCorasick.h:28
Uses the Aho-Corasick algorithm to detect language and patterns.
Definition: AhoCorasick.h:18
AhoCorasick() noexcept
Instantiates the object with default parameters (default constructor).
Definition: AhoCorasick.h:25
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
The class for writing binary to streams (to OutputStream).
Definition: BinaryWriter.h:13
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:13
Defines the class for constructing and accessing a parentheses representation of a tree...
Creates the index (automaton) used in the Aho-Corasick algorithm.