From 3a39d6ab22b2084346aa7c9e4988d345f2002cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz> Date: Thu, 25 Nov 2021 14:27:28 +0100 Subject: [PATCH] data: count -> contains even though the count result casted to boolean is semantically the same, contains is more expressive --- alib2data/src/automaton/FSM/CompactDFA.h | 18 ++++++------- alib2data/src/automaton/FSM/CompactNFA.h | 18 ++++++------- alib2data/src/automaton/FSM/DFA.h | 16 ++++++------ alib2data/src/automaton/FSM/EpsilonNFA.h | 24 ++++++++--------- alib2data/src/automaton/FSM/ExtendedNFA.h | 18 ++++++------- .../FSM/MultiInitialStateEpsilonNFA.h | 26 +++++++++---------- .../src/automaton/FSM/MultiInitialStateNFA.h | 18 ++++++------- alib2data/src/automaton/FSM/NFA.h | 18 ++++++------- 8 files changed, 78 insertions(+), 78 deletions(-) diff --git a/alib2data/src/automaton/FSM/CompactDFA.h b/alib2data/src/automaton/FSM/CompactDFA.h index c66e2214a7..b9625c0666 100644 --- a/alib2data/src/automaton/FSM/CompactDFA.h +++ b/alib2data/src/automaton/FSM/CompactDFA.h @@ -430,16 +430,16 @@ CompactDFA < SymbolType, StateType >::CompactDFA ( const DFA < SymbolType, State template < class SymbolType, class StateType > bool CompactDFA < SymbolType, StateType >::addTransition ( StateType from, ext::vector < SymbolType > input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); ext::set < SymbolType > inputStringAlphabet ( input.begin ( ), input.end ( ) ); // Transition regexp's alphabet must be subset of automaton's alphabet - if ( !std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputStringAlphabet.begin ( ), inputStringAlphabet.end ( ) ) ) + if ( ! std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputStringAlphabet.begin ( ), inputStringAlphabet.end ( ) ) ) throw AutomatonException ( "Input string is over different alphabet than automaton" ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); ext::pair < StateType, ext::vector < SymbolType > > key = ext::make_pair ( std::move ( from ), std::move ( input ) ); @@ -486,7 +486,7 @@ ext::map < ext::pair < StateType, ext::vector < SymbolType > >, StateType > && C template<class SymbolType, class StateType > ext::iterator_range < typename ext::map < ext::pair < StateType, ext::vector < SymbolType > >, StateType >::const_iterator > CompactDFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); auto lower = transitions.lower_bound ( ext::slice_comp ( from ) ); @@ -497,7 +497,7 @@ ext::iterator_range < typename ext::map < ext::pair < StateType, ext::vector < S template < class SymbolType, class StateType > ext::map < ext::pair < StateType, ext::vector < SymbolType > >, StateType > CompactDFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::map < ext::pair < StateType, ext::vector < SymbolType > >, StateType > transitionsToState; @@ -533,7 +533,7 @@ public: static bool used ( const automaton::CompactDFA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { for ( const std::pair < const ext::pair < StateType, ext::vector < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) { ext::set < SymbolType > alphabet ( transition.first.second.begin ( ), transition.first.second.end ( ) ); - if ( alphabet.count ( symbol ) ) + if ( alphabet.contains ( symbol ) ) return true; } @@ -583,7 +583,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, ext::vector < SymbolType > >, StateType > & t : automaton.getTransitions ( ) ) @@ -645,7 +645,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::CompactDFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -676,7 +676,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::CompactDFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index 38c9eb6232..7e092c9579 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -511,16 +511,16 @@ CompactNFA < SymbolType, StateType >::CompactNFA ( const DFA < SymbolType, State template < class SymbolType, class StateType > bool CompactNFA < SymbolType, StateType >::addTransition ( StateType from, ext::vector < SymbolType > input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); ext::set < SymbolType > inputStringAlphabet ( input.begin ( ), input.end ( ) ); // Transition regexp's alphabet must be subset of automaton's alphabet - if ( !std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputStringAlphabet.begin ( ), inputStringAlphabet.end ( ) ) ) + if ( ! std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputStringAlphabet.begin ( ), inputStringAlphabet.end ( ) ) ) throw AutomatonException ( "Input string is over different alphabet than automaton" ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -558,7 +558,7 @@ ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > template < class SymbolType, class StateType > ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > CompactNFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > transitionsFromState; @@ -572,7 +572,7 @@ ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > template < class SymbolType, class StateType > ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > CompactNFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, ext::vector < SymbolType > >, StateType > transitionsToState; @@ -608,7 +608,7 @@ public: static bool used ( const automaton::CompactNFA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { for ( const std::pair < const ext::pair < StateType, ext::vector < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) { ext::set < SymbolType > alphabet ( transition.first.second.begin ( ), transition.first.second.end ( ) ); - if ( alphabet.count ( symbol ) ) + if ( alphabet.contains ( symbol ) ) return true; } @@ -658,7 +658,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, ext::vector < SymbolType > >, StateType > & t : automaton.getTransitions ( ) ) @@ -720,7 +720,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::CompactNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -751,7 +751,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::CompactNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index 5c5d05d856..9837643a46 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -425,13 +425,13 @@ DFA<SymbolType, StateType>::DFA ( StateType initialState ) : DFA ( ext::set < St template<class SymbolType, class StateType > bool DFA<SymbolType, StateType>::addTransition ( StateType from, SymbolType input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - if ( !getInputAlphabet ( ).count ( input ) ) + if ( ! getInputAlphabet ( ).contains ( input ) ) throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); ext::pair < StateType, SymbolType > key = ext::make_pair ( std::move ( from ), std::move ( input ) ); @@ -476,7 +476,7 @@ ext::map < ext::pair < StateType, SymbolType >, StateType > && DFA<SymbolType, S template<class SymbolType, class StateType > ext::iterator_range < typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator > DFA<SymbolType, StateType>::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); auto lower = transitions.lower_bound ( ext::slice_comp ( from ) ); @@ -487,7 +487,7 @@ ext::iterator_range < typename ext::map < ext::pair < StateType, SymbolType >, S template<class SymbolType, class StateType > ext::map < ext::pair < StateType, SymbolType >, StateType > DFA<SymbolType, StateType>::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::map < ext::pair < StateType, SymbolType >, StateType > transitionsToState; @@ -577,7 +577,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & t : automaton.getTransitions ( ) ) @@ -640,7 +640,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::DFA<SymbolType, StateType> & automaton, const StateType & state ) { - return automaton.getStates ( ).count ( state ); + return automaton.getStates ( ).contains ( state ); } /** @@ -672,7 +672,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::DFA<SymbolType, StateType> & automaton, const StateType & state ) { - return automaton.getStates ( ).count ( state ); + return automaton.getStates ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index c8535b93a0..1b2a2041bd 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -597,13 +597,13 @@ EpsilonNFA < SymbolType, StateType >::EpsilonNFA ( const DFA < SymbolType, State template<class SymbolType, class StateType > bool EpsilonNFA < SymbolType, StateType >::addTransition ( StateType from, common::symbol_or_epsilon < SymbolType > input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - if ( ! input.is_epsilon ( ) && !getInputAlphabet ( ).count ( input.getSymbol ( ) ) ) + if ( ! input.is_epsilon ( ) && !getInputAlphabet ( ).contains ( input.getSymbol ( ) ) ) throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -691,7 +691,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > EpsilonNFA < Sy template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > EpsilonNFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > transitionsFromState; @@ -705,7 +705,7 @@ ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > template<class SymbolType, class StateType > ext::multimap < StateType, StateType > EpsilonNFA < SymbolType, StateType >::getEpsilonTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::pair < StateType, common::symbol_or_epsilon < SymbolType > > key ( from, common::symbol_or_epsilon < SymbolType > ( ) ); @@ -718,7 +718,7 @@ ext::multimap < StateType, StateType > EpsilonNFA < SymbolType, StateType >::get template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > EpsilonNFA < SymbolType, StateType >::getSymbolTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsFromState; @@ -732,7 +732,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > EpsilonNFA < Sy template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > EpsilonNFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > transitionsToState; @@ -746,7 +746,7 @@ ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > template<class SymbolType, class StateType > ext::multimap < StateType, StateType > EpsilonNFA < SymbolType, StateType >::getEpsilonTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < StateType, StateType > transitionsToState; @@ -760,7 +760,7 @@ ext::multimap < StateType, StateType > EpsilonNFA < SymbolType, StateType >::get template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > EpsilonNFA < SymbolType, StateType >::getSymbolTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsToState; @@ -870,7 +870,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) @@ -932,7 +932,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::EpsilonNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -963,7 +963,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::EpsilonNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index 0d03210d77..b34cb87027 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -537,16 +537,16 @@ ExtendedNFA < SymbolType, StateType >::ExtendedNFA ( const DFA < SymbolType, Sta template<class SymbolType, class StateType > bool ExtendedNFA < SymbolType, StateType >::addTransition ( StateType from, regexp::UnboundedRegExpStructure < SymbolType > input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); ext::set < SymbolType > inputRegExpAlphabet = input.getStructure ( ).computeMinimalAlphabet ( ); // Transition regexp's alphabet must be subset of automaton's alphabet - if ( !std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputRegExpAlphabet.begin ( ), inputRegExpAlphabet.end ( ) ) ) + if ( ! std::includes ( getInputAlphabet ( ).begin ( ), getInputAlphabet ( ).end ( ), inputRegExpAlphabet.begin ( ), inputRegExpAlphabet.end ( ) ) ) throw AutomatonException ( "Input string is over different alphabet than automaton" ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -584,7 +584,7 @@ ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < Symbol template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > ExtendedNFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > transitionsFromState; @@ -598,7 +598,7 @@ ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < Symbol template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > ExtendedNFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > transitionsToState; @@ -634,7 +634,7 @@ public: static bool used ( const automaton::ExtendedNFA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { for ( const std::pair < const ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) { ext::set < SymbolType > alphabet = transition.first.second.getStructure ( ).computeMinimalAlphabet ( ); - if ( alphabet.count ( symbol ) ) + if ( alphabet.contains ( symbol ) ) return true; } @@ -684,7 +684,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) @@ -746,7 +746,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::ExtendedNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -777,7 +777,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::ExtendedNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h index 1267336f3a..9d1c27fa61 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h @@ -629,13 +629,13 @@ MultiInitialStateEpsilonNFA < SymbolType, StateType >::MultiInitialStateEpsilonN template<class SymbolType, class StateType > bool MultiInitialStateEpsilonNFA < SymbolType, StateType >::addTransition ( StateType from, common::symbol_or_epsilon < SymbolType > input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - if ( ! input.is_epsilon ( ) && !getInputAlphabet ( ).count ( input ) ) + if ( ! input.is_epsilon ( ) && !getInputAlphabet ( ).contains ( input ) ) throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -723,7 +723,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialSta template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > transitionsFromState; @@ -737,7 +737,7 @@ ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > template<class SymbolType, class StateType > ext::multimap < StateType, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getEpsilonTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::pair < StateType, common::symbol_or_epsilon < SymbolType > > key ( from, common::symbol_or_epsilon < SymbolType > ( ) ); @@ -751,7 +751,7 @@ ext::multimap < StateType, StateType > MultiInitialStateEpsilonNFA < SymbolType, template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getSymbolTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsFromState; @@ -765,7 +765,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialSta template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > transitionsToState; @@ -779,7 +779,7 @@ ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < SymbolType > template<class SymbolType, class StateType > ext::multimap < StateType, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getEpsilonTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < StateType, StateType > transitionsToState; @@ -793,7 +793,7 @@ ext::multimap < StateType, StateType > MultiInitialStateEpsilonNFA < SymbolType, template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialStateEpsilonNFA < SymbolType, StateType >::getSymbolTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsToState; @@ -900,10 +900,10 @@ public: * \returns true if the state is used, false othervise */ static bool used ( const automaton::MultiInitialStateEpsilonNFA < SymbolType, StateType > & automaton, const StateType & state ) { - if ( automaton.getInitialStates ( ).count ( state ) ) + if ( automaton.getInitialStates ( ).contains ( state ) ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > & transition : automaton.getTransitions ( ) ) @@ -965,7 +965,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::MultiInitialStateEpsilonNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -1008,7 +1008,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::MultiInitialStateEpsilonNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h index 7a0c768e30..9c5c88c747 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h @@ -479,13 +479,13 @@ MultiInitialStateNFA < SymbolType, StateType >::MultiInitialStateNFA ( const NFA template < class SymbolType, class StateType > bool MultiInitialStateNFA < SymbolType, StateType >::addTransition ( StateType from, SymbolType input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - if ( !getInputAlphabet ( ).count ( input ) ) + if ( ! getInputAlphabet ( ).contains ( input ) ) throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -523,7 +523,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > && MultiInitial template < class SymbolType, class StateType > auto MultiInitialStateNFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); return transitions.equal_range ( ext::slice_comp ( from ) ); @@ -531,7 +531,7 @@ auto MultiInitialStateNFA < SymbolType, StateType >::getTransitionsFromState ( c template < class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialStateNFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsToState; @@ -629,10 +629,10 @@ public: * \returns true if the state is used, false othervise */ static bool used ( const automaton::MultiInitialStateNFA < SymbolType, StateType > & automaton, const StateType & state ) { - if ( automaton.getInitialStates ( ).count ( state ) ) + if ( automaton.getInitialStates ( ).contains ( state ) ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & transition : automaton.getTransitions ( ) ) @@ -694,7 +694,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::MultiInitialStateNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -737,7 +737,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::MultiInitialStateNFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index 4f5345bf20..d60fc3b524 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -443,13 +443,13 @@ NFA < SymbolType, StateType >::NFA ( const DFA < SymbolType, StateType > & other template<class SymbolType, class StateType > bool NFA < SymbolType, StateType >::addTransition ( StateType from, SymbolType input, StateType to ) { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - if ( !getInputAlphabet ( ).count ( input ) ) + if ( ! getInputAlphabet ( ).contains ( input ) ) throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist." ); auto upper_bound = transitions.upper_bound ( ext::tie ( from, input ) ); @@ -487,7 +487,7 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > && NFA < Symbol template<class SymbolType, class StateType > auto NFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if ( !getStates ( ).count ( from ) ) + if ( ! getStates ( ).contains ( from ) ) throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); return transitions.equal_range ( ext::slice_comp ( from ) ); @@ -495,7 +495,7 @@ auto NFA < SymbolType, StateType >::getTransitionsFromState ( const StateType & template<class SymbolType, class StateType > ext::multimap < ext::pair < StateType, SymbolType >, StateType > NFA < SymbolType, StateType >::getTransitionsToState ( const StateType & to ) const { - if ( !getStates ( ).count ( to ) ) + if ( ! getStates ( ).contains ( to ) ) throw AutomatonException ( "State \"" + ext::to_string ( to ) + "\" doesn't exist" ); ext::multimap < ext::pair < StateType, SymbolType >, StateType > transitionsToState; @@ -523,7 +523,7 @@ template<class SymbolType, class StateType > bool NFA < SymbolType, StateType >::isTotal ( ) const { for ( const StateType & state : getStates ( ) ) { for ( const SymbolType & symbol : getInputAlphabet ( ) ) { - if ( 0 == getTransitions ( ).count ( ext::make_pair ( state, symbol ) ) ) + if ( ! getTransitions ( ).contains ( ext::make_pair ( state, symbol ) ) ) return false; } } @@ -602,7 +602,7 @@ public: if ( automaton.getInitialState ( ) == state ) return true; - if ( automaton.getFinalStates ( ).count ( state ) ) + if ( automaton.getFinalStates ( ).contains ( state ) ) return true; for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & transition : automaton.getTransitions ( ) ) @@ -664,7 +664,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::NFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** @@ -695,7 +695,7 @@ public: * \returns true if the state is already in the set of states of the automaton */ static bool available ( const automaton::NFA < SymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state ); } /** -- GitLab