tgba_digraph: add a purge_dead_states() method

* src/tgba/tgbagraph.hh, src/tgba/tgbagraph.cc (purge_dead_states): New.
* src/graph/graph.hh (defrag_states): New methods.
* src/tgbaalgos/dtgbacomp.cc: Use it.
* src/tgbatest/det.test: Fix state number.
This commit is contained in:
Alexandre Duret-Lutz 2014-10-24 00:37:18 +02:00
parent 63708ddcc7
commit 2553c29ca7
5 changed files with 117 additions and 10 deletions

View file

@ -273,8 +273,7 @@ namespace spot
killer_trans_iterator operator++(int)
{
killer_trans_iterator ti = *this;
prev_ = this->t_;
this->t_ = this->operator*().next_succ;
++*this;
return ti;
}
@ -302,7 +301,7 @@ namespace spot
// Erased transitions have themselves as next_succ.
this->operator*().next_succ = this->t_;
// Advance iterator to next transitions.
// Advance iterator to next transition.
this->t_ = next;
++this->g_->killed_trans_;
@ -647,6 +646,57 @@ namespace spot
}
}
void defrag_states(std::vector<unsigned>&& newst, unsigned used_states)
{
assert(newst.size() == states_.size());
assert(used_states > 0);
// Shift all states in states_, as indicated by newst.
unsigned send = states_.size();
for (state s = 0; s < send; ++s)
{
state dst = newst[s];
if (dst == s || dst == -1U)
continue;
states_[dst] = std::move(states_[s]);
}
states_.resize(used_states);
// Shift all transitions in transitions_. The algorithm is
// similar to remove_if, but it also keeps the correspondence
// between the old and new index as newidx[old] = new.
unsigned tend = transitions_.size();
std::vector<transition> newidx(tend);
unsigned dest = 1;
for (transition t = 1; t < tend; ++t)
{
if (is_dead_transition(t))
continue;
if (t != dest)
transitions_[dest] = std::move(transitions_[t]);
newidx[t] = dest;
++dest;
}
transitions_.resize(dest);
killed_trans_ = 0;
// Adjust next_succ and dst pointers in all transitions.
for (transition t = 1; t < dest; ++t)
{
auto& tr = transitions_[t];
tr.next_succ = newidx[tr.next_succ];
tr.dst = newst[tr.dst];
assert(tr.dst != -1U);
}
// Adjust succ and succ_tails pointers in all states.
for (auto& s: states_)
{
s.succ = newidx[s.succ];
s.succ_tail = newidx[s.succ_tail];
}
}
};
}