nlib
AhoCorasickBuilder.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
17 #define INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
18 
19 #include <string.h>
20 #include <utility>
21 
23 
24 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
25 #undef NLIB_VIS_PUBLIC
26 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
27 #endif
28 
29 NLIB_NAMESPACE_BEGIN
30 namespace succinct {
31 
33  public:
36  bool Init() NLIB_NOEXCEPT;
37  bool AddWord(const char* str) NLIB_NOEXCEPT;
38  bool AddPattern(const void* p, size_t n) NLIB_NOEXCEPT;
39  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
40  bool AddWords(const char* str) NLIB_NOEXCEPT {
41  return AddWords(str, nlib_strlen(str));
42  }
43  AhoCorasick* Build() NLIB_NOEXCEPT;
44  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
45  void* user_obj);
46  void MatchByBuilder(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
47  void MatchByBuilder(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
48  MatchByBuilder(doc, callback, NULL);
49  }
50  void print() NLIB_NOEXCEPT;
51  size_t GetNumWords() const NLIB_NOEXCEPT;
52  size_t GetNumBytes() const NLIB_NOEXCEPT;
53  size_t GetNumNodes() const NLIB_NOEXCEPT;
54 
55  private:
56  NLIB_VIS_HIDDEN bool SortNodes() NLIB_NOEXCEPT;
57  struct BuildFailureArcTh;
58  struct BuildReportTreeHolderTh;
59  struct BuildFailureTreeHolderTh;
60  struct BuildGotoArcHolderTh;
61  struct BuildLenHolderTh;
62  struct SortNodesTh;
63 
64  private:
65  struct AhoCorasickBuilderPrivate;
66  AhoCorasickBuilderPrivate* prv_;
68 };
69 
70 } // namespace succinct
71 NLIB_NAMESPACE_END
72 
73 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
74 #undef NLIB_VIS_PUBLIC
75 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
76 #endif
77 
78 #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:158
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:86
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
Uses the Aho-Corasick algorithm to detect language and patterns.
Definition: AhoCorasick.h:31
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:99
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:224
Creates the index (automaton) used in the Aho-Corasick algorithm.