nlib
AhoCorasickBuilder.h
[詳解]
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
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 
22 #include "nn/nlib/Swap.h"
24 
25 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
26 #undef NLIB_VIS_PUBLIC
27 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
28 #endif
29 
30 NLIB_NAMESPACE_BEGIN
31 namespace succinct {
32 
34  public:
37  NLIB_DEFMOVE_PIMPL(AhoCorasickBuilder);
39  using std::swap;
40  swap(prv_, rhs.prv_);
41  }
42  void Reset() NLIB_NOEXCEPT;
43  bool Init() NLIB_NOEXCEPT;
44  bool AddWord(const char* str) NLIB_NOEXCEPT;
45  bool AddPattern(const void* p, size_t n) NLIB_NOEXCEPT;
46  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
47  bool AddWords(const char* str) NLIB_NOEXCEPT {
48  return AddWords(str, nlib_strlen(str));
49  }
50  AhoCorasick* Build() NLIB_NOEXCEPT;
51  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
52  void* user_obj);
53  void MatchByBuilder(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
54  void MatchByBuilder(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
55  MatchByBuilder(doc, callback, nullptr);
56  }
57  void print() NLIB_NOEXCEPT;
58  size_t GetNumWords() const NLIB_NOEXCEPT;
59  size_t GetNumBytes() const NLIB_NOEXCEPT;
60  size_t GetNumNodes() const NLIB_NOEXCEPT;
61 
62  private:
63  NLIB_VIS_HIDDEN bool SortNodes() NLIB_NOEXCEPT;
64  struct BuildFailureArcTh;
65  struct BuildReportTreeHolderTh;
66  struct BuildFailureTreeHolderTh;
67  struct BuildGotoArcHolderTh;
68  struct BuildLenHolderTh;
69  struct SortNodesTh;
70 
71  private:
72  struct AhoCorasickBuilderPrivate;
73  AhoCorasickBuilderPrivate* prv_;
75 };
76 
77 } // namespace succinct
78 NLIB_NAMESPACE_END
79 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::AhoCorasickBuilder)
80 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
81 #undef NLIB_VIS_PUBLIC
82 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
83 #endif
84 
85 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:88
#define NLIB_DEPRECATED
関数等がdeprecatedになったことを示します。
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
~AhoCorasickBuilder() noexcept
デストラクタです。
AC法を用いて語やパターンの検出を行います。
Definition: AhoCorasick.h:31
constexpr AhoCorasickBuilder() noexcept
デフォルトコンストラクタです。
Aho Corasick法を用いた文字列検索を行うためのクラスが定義されています。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
bool AddWords(const char *str) noexcept
検出対象の文字列の集合が入った配列から文字列を追加します。文字列の区切りは改行(CRLFかLF)である必要が...
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
AC法で用いるインデックス(オートマトン)を作成します。