* 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,6 +1,7 @@
|
|||
#ifndef SPOT_TGBA_STATE_HH
|
||||
# define SPOT_TGBA_STATE_HH
|
||||
|
||||
#include <cstddef>
|
||||
#include <bdd.h>
|
||||
|
||||
namespace spot
|
||||
|
|
@ -22,6 +23,27 @@ namespace spot
|
|||
/// \sa spot::state_ptr_less_than
|
||||
virtual int compare(const state* other) const = 0;
|
||||
|
||||
/// \brief Hash a state.
|
||||
///
|
||||
/// This method returns an integer that can be used as a
|
||||
/// hash value for this state.
|
||||
///
|
||||
/// Note that the hash value is guaranteed to be unique for all
|
||||
/// equal states (in compare()'s sense) for only has long has one
|
||||
/// of these states exists. So it's OK to use a spot::state as a
|
||||
/// key in a \c hash_map because the mere use of the state as a
|
||||
/// key in the hash will ensure the state continues to exist.
|
||||
///
|
||||
/// However if you create the state, get its hash key, delete the
|
||||
/// state, recreate the same state, and get its hash key, you may
|
||||
/// obtain two different hash keys if the same state were not
|
||||
/// already used elsewhere. In practice this weird situation can
|
||||
/// occur only when the state is BDD-encoded, because BDD numbers
|
||||
/// (used to build the hash value) can be reused for other
|
||||
/// formulas. That probably doesn't matter, since the hash value
|
||||
/// is meant to be used in a \c hash_map, but it had to be noted.
|
||||
virtual size_t hash() const = 0;
|
||||
|
||||
/// Duplicate a state.
|
||||
virtual state* clone() const = 0;
|
||||
|
||||
|
|
@ -51,6 +73,50 @@ namespace spot
|
|||
}
|
||||
};
|
||||
|
||||
/// \brief An Equivalence Relation for \c state*.
|
||||
///
|
||||
/// This is meant to be used as a comparison functor for
|
||||
/// Sgi \c hash_map whose key are of type \c state*.
|
||||
///
|
||||
/// For instance here is how one could declare
|
||||
/// a map of \c state*.
|
||||
/// \code
|
||||
/// // Remember how many times each state has been visited.
|
||||
/// Sgi::hash_map<spot::state*, int, spot::state_ptr_less_than,
|
||||
/// spot::state_ptr_equal> seen;
|
||||
/// \endcode
|
||||
struct state_ptr_equal
|
||||
{
|
||||
bool
|
||||
operator()(const state* left, const state* right) const
|
||||
{
|
||||
assert(left);
|
||||
return 0 == left->compare(right);
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Hash Function for \c state*.
|
||||
///
|
||||
/// This is meant to be used as a hash functor for
|
||||
/// Sgi's \c hash_map whose key are of type \c state*.
|
||||
///
|
||||
/// For instance here is how one could declare
|
||||
/// a map of \c state*.
|
||||
/// \code
|
||||
/// // Remember how many times each state has been visited.
|
||||
/// Sgi::hash_map<spot::state*, int, spot::state_ptr_less_than,
|
||||
/// spot::state_ptr_equal> seen;
|
||||
/// \endcode
|
||||
struct state_ptr_hash
|
||||
{
|
||||
size_t
|
||||
operator()(const state* that) const
|
||||
{
|
||||
assert(that);
|
||||
return that->hash();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SPOT_TGBA_STATE_HH
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue