nlib
AhoCorasick.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_AHOCORASICK_H_
17 #define INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
18 
19 #include "nn/nlib/Swap.h"
20 #include "nn/nlib/succinct/Bp.h"
21 #include "nn/nlib/succinct/Sbv.h"
22 
23 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
24 #undef NLIB_VIS_PUBLIC
25 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
26 #endif
27 
28 NLIB_NAMESPACE_BEGIN
29 namespace succinct {
30 
32  public:
33  static const size_t LABEL_WIDTH = 8; // 1,2,4,8
34  static const int LABEL_MASK = (1 << LABEL_WIDTH) - 1;
35  static const int NUMLABEL_PER_BYTE = 8 / LABEL_WIDTH;
36 
37  public:
38  AhoCorasick() NLIB_NOEXCEPT : prv_(NULL) {}
40  NLIB_MOVE_MEMBER_HELPER_1(AhoCorasick, prv_);
42  AhoCorasickPrivate* tmp = prv_;
43  prv_ = rhs.prv_;
44  rhs.prv_ = tmp;
45  }
46  typedef bool (*MatchCallback)(const char* first, const char* last, uint32_t nodeid,
47  void* user_obj);
48  void Match(const char* doc, MatchCallback callback, void* userobj) NLIB_NOEXCEPT {
49  this->Match(doc, nlib_strlen(doc), callback, userobj);
50  }
51  void Match(const char* doc, MatchCallback callback) NLIB_NOEXCEPT {
52  this->Match(doc, nlib_strlen(doc), callback, NULL);
53  }
54  void Match(const void* data, size_t n, MatchCallback callback, void* userobj) NLIB_NOEXCEPT;
55  void Match(const void* data, size_t n, MatchCallback callback) NLIB_NOEXCEPT {
56  Match(data, n, callback, NULL);
57  }
58  size_t MemSize() const NLIB_NOEXCEPT;
59 
60  void MemSize(size_t* len_store, size_t* goto_arc, size_t* report_arc,
61  size_t* failure_arc) const NLIB_NOEXCEPT;
62  void Reset() NLIB_NOEXCEPT;
63  bool Export(BinaryWriter* w) const NLIB_NOEXCEPT;
64  bool Import(BinaryReader* r) NLIB_NOEXCEPT;
65 
66  private:
67  struct AhoCorasickPrivate;
68  AhoCorasickPrivate* prv_;
69  friend class AhoCorasickBuilder;
71 };
72 
73 } // namespace succinct
74 NLIB_NAMESPACE_END
75 
76 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::AhoCorasick)
77 
78 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
79 #undef NLIB_VIS_PUBLIC
80 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
81 #endif
82 
83 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
rank/select操作をベースとした基本的なクラスが定義されています。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:163
void Match(const char *doc, MatchCallback callback, void *userobj) noexcept
文字列を検査して検出対象の文字列を検出します。
Definition: AhoCorasick.h:48
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
void swap(AhoCorasick &rhs) noexcept
オブジェクトの内容をスワップします。
Definition: AhoCorasick.h:41
AC法を用いて語やパターンの検出を行います。
Definition: AhoCorasick.h:31
AhoCorasick() noexcept
デフォルトコンストラクタです。
Definition: AhoCorasick.h:38
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
ストリーム(OutputStream)にバイナリを書き込むクラスです。
Definition: BinaryWriter.h:26
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
ストリーム(InputStream)からバイナリを読み込むクラスです。
Definition: BinaryReader.h:26
括弧木を構築したり、括弧木にアクセスしたりするためのクラスが定義されています。
AC法で用いるインデックス(オートマトン)を作成します。