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);
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)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:179
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:88
#define NLIB_DEPRECATED
Indicates that a function or something has been deprecated.
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
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...
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
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:245
Creates the index (automaton) used in the Aho-Corasick algorithm.