Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BackboneLength.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <queue>
9
10#include <ext/algorithm>
11#include <ext/utility>
12
13#include <automaton/FSM/DFA.h>
14
15namespace stringology {
16
17namespace properties {
18
20public:
26 template < class SymbolType, class StateType >
28
29 template < class StateType >
31 public:
32 bool operator ( ) ( const std::pair < StateType, unsigned > & first, const std::pair < StateType, unsigned > & second ) {
33 return first.second < second.second;
34 }
35 };
36
37};
38
39template < class SymbolType, class StateType >
41 std::priority_queue < std::pair < StateType, unsigned >, ext::vector < std::pair < StateType, unsigned > >, BackboneLengthLess < StateType > > open;
43
44 unsigned max = 0;
45 open.push ( std::make_pair ( automaton.getInitialState ( ), max ) );
46
47 while ( ! open.empty ( ) ) {
48 std::pair < StateType, unsigned > current = std::move ( open.top ( ) );
49 open.pop ( );
50 unsigned & dist = closed [ current.first ];
51
52 if ( dist > current.second )
53 continue;
54
55 dist = current.second;
56 max = std::max ( max, current.second );
57
58 for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & target : automaton.getTransitionsFromState ( current.first ) )
59 open.push ( std::make_pair ( target.second, current.second + 1 ) );
60 }
61
62 return max;
63}
64
65} /* namespace properties */
66
67} /* namespace stringology */
68
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Definition: BackboneLength.h:19
static unsigned length(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: BackboneLength.h:40
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
p second
Definition: ToRegExpAlgebraic.h:126
Definition: ToGrammar.h:31
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ArithmeticCompression.h:18