nlib
AhoCorasickBuilder.h
Go to the documentation of this file.
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
Creates the AhoCorasick object and return it with unique_ptr. Constructs an Aho-Corasick algorithm au...
#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:183
#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
constexpr AhoCorasickBuilder() noexcept
Instantiates the object with default parameters (default constructor).
Defines the class for searching text strings using the Aho-Corasick string-matching algorithm...
Implements stream-related classes usually commonly used, various containers, and other gadget classes...
Definition: Base64.h:25
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
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:250
Creates the index (automaton) used in the Aho-Corasick algorithm.
void MatchByBuilder(const char *doc, MatchCallback callback) noexcept
A parameter omitted version of the above function.