nlib
AhoCorasickBuilder.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
4 #define INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
5 
6 #include <string.h>
7 #include <utility>
8 
10 
11 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
12 #undef NLIB_VIS_PUBLIC
13 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
14 #endif
15 
16 NLIB_NAMESPACE_BEGIN
17 namespace succinct {
18 
20  public:
23  bool Init() NLIB_NOEXCEPT;
24  bool AddWord(const char* str) NLIB_NOEXCEPT;
25  bool AddPattern(const void* p, size_t n) NLIB_NOEXCEPT;
26  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
27  bool AddWords(const char* str) NLIB_NOEXCEPT {
28  return AddWords(str, nlib_strlen(str));
29  }
30  AhoCorasick* Build() NLIB_NOEXCEPT;
31  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
32  void* user_obj);
33  void MatchByBuilder(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
34  void MatchByBuilder(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
35  MatchByBuilder(doc, callback, NULL);
36  }
37  void print() NLIB_NOEXCEPT;
38  size_t GetNumWords() const NLIB_NOEXCEPT;
39  size_t GetNumBytes() const NLIB_NOEXCEPT;
40  size_t GetNumNodes() const NLIB_NOEXCEPT;
41 
42  private:
43  NLIB_VIS_HIDDEN bool SortNodes() NLIB_NOEXCEPT;
44  struct BuildFailureArcTh;
45  struct BuildReportTreeHolderTh;
46  struct BuildFailureTreeHolderTh;
47  struct BuildGotoArcHolderTh;
48  struct BuildLenHolderTh;
49  struct SortNodesTh;
50 
51  private:
52  struct AhoCorasickBuilderPrivate;
53  AhoCorasickBuilderPrivate* prv_;
55 };
56 
57 } // namespace succinct
58 NLIB_NAMESPACE_END
59 
60 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
61 #undef NLIB_VIS_PUBLIC
62 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
63 #endif
64 
65 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
#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
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:60
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
Uses the Aho-Corasick algorithm to detect language and patterns.
Definition: AhoCorasick.h:18
AhoCorasickBuilder() noexcept
Instantiates the object with default parameters (default constructor).
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
#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.
bool AddWords(const char *str) noexcept
Adds a string from an array containing a set of target strings. The strings must be delimited by newl...
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
Creates the index (automaton) used in the Aho-Corasick algorithm.