nlib
AhoCorasick.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_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_
Defines the basic classes that form the basis to Rank and Select operations.
#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:163
void Match(const char *doc, MatchCallback callback, void *userobj) noexcept
Inspects the string to detect the target string.
Definition: AhoCorasick.h:48
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
void swap(AhoCorasick &rhs) noexcept
Swaps the contents of an object.
Definition: AhoCorasick.h:41
Uses the Aho-Corasick algorithm to detect language and patterns.
Definition: AhoCorasick.h:31
AhoCorasick() noexcept
Instantiates the object with default parameters (default constructor).
Definition: AhoCorasick.h:38
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
The class for writing binary to streams (to OutputStream).
Definition: BinaryWriter.h:26
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
The class for reading binary from streams (from InputStream).
Definition: BinaryReader.h:26
Defines the class for constructing and accessing a parentheses representation of a tree...
Creates the index (automaton) used in the Aho-Corasick algorithm.