liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
liblevenshtein::Prefix Class Reference

Represents the prefix of a dictionary term. More...

#include <prefix.h>

Collaboration diagram for liblevenshtein::Prefix:

Public Member Functions

 Prefix (DawgNode *node, Prefix *parent, char label)
 Constructs a new prefix that follows another along the path from the root node to the current one.
 
 Prefix (DawgNode *root)
 Constructs the initial prefix from which all prefixes of the dictionary terms follow.
 
 Prefix (const Prefix &prefix)=default
 Copy constructor for a prefix node.
 
 Prefix (Prefix &&prefix) noexcept
 Move constructor for a prefix node.
 
auto node () const -> DawgNode *
 Returns the node analogous to this prefix, within the dictionary.
 
auto label () const -> char
 Returns the character label associated with this prefixed position within the dictionary term.
 
auto str () const -> std::string
 Returns the string constructed by following the path between the root prefix node and this one, which is either a prefix of the current dictionary term or the whole term (which is also a prefix).
 

Private Attributes

DawgNode_node
 Analogous dictionary node to this prefix node.
 
Prefix_parent
 Parent prefix node to this one; used to construct the prefix string.
 
char _label
 Current character label along the path from the root prefix node to this one.
 

Friends

auto operator<< (std::ostream &out, const Prefix &prefix) -> std::ostream &
 Specifies the ostream operator may access all this node's members.
 

Detailed Description

Represents the prefix of a dictionary term.

The prefix is formed by traversing the outgoing edges from the root node of the dictionary.

Definition at line 16 of file prefix.h.

Constructor & Destructor Documentation

◆ Prefix() [1/4]

liblevenshtein::Prefix::Prefix ( DawgNode * node,
Prefix * parent,
char label )

Constructs a new prefix that follows another along the path from the root node to the current one.

Parameters
nodeDictionary node represented by this prefix.
parentPrefix representing the path from the root node to that immediately prior to this one.
labelCharacter label for the current position within the dictionary term.

Definition at line 8 of file prefix.cpp.

9 : _node(node),
12{}
char _label
Current character label along the path from the root prefix node to this one.
Definition prefix.h:92
Prefix * _parent
Parent prefix node to this one; used to construct the prefix string.
Definition prefix.h:88
auto label() const -> char
Returns the character label associated with this prefixed position within the dictionary term.
Definition prefix.cpp:30
auto node() const -> DawgNode *
Returns the node analogous to this prefix, within the dictionary.
Definition prefix.cpp:26
DawgNode * _node
Analogous dictionary node to this prefix node.
Definition prefix.h:85
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25

◆ Prefix() [2/4]

liblevenshtein::Prefix::Prefix ( DawgNode * root)

Constructs the initial prefix from which all prefixes of the dictionary terms follow.

Parameters
rootRoot node of the dictionary.

Definition at line 14 of file prefix.cpp.

15 : _node(root),
16 _parent(nullptr),
17 _label('\0')
18{}

◆ Prefix() [3/4]

liblevenshtein::Prefix::Prefix ( const Prefix & prefix)
default

Copy constructor for a prefix node.

Parameters
prefixPrefix node to copy.

◆ Prefix() [4/4]

liblevenshtein::Prefix::Prefix ( Prefix && prefix)
noexcept

Move constructor for a prefix node.

Parameters
prefixPrefix node whose memory must be moved.

Definition at line 20 of file prefix.cpp.

21 : _node(prefix._node),
22 _parent(prefix._parent),
23 _label(prefix._label)
24{}

Member Function Documentation

◆ label()

auto liblevenshtein::Prefix::label ( ) const -> char

Returns the character label associated with this prefixed position within the dictionary term.

Returns
The character label associated with the current position within the prefix of the dictionary term.

Definition at line 30 of file prefix.cpp.

30 {
31 return _label;
32}

References _label.

◆ node()

auto liblevenshtein::Prefix::node ( ) const -> DawgNode *

Returns the node analogous to this prefix, within the dictionary.

Returns
Dictionary node represented by this prefix.

Definition at line 26 of file prefix.cpp.

26 {
27 return _node;
28}

References _node.

◆ str()

auto liblevenshtein::Prefix::str ( ) const -> std::string

Returns the string constructed by following the path between the root prefix node and this one, which is either a prefix of the current dictionary term or the whole term (which is also a prefix).

Returns
The current prefix string of the dictionary term.

Definition at line 34 of file prefix.cpp.

34 {
35 std::stringstream ss;
36 ss << *this;
37 return ss.str();
38}

References query().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

auto operator<< ( std::ostream & out,
const Prefix & prefix ) -> std::ostream &
friend

Specifies the ostream operator may access all this node's members.

Definition at line 40 of file prefix.cpp.

40 {
41 if (prefix._parent != nullptr) {
42 out << *(prefix._parent) << prefix._label;
43 }
44 return out;
45}

Member Data Documentation

◆ _label

char liblevenshtein::Prefix::_label
private

Current character label along the path from the root prefix node to this one.

Definition at line 92 of file prefix.h.

Referenced by label().

◆ _node

DawgNode* liblevenshtein::Prefix::_node
private

Analogous dictionary node to this prefix node.

Definition at line 85 of file prefix.h.

Referenced by node().

◆ _parent

Prefix* liblevenshtein::Prefix::_parent
private

Parent prefix node to this one; used to construct the prefix string.

Definition at line 88 of file prefix.h.


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