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

Iterates over the Position nodes in the linked-list of a Levenshtein State. More...

#include <state_iterator.h>

Collaboration diagram for liblevenshtein::StateIterator:

Public Member Functions

 StateIterator (State *state, Position *head, StateIterator *outer=nullptr)
 Constructs a new StateIterator of the Position nodes of state, with an optional outer pointer for unsubsumption.
 
void insert (Position *position)
 Inserts a new Position after the current one in the linked-list.
 
void remove ()
 Removes the current Position from the linked-list.
 
auto operator++ () -> StateIterator &
 Advances the Position in the linked-list by one.
 
auto operator* () const -> Position *
 Returns a pointer to the current Position in the linked-list.
 
auto operator== (const StateIterator &other) const -> bool
 Returns whether this StateIterator is equivalent to another.
 

Private Member Functions

void advance ()
 Advances the Position being iterated over by one.
 

Private Attributes

StateIterator_outer = nullptr
 Outermost iterator over the same linked-list, used for unsubsumption.
 
State_state = nullptr
 Levenshtein State that owns the linked-list being iterated over.
 
Position_next = nullptr
 Next Position to be iterated over.
 
Position_curr = nullptr
 Current Position being iterated over.
 
Position_prev = nullptr
 Previous Position being iterated over.
 

Detailed Description

Iterates over the Position nodes in the linked-list of a Levenshtein State.

Definition at line 14 of file state_iterator.h.

Constructor & Destructor Documentation

◆ StateIterator()

liblevenshtein::StateIterator::StateIterator ( State * state,
Position * head,
StateIterator * outer = nullptr )

Constructs a new StateIterator of the Position nodes of state, with an optional outer pointer for unsubsumption.

Parameters
stateLevenshtein State owning the linked-list being iterated over.
headHead Position of the current sub-list.
outerIterator during unsubsumption that owns the outermost level of iteration over the linked-list.

Definition at line 6 of file state_iterator.cpp.

7 : _outer(outer),
8 _state(state),
9 _curr(head),
10 _next(head != nullptr ? head->next() : nullptr)
11{}
StateIterator * _outer
Outermost iterator over the same linked-list, used for unsubsumption.
Position * _curr
Current Position being iterated over.
Position * _next
Next Position to be iterated over.
State * _state
Levenshtein State that owns the linked-list being iterated over.
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25

Member Function Documentation

◆ advance()

void liblevenshtein::StateIterator::advance ( )
private

Advances the Position being iterated over by one.

Definition at line 45 of file state_iterator.cpp.

45 {
46 if (_curr != nullptr) {
47 _prev = _curr;
48 }
49
50 _curr = _next;
51
52 if (_next != nullptr) {
53 _next = _next->next();
54 }
55}
void next(Position *next)
Assigns the subsequent Position along the current path.
Definition position.cpp:15
Position * _prev
Previous Position being iterated over.

References _curr, _next, _prev, and liblevenshtein::Position::next().

Here is the call graph for this function:

◆ insert()

void liblevenshtein::StateIterator::insert ( Position * position)

Inserts a new Position after the current one in the linked-list.

Parameters
positionNew Position to add after the current one in the linked-list.

Definition at line 26 of file state_iterator.cpp.

26 {
27 if (_curr != nullptr) {
29 } else {
31 }
33}
void insert_after(Position *curr, Position *next)
Inserts a new Position into the linked-list following an existing member.
Definition state.cpp:48
void head(Position *head)
Sets the first element in the linked-list of Position nodes.
Definition state.cpp:26

References _curr, _next, _state, liblevenshtein::State::head(), liblevenshtein::State::insert_after(), and query().

Here is the call graph for this function:

◆ operator*()

auto liblevenshtein::StateIterator::operator* ( ) const -> Position *

Returns a pointer to the current Position in the linked-list.

Returns
A pointer to the current Position in the linked-list.

Definition at line 18 of file state_iterator.cpp.

18 {
19 return _curr;
20}

References _curr.

◆ operator++()

auto liblevenshtein::StateIterator::operator++ ( ) -> StateIterator &

Advances the Position in the linked-list by one.

Returns
A reference to the iterator containing the advanced state.

Definition at line 13 of file state_iterator.cpp.

13 {
14 advance();
15 return *this;
16}
void advance()
Advances the Position being iterated over by one.

◆ operator==()

auto liblevenshtein::StateIterator::operator== ( const StateIterator & other) const -> bool

Returns whether this StateIterator is equivalent to another.

By convention, the iterators must be over the same linked-list.

Parameters
otherA StateIterator to compare with this one for equivalence.
Returns
Whether this StateIterator is equivalent to the other.

Definition at line 22 of file state_iterator.cpp.

22 {
23 return (_curr == other._curr) && (_next == other._next);
24}
Position * _next
The Position that follows this one along the current path.
Definition position.h:68

References query().

Here is the call graph for this function:

◆ remove()

void liblevenshtein::StateIterator::remove ( )

Removes the current Position from the linked-list.

Definition at line 35 of file state_iterator.cpp.

35 {
36 if (_curr != nullptr) {
37 if (_outer != nullptr && _outer->_next == _curr) {
39 }
41 _curr = nullptr;
42 }
43}
void remove(Position *prev, Position *curr)
Removes a Position from the linked-list.
Definition state.cpp:58

References _curr, _next, _outer, _prev, _state, liblevenshtein::Position::next(), and liblevenshtein::State::remove().

Here is the call graph for this function:

Member Data Documentation

◆ _curr

Position* liblevenshtein::StateIterator::_curr = nullptr
private

Current Position being iterated over.

Definition at line 75 of file state_iterator.h.

Referenced by advance(), insert(), operator*(), and remove().

◆ _next

Position* liblevenshtein::StateIterator::_next = nullptr
private

Next Position to be iterated over.

Definition at line 72 of file state_iterator.h.

Referenced by advance(), insert(), and remove().

◆ _outer

StateIterator* liblevenshtein::StateIterator::_outer = nullptr
private

Outermost iterator over the same linked-list, used for unsubsumption.

Definition at line 66 of file state_iterator.h.

Referenced by remove().

◆ _prev

Position* liblevenshtein::StateIterator::_prev = nullptr
private

Previous Position being iterated over.

Definition at line 78 of file state_iterator.h.

Referenced by advance(), and remove().

◆ _state

State* liblevenshtein::StateIterator::_state = nullptr
private

Levenshtein State that owns the linked-list being iterated over.

Definition at line 69 of file state_iterator.h.

Referenced by insert(), and remove().


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