* src/tgba/state.hh (state::hash): New method.
(state_ptr_equal, state_ptr_hash): New functors. * src/tgba/statebdd.hh, src/tgba/statebdd.cc (state_bdd::hash): New method. * src/tgba/tgbaexplicit.hh, src/tgba/tgbaexplicit.cc (state_explicit::hash): New method. (ns_map, sn_map): Use Sgi::hash_map instead of std::map. * src/tgba/tgbaproduct.hh, src/tgba/tgbaproduct.cc (state_product::hash): New method. * src/tgba/tgbatba.cc (state_tba_proxy::hash): New method. * src/tgbaalgos/lbtt.cc (acp_seen, todo_set, seen_map): Redefine using Sgi::hash_map or Sgi::hash_set. (lbtt_reachable): Don't erase a key that is pointed to by an iterator. * src/tgbaalgos/reachiter.cc (tgba_reachable_iterator::~tgba_reachable_iterator): Likewise. * src/tgbaalgos/magic.cc (magic_search::~magic_search()): Likewise. * src/tgbaalgos/magic.hh (hash_type): Redefine using Sgi::hash_map. * src/tgbaalgos/reachiter.hh (seen_map): Redefine using Sgi::hash_map. * iface/gspn/gspn.cc (state_gspn::hash): New method. * src/misc/hash.hh (string_hash): New functor.
This commit is contained in:
parent
6da1f35641
commit
f0de38680a
16 changed files with 201 additions and 26 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include "misc/hash.hh"
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
|
@ -86,30 +87,41 @@ namespace spot
|
|||
|
||||
typedef std::pair<state*, bdd> state_acc_pair;
|
||||
|
||||
struct state_acc_pair_less_than
|
||||
struct state_acc_pair_equal
|
||||
{
|
||||
bool
|
||||
operator()(const state_acc_pair& left, const state_acc_pair& right) const
|
||||
{
|
||||
int cmp = left.first->compare(right.first);
|
||||
if (cmp < 0)
|
||||
return true;
|
||||
if (cmp > 0)
|
||||
if (left.first->compare(right.first))
|
||||
return false;
|
||||
return left.second.id() < right.second.id();
|
||||
return left.second.id() == right.second.id();
|
||||
}
|
||||
};
|
||||
|
||||
struct state_acc_pair_hash
|
||||
{
|
||||
bool
|
||||
operator()(const state_acc_pair& that) const
|
||||
{
|
||||
// We assume there will be far more states than accepting conditions.
|
||||
// Hence we keep only 8 bits for the latter.
|
||||
return (that.first->hash() << 8) + (that.second.id() & 0xFF);
|
||||
}
|
||||
};
|
||||
|
||||
// Each state of the produced automata is numbered. Map of state seen.
|
||||
typedef std::map<state_acc_pair, unsigned, state_acc_pair_less_than> acp_seen_map;
|
||||
typedef Sgi::hash_map<state_acc_pair, unsigned, state_acc_pair_hash,
|
||||
state_acc_pair_equal> acp_seen_map;
|
||||
|
||||
// Set of states yet to produce.
|
||||
typedef std::set<state_acc_pair, state_acc_pair_less_than> todo_set;
|
||||
typedef Sgi::hash_set<state_acc_pair, state_acc_pair_hash,
|
||||
state_acc_pair_equal> todo_set;
|
||||
|
||||
// Each *source* state corresponds to several states in the produced
|
||||
// automata. A minmax_pair specifies the range of such associated states.
|
||||
typedef std::pair<unsigned, unsigned> minmax_pair;
|
||||
typedef std::map<state*, minmax_pair, state_ptr_less_than> seen_map;
|
||||
typedef Sgi::hash_map<state*, minmax_pair,
|
||||
state_ptr_hash, state_ptr_equal> seen_map;
|
||||
|
||||
// Take a STATE from the source automaton, and fill TODO with
|
||||
// the list of associated states to output. Return the correponding
|
||||
|
|
@ -230,8 +242,14 @@ namespace spot
|
|||
os << state_number << " " << acs.count() << std::endl;
|
||||
os << body.str();
|
||||
// Finally delete all states used as keys in m.
|
||||
for (seen_map::iterator i = seen.begin(); i != seen.end(); ++i)
|
||||
delete i->first;
|
||||
seen_map::const_iterator s = seen.begin();
|
||||
while (s != seen.end())
|
||||
{
|
||||
// Advance the iterator before deleting the "key" pointer.
|
||||
const state* ptr = s->first;
|
||||
++s;
|
||||
delete ptr;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,14 @@ namespace spot
|
|||
|
||||
magic_search::~magic_search()
|
||||
{
|
||||
for (hash_type::iterator i = h.begin(); i != h.end(); ++i)
|
||||
delete i->first;
|
||||
hash_type::const_iterator s = h.begin();
|
||||
while (s != h.end())
|
||||
{
|
||||
// Advance the iterator before deleting the "key" pointer.
|
||||
const state* ptr = s->first;
|
||||
++s;
|
||||
delete ptr;
|
||||
}
|
||||
if (x)
|
||||
delete x;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPOT_TGBAALGOS_MAGIC_HH
|
||||
# define SPOT_TGBAALGOS_MAGIC_HH
|
||||
|
||||
#include "misc/hash.hh"
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
|
|
@ -82,8 +83,8 @@ namespace spot
|
|||
/// This is an addition to the data from the paper.
|
||||
tstack_type tstack;
|
||||
|
||||
// FIXME: use a hash_map.
|
||||
typedef std::map<const state*, magic, state_ptr_less_than> hash_type;
|
||||
typedef Sgi::hash_map<const state*, magic,
|
||||
state_ptr_hash, state_ptr_equal> hash_type;
|
||||
hash_type h; ///< Map of visited states.
|
||||
|
||||
/// Append a new state to the current path.
|
||||
|
|
|
|||
|
|
@ -13,8 +13,14 @@ namespace spot
|
|||
|
||||
tgba_reachable_iterator::~tgba_reachable_iterator()
|
||||
{
|
||||
for (seen_map::const_iterator s = seen.begin(); s != seen.end(); ++s)
|
||||
delete s->first;
|
||||
seen_map::const_iterator s = seen.begin();
|
||||
while (s != seen.end())
|
||||
{
|
||||
// Advance the iterator before deleting the "key" pointer.
|
||||
const state* ptr = s->first;
|
||||
++s;
|
||||
delete ptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ namespace spot
|
|||
protected:
|
||||
const tgba* automata_; ///< The spot::tgba to explore.
|
||||
|
||||
typedef std::map<const state*, int, state_ptr_less_than> seen_map;
|
||||
typedef Sgi::hash_map<const state*, int,
|
||||
state_ptr_hash, state_ptr_equal> seen_map;
|
||||
seen_map seen; ///< States already seen.
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue