* src/ltlast/formula.hh (hash, dump, dump_, hash_key_): New members.

(formula_ptr_less_than, formula_ptr_hash): New class.
* src/ltlast/atomic_prop.cc, src/ltlast/binop.cc,
src/ltlast/constant.cc, src/ltlast/formula.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc: Adjust to handle dump_.
* src/ltlvisit/apcollect.cc, src/ltlvisit/apcollect.hh:
Sort the set using formula_ptr_less_than.
* src/ltlvisit/dump.cc: Simplify using ->dump().
* src/tgbaalgos/ltl2tgba_fm.cc: Sort all maps to get deterministic
results.
This commit is contained in:
Alexandre Duret-Lutz 2005-01-20 17:33:55 +00:00
parent 8a5e31f00e
commit 5069a565b6
12 changed files with 153 additions and 82 deletions

View file

@ -24,6 +24,8 @@
#ifndef SPOT_LTLAST_FORMULA_HH
# define SPOT_LTLAST_FORMULA_HH
#include <string>
#include <cassert>
#include "predecl.hh"
namespace spot
@ -89,6 +91,15 @@ namespace spot
/// want to release a whole formula, use spot::ltl::destroy() instead.
static void unref(formula* f);
/// Return a canonic representation of the formula
const std::string& dump() const;
/// Return a hash_key for the formula.
const size_t
hash() const
{
return hash_key_;
}
protected:
virtual ~formula();
@ -97,8 +108,70 @@ namespace spot
/// \brief decrement reference counter if any, return true when
/// the instance must be deleted (usually when the counter hits 0).
virtual bool unref_();
/// \brief Compute key_ from dump_.
///
/// Should be called once in each object, after dump_ has been set.
void set_key_();
/// The canonic representation of the formula
std::string dump_;
/// \brief The hash key of this formula.
///
/// Initialized by set_key_().
size_t hash_key_;
};
/// \brief Strict Weak Ordering for <code>const formula*</code>.
/// \ingroup ltl_essentials
///
/// This is meant to be used as a comparison functor for
/// STL \c map whose key are of type <code>const formula*</code>.
///
/// For instance here is how one could declare
/// a map of \c const::formula*.
/// \code
/// // Remember how many times each formula has been seen.
/// std::map<const spot::ltl::formula*, int,
/// spot::formula_ptr_less_than> seen;
/// \endcode
struct formula_ptr_less_than:
public std::binary_function<const formula*, const formula*, bool>
{
bool
operator()(const formula* left, const formula* right) const
{
assert(left);
assert(right);
return left->hash() < right->hash();
}
};
/// \brief Hash Function for <code>const formula*</code>.
/// \ingroup ltl_essentials
/// \ingroup hash_funcs
///
/// This is meant to be used as a hash functor for
/// Sgi's \c hash_map whose key are of type <code>const formula*</code>.
///
/// For instance here is how one could declare
/// a map of \c const::formula*.
/// \code
/// // Remember how many times each formula has been seen.
/// Sgi::hash_map<const spot::ltl::formula*, int,
/// const spot::ltl::formula_ptr_hash> seen;
/// \endcode
struct formula_ptr_hash:
public std::unary_function<const formula*, size_t>
{
size_t
operator()(const formula* that) const
{
assert(that);
return that->hash();
}
};
}
}