reglibcpp  1.6.0
(Naïve) C++ implementation of models for regular languages
Public Member Functions | Public Attributes | List of all members
reg::dfa::builder::pImpl Struct Reference

Private implementation details of DFA builders. More...

Public Member Functions

 pImpl ()=default
 Constructs empty private implementation object. More...
 
 pImpl (string &initial, unordered_set< char32_t > &alphabet, unordered_set< string > &acceptingStates, Dtransitionmap &transitions)
 Constructs private implementation object with provided members. More...
 
bool isTrashState (string const &q) const
 Tests whether all of a state's outgoing transitions point to itself. More...
 
string const & generateNewState ()
 Generates a uniquely named new state and adds it to the set of states. More...
 
void complete ()
 Totalizes a partial transition function by pointing any undefined transitions towards a trash state. More...
 

Public Attributes

string initial
 Name of the prospective DFA's initial state. More...
 
unordered_set< char32_t > alphabet
 Set of symbols processable by the prospective DFA. More...
 
unordered_set< stringacceptingStates
 Set of names of the prospective DFA's accept states. More...
 
Dtransitionmap transitions
 Transition function (state × symbol → state) of the prospective DFA. More...
 

Detailed Description

Private implementation details of DFA builders.

Definition at line 493 of file dfa.cpp.

Constructor & Destructor Documentation

◆ pImpl() [1/2]

reg::dfa::builder::pImpl::pImpl ( )
default

Constructs empty private implementation object.

◆ pImpl() [2/2]

reg::dfa::builder::pImpl::pImpl ( string initial,
unordered_set< char32_t > &  alphabet,
unordered_set< string > &  acceptingStates,
Dtransitionmap transitions 
)
inline

Constructs private implementation object with provided members.

Definition at line 505 of file dfa.cpp.

510  : initial(move(initial)),
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:497
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:495
T move(T... args)
string initial
Name of the prospective DFA&#39;s initial state.
Definition: dfa.cpp:494
unordered_set< string > acceptingStates
Set of names of the prospective DFA&#39;s accept states.
Definition: dfa.cpp:496

Member Function Documentation

◆ complete()

void reg::dfa::builder::pImpl::complete ( )
inline

Totalizes a partial transition function by pointing any undefined transitions towards a trash state.

If there is no state satisfying trashiness, a new one will be generated.

Definition at line 545 of file dfa.cpp.

545  {
546  bool trashUsed(false);
547  string const& trashState = [&]{
548  for (auto const& entry : this->transitions) {
549  if (this->isTrashState(entry.first)) {
550  trashUsed = true;
551  return entry.first;
552  }
553  }
554  return this->generateNewState();
555  }();
556  for (auto& from : transitions) {
557  for (char32_t symbol : alphabet) {
558  if (from.second.find(symbol) == from.second.end()) {
559  from.second[symbol] = trashState;
560  trashUsed |= (from.first != trashState);
561  }
562  }
563  }
564  if (!trashUsed) {
565  transitions.erase(trashState);
566  }
567  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:497
bool isTrashState(string const &q) const
Tests whether all of a state's outgoing transitions point to itself.
Definition: dfa.cpp:516
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:495
string const & generateNewState()
Generates a uniquely named new state and adds it to the set of states.
Definition: dfa.cpp:531

◆ generateNewState()

string const& reg::dfa::builder::pImpl::generateNewState ( )
inline

Generates a uniquely named new state and adds it to the set of states.

Definition at line 531 of file dfa.cpp.

531  {
532  size_t q(0);
533  string newState;
534  while (transitions.find(newState = "q" + to_string(q)) != transitions.end()) {
535  q++;
536  }
537  if (transitions.empty()) {
538  initial = newState;
539  }
540  return transitions.insert(std::make_pair(newState, unordered_map<char32_t, string>())).first->first;
541  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:497
T to_string(T... args)
string initial
Name of the prospective DFA&#39;s initial state.
Definition: dfa.cpp:494

◆ isTrashState()

bool reg::dfa::builder::pImpl::isTrashState ( string const &  q) const
inline

Tests whether all of a state's outgoing transitions point to itself.

Definition at line 516 of file dfa.cpp.

516  {
517  if (acceptingStates.count(q) != 0) {
518  return false;
519  }
520  auto const& from = transitions.at(q);
521  for (char32_t symbol : alphabet) {
522  auto via = from.find(symbol);
523  if (via != from.end() && (*via).second != q) {
524  return false;
525  }
526  }
527  return true;
528  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:497
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:495
unordered_set< string > acceptingStates
Set of names of the prospective DFA&#39;s accept states.
Definition: dfa.cpp:496

Member Data Documentation

◆ acceptingStates

unordered_set<string> reg::dfa::builder::pImpl::acceptingStates

Set of names of the prospective DFA's accept states.

Definition at line 496 of file dfa.cpp.

◆ alphabet

unordered_set<char32_t> reg::dfa::builder::pImpl::alphabet

Set of symbols processable by the prospective DFA.

Definition at line 495 of file dfa.cpp.

◆ initial

string reg::dfa::builder::pImpl::initial

Name of the prospective DFA's initial state.

Definition at line 494 of file dfa.cpp.

◆ transitions

Dtransitionmap reg::dfa::builder::pImpl::transitions

Transition function (state × symbol → state) of the prospective DFA.

Also encodes the set of states in its set of keys.

Definition at line 497 of file dfa.cpp.


The documentation for this struct was generated from the following file: