3 #ifndef INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
4 #define INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
6 #include "nn/nlib/Swap.h"
10 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
11 #undef NLIB_VIS_PUBLIC
12 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
19 class GotoArcHolder NLIB_FINAL {
21 uint64_t GetPos(uint32_t nodeid,
unsigned char c)
NLIB_NOEXCEPT {
22 uint64_t rval = m_NumNodeId;
23 rval = rval * c + nodeid;
30 bool TurnOn(uint32_t nodeid,
unsigned char c) NLIB_NOEXCEPT {
31 uint64_t idx = this->GetPos(nodeid, c);
32 return m_Set.TurnOn(idx);
34 bool Build() NLIB_NOEXCEPT {
return m_Set.Build(); }
37 size_t MemSize()
const NLIB_NOEXCEPT {
return sizeof(m_NumNodeId) + m_Set.MemSize(); }
40 void swap(GotoArcHolder& rhs) NLIB_NOEXCEPT {
42 swap(m_Set, rhs.m_Set);
43 swap(m_NumNodeId, rhs.m_NumNodeId);
56 static const size_t LABEL_WIDTH = 8;
57 static const int LABEL_MASK = (1 << LABEL_WIDTH) - 1;
58 static const int NUMLABEL_PER_BYTE = 8 / LABEL_WIDTH;
63 NLIB_MOVE_MEMBER_HELPER_4(
AhoCorasick, m_LenHolder, m_ReportTreeHolder, m_GotoArcHolder,
66 typedef bool (*MatchCallback)(
const char* first,
const char* last, uint32_t nodeid,
68 void Match(
const char* doc, MatchCallback callback,
void* userobj = NULL) NLIB_NOEXCEPT {
69 this->Match(doc,
nlib_strlen(doc), callback, userobj);
71 NLIB_VIS_PUBLIC void Match(
const void* data,
size_t n, MatchCallback callback,
72 void* userobj = NULL) NLIB_NOEXCEPT;
75 NLIB_VIS_PUBLIC void MemSize(
size_t* len_store,
size_t* goto_arc,
size_t* report_arc,
76 size_t* failure_arc) const NLIB_NOEXCEPT;
83 Map m_ReportTreeHolder;
84 detail::GotoArcHolder m_GotoArcHolder;
85 Bp m_FailureTreeHolder;
95 NLIB_DEFINE_STD_SWAP(::
nlib_ns::succinct::AhoCorasick)
97 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS)
98 #undef NLIB_VIS_PUBLIC
99 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
102 #endif // INCLUDE_NN_NLIB_SUCCINCT_AHOCORASICK_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Defines the basic classes that form the basis to Rank and Select operations.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
void Match(const char *doc, MatchCallback callback, void *userobj=NULL) noexcept
Inspects the string to detect the target string.
Uses the Aho-Corasick algorithm to detect language and patterns.
Provides a compact tree structure that can provide various operations in constant time...
Implements common features and features that are highly platform-dependent. Also refer to nlib Platfo...
Succinct data structure to hold a nowhere dense set of 64-bit unsigned integers.
The class for writing binary to streams (to OutputStream).
A compact integer to integer read-only associative array.
The class for reading binary from streams (from InputStream).
Defines the class for constructing and accessing a parentheses representation of a tree...
Creates the index (automaton) used in the Aho-Corasick algorithm.