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);
38  void Reset() NLIB_NOEXCEPT;
39  bool Init() NLIB_NOEXCEPT;
40  bool AddWord(const char* str) NLIB_NOEXCEPT;
41  bool AddPattern(const void* p, size_t n) NLIB_NOEXCEPT;
42  bool AddWords(const char* str, size_t len) NLIB_NOEXCEPT;
43  bool AddWords(const char* str) NLIB_NOEXCEPT { return AddWords(str, nlib_strlen(str)); }
44  AhoCorasick* Build() NLIB_NOEXCEPT;
45 #ifdef __cpp_rvalue_references
46  std::unique_ptr<AhoCorasick> Build2() NLIB_NOEXCEPT { return decltype(Build2())(Build()); }
47 #endif
48  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
49  void* user_obj);
50  void MatchByBuilder(const char* doc, MatchCallback callback, void* user_obj) NLIB_NOEXCEPT;
51  void MatchByBuilder(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
52  MatchByBuilder(doc, callback, nullptr);
53  }
54  void print() NLIB_NOEXCEPT;
55  size_t GetNumWords() const NLIB_NOEXCEPT;
56  size_t GetNumBytes() const NLIB_NOEXCEPT;
57  size_t GetNumNodes() const NLIB_NOEXCEPT;
58 
59  private:
60  NLIB_VIS_HIDDEN bool SortNodes() NLIB_NOEXCEPT;
61  struct BuildFailureArcTh;
62  struct BuildReportTreeHolderTh;
63  struct BuildFailureTreeHolderTh;
64  struct BuildGotoArcHolderTh;
65  struct BuildLenHolderTh;
66  struct SortNodesTh;
67 
68  private:
69  struct AhoCorasickBuilderPrivate;
70  AhoCorasickBuilderPrivate* prv_;
72 };
73 
74 } // namespace succinct
75 NLIB_NAMESPACE_END
76 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::AhoCorasickBuilder)
77 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
78 #undef NLIB_VIS_PUBLIC
79 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
80 #endif
81 
82 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICKBUILDER_H_
std::unique_ptr< AhoCorasick > Build2() noexcept
AhoCorasick オブジェクトを作成してunique_ptrで返します。追加された文字列(パターン)を検出するAC法のた...
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:86
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
~AhoCorasickBuilder() noexcept
デストラクタです。
AC法を用いて語やパターンの検出を行います。
Definition: AhoCorasick.h:31
constexpr AhoCorasickBuilder() noexcept
デフォルトコンストラクタです。
Aho Corasick法を用いた文字列検索を行うためのクラスが定義されています。
共通して使われることの多いストリーム関連のクラス群や各種コンテナ、及びガシェットクラスが実装されてい...
Definition: Base64.h:25
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
bool AddWords(const char *str) noexcept
検出対象の文字列の集合が入った配列から文字列を追加します。文字列の区切りは改行(CRLFかLF)である必要が...
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250
AC法で用いるインデックス(オートマトン)を作成します。
void MatchByBuilder(const char *doc, MatchCallback callback) noexcept
上記関数の引数省略版です。