nlib
nn::nlib::succinct::AhoCorasick Class Referencefinal

Uses the Aho-Corasick algorithm to detect language and patterns. More...

#include "nn/nlib/succinct/AhoCorasick.h"

Public Member Functions

void Reset () noexcept
 Returns the object to the state immediately after the constructor is called.
 
Basic Member Functions
 AhoCorasick () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~AhoCorasick () noexcept
 Destructor.
 
AhoCorasickassign (AhoCorasick &rhs, move_tag)
 Assigns the object by using swap for a move.
 
 AhoCorasick (AhoCorasick &rhs, move_tag)
 Instantiates the object by using swap for a move.
 
 AhoCorasick (AhoCorasick &&rhs)
 Instantiates the object (move constructor). This function is useful when using C++11.
 
AhoCorasickoperator= (AhoCorasick &&rhs)
 Move assignment operator. This function is useful when using C++11.
 
void swap (AhoCorasick &rhs) noexcept
 Swaps the contents of an object.
 
Importing and Exporting Data
bool Export (BinaryWriter *w) const noexcept
 Writes the object to the file. More...
 
bool Import (BinaryReader *r) noexcept
 Reads the written object. More...
 

String Matching

typedef bool(* MatchCallback) (const char *first, const char *last, uint32_t nodeid, void *user_obj)
 The user-defined callback function is called when the target string is detected. More...
 
void Match (const char *doc, MatchCallback callback, void *userobj) noexcept
 Inspects the string to detect the target string. More...
 
void Match (const void *data, size_t n, MatchCallback callback, void *userobj) noexcept
 Inspects the data to detect the target pattern. More...
 
size_t MemSize () const noexcept
 Returns the amount of memory explicitly allocated by the class. More...
 

Detailed Description

Uses the Aho-Corasick algorithm to detect language and patterns.

Description
The automaton used in the Aho-Corasick algorithm is implemented in a compact size in an implementation described in the following link with minor changes.
The class object is built using AhoCorasickBuilder::Build or the AhoCorasick::Import function.

Definition at line 31 of file AhoCorasick.h.

Member Typedef Documentation

◆ MatchCallback

nn::nlib::succinct::AhoCorasick::MatchCallback

The user-defined callback function is called when the target string is detected.

Parameters
[in]firstPointer to the head of the extracted terms.
[in]lastPointer to the tail of the extracted terms.
[in]nodeidThe ID of the detected term (not a continuous value).
[in,out]user_objPointer to the user-specified object.
Returns
Continues analysis if true. Ends the process when false.
Description
Called when the string (pattern) is detected. Developers will write a process to handle each.

Definition at line 46 of file AhoCorasick.h.

Member Function Documentation

◆ Export()

nn::nlib::succinct::AhoCorasick::Export ( BinaryWriter w) const
noexcept

Writes the object to the file.

Parameters
[in]wWrite out object.
Returns
Returns true when successful.
Description
The written data can be read and restored using the Import function. The data is always written little endian.

◆ Import()

nn::nlib::succinct::AhoCorasick::Import ( BinaryReader r)
noexcept

Reads the written object.

Parameters
[in]rRead out object.
Returns
Returns true when import is successful.

◆ Match() [1/2]

nn::nlib::succinct::AhoCorasick::Match ( const char *  doc,
MatchCallback  callback,
void *  userobj 
)
inlinenoexcept

Inspects the string to detect the target string.

Parameters
[in]docString that terminates at null.
[in]callbackCallback function called when the term is detected.
[in,out]userobjPointer to the user-specified object.

Definition at line 48 of file AhoCorasick.h.

◆ Match() [2/2]

nn::nlib::succinct::AhoCorasick::Match ( const void *  data,
size_t  n,
MatchCallback  callback,
void *  userobj 
)
noexcept

Inspects the data to detect the target pattern.

Parameters
[in]dataThe data to draw.
[in]nData size.
[in]callbackCallback function called when the pattern is detected.
[in,out]userobjPointer to the user-specified object.

◆ MemSize()

nn::nlib::succinct::AhoCorasick::MemSize ( ) const
noexcept

Returns the amount of memory explicitly allocated by the class.

Description
The actual amount of memory allocated by the system may be larger than the value returned by this function because of alignment and space for heap management.
Returns
Returns the number of bytes.

The documentation for this class was generated from the following files: