graph: Add a is_dead_transition method.

* src/graph/graph.hh, src/tgba/tgbagraph.hh (is_dead_transition): New
method.
This commit is contained in:
Alexandre Duret-Lutz 2014-08-20 16:09:53 +02:00
parent 73e74c0ad3
commit d28e7f9c5c
2 changed files with 18 additions and 3 deletions

View file

@ -151,6 +151,7 @@ namespace spot
State dst; // destination State dst; // destination
Transition next_succ; // next outgoing transition with same Transition next_succ; // next outgoing transition with same
// source, or 0 // source, or 0
explicit trans_storage() explicit trans_storage()
: Trans_Data{} : Trans_Data{}
{ {
@ -530,13 +531,13 @@ namespace spot
return t; return t;
} }
state index_of_state(state_storage_t& ss) state index_of_state(const state_storage_t& ss) const
{ {
assert(!states_.empty()); assert(!states_.empty());
return &ss - &states_.front(); return &ss - &states_.front();
} }
transition index_of_transition(trans_storage_t& tt) transition index_of_transition(const trans_storage_t& tt) const
{ {
assert(!transitions_.empty()); assert(!transitions_.empty());
return &tt - &transitions_.front(); return &tt - &transitions_.front();
@ -598,6 +599,16 @@ namespace spot
return transitions_; return transitions_;
} }
bool is_dead_transition(unsigned t) const
{
return transitions_[t].next_succ == t;
}
bool is_dead_transition(trans_storage_t& t) const
{
return t.next_succ == index_of_transition(t);
}
void defrag() void defrag()
{ {
if (killed_trans_ == 0) // Nothing to do. if (killed_trans_ == 0) // Nothing to do.
@ -611,7 +622,7 @@ namespace spot
unsigned dest = 1; unsigned dest = 1;
for (transition t = 1; t < tend; ++t) for (transition t = 1; t < tend; ++t)
{ {
if (transitions_[t].next_succ == t) if (is_dead_transition(t))
continue; continue;
if (t != dest) if (t != dest)
transitions_[dest] = std::move(transitions_[t]); transitions_[dest] = std::move(transitions_[t]);

View file

@ -357,6 +357,10 @@ namespace spot
auto transitions() auto transitions()
SPOT_RETURN(g_.transitions()); SPOT_RETURN(g_.transitions());
template<typename T>
auto is_dead_transition(T t) const
SPOT_RETURN(g_.is_dead_transition(t));
/// \brief Copy the acceptance conditions of another tgba. /// \brief Copy the acceptance conditions of another tgba.
void copy_acceptance_conditions_of(const const_tgba_ptr& a) void copy_acceptance_conditions_of(const const_tgba_ptr& a)
{ {