|
REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
|
What successive munches over ONE subject have learnt, so that tokenizing the whole subject costs O(states × length) instead of O(length²) (Reps, "Maximal-munch tokenization in linear time", 1998). More...
#include <dfa.hpp>
Public Member Functions | |
| dfa_munch_memo (std::size_t subject_size) | |
| An empty memo for one subject. | |
| std::size_t | transitions () const noexcept |
| DFA transitions taken by every munch so far – the work the bound is stated in. | |
| bool | armed () const noexcept |
| Whether a walk over this subject has run more than short_stretch steps past its last accept, so later walks consult the memo; until then it holds nothing and costs nothing. | |
Private Attributes | |
| std::size_t | size_ |
| The subject's length. | |
| std::vector< std::vector< bool > > | dead_after_ |
| [state][position]: no accept follows. | |
| std::vector< std::uint8_t > | marked_ |
| [state]: dead_after_[state] holds a mark. | |
| bool | marks_from_open_walks_ {} |
| A mark came from a walk alive at the subject's end: dead for this subject only. | |
| std::size_t | transitions_ {0} |
| See transitions(). | |
| const void * | owner_ {nullptr} |
| The dfa's tables this memo describes. | |
Friends | |
| class | dfa |
What successive munches over ONE subject have learnt, so that tokenizing the whole subject costs O(states × length) instead of O(length²) (Reps, "Maximal-munch tokenization in linear time", 1998).
A munch walks the DFA until it dies or the subject ends, then answers its last accepting position. Every (state, position) visited after that position leads to no accept, so a later munch reaching the same pair can stop there with the answer it holds. Without this, a rule like a*b beside a rescans the rest of aaa… from every position.
Bound to one dfa and one subject: pass it to dfa::match(std::string_view, std::size_t, dfa_munch_memo&) const with the same pair every time. Memory is one bit per remembered state per subject position, allocated on a state's first mark; a walk replays its dead stretch to mark it rather than holding it.
|
inlineexplicit |
An empty memo for one subject.
| [in] | subject_size | The subject's length in bytes. |
|
inlinenoexcept |
Whether a walk over this subject has run more than short_stretch steps past its last accept, so later walks consult the memo; until then it holds nothing and costs nothing.
|
inlinenoexcept |
DFA transitions taken by every munch so far – the work the bound is stated in.