* 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

@ -1,4 +1,4 @@
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -32,6 +32,8 @@ namespace spot
atomic_prop::atomic_prop(const std::string& name, environment& env)
: name_(name), env_(&env)
{
dump_ = "AP(" + name + ")";
set_key_();
}
atomic_prop::~atomic_prop()

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -31,6 +31,10 @@ namespace spot
binop::binop(type op, formula* first, formula* second)
: op_(op), first_(first), second_(second)
{
dump_ = "binop(";
dump_ += op_name();
dump_ += ", " + first->dump() + ", " + second->dump() + ")";
set_key_();
}
binop::~binop()

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -30,6 +30,19 @@ namespace spot
constant::constant(type val)
: val_(val)
{
switch (val)
{
case True:
dump_ = "constant(1)";
set_key_();
return;
case False:
dump_ = "constant(0)";
set_key_();
return;
}
// Unreachable code.
assert(0);
}
constant::~constant()

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -20,6 +20,7 @@
// 02111-1307, USA.
#include "formula.hh"
#include "misc/hash.hh"
namespace spot
{
@ -55,5 +56,19 @@ namespace spot
// Not reference counted by default.
return false;
}
const std::string&
formula::dump() const
{
return dump_;
}
void
formula::set_key_()
{
string_hash sh;
hash_key_ = sh(dump_);
}
}
}

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();
}
};
}
}

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -34,6 +34,15 @@ namespace spot
multop::multop(type op, vec* v)
: op_(op), children_(v)
{
dump_ = "multop(";
dump_ += op_name();
unsigned max = v->size();
for (unsigned n = 0; n < max; ++n)
{
dump_ += ", " + (*v)[n]->dump();
}
dump_ += ")";
set_key_();
}
multop::~multop()
@ -131,7 +140,7 @@ namespace spot
v->insert(v->end(), inlined.begin(), inlined.end());
}
std::sort(v->begin(), v->end());
std::sort(v->begin(), v->end(), formula_ptr_less_than());
// Remove duplicates. We can't use std::unique(), because we
// must destroy() any formula we drop.

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -30,6 +30,10 @@ namespace spot
unop::unop(type op, formula* child)
: op_(op), child_(child)
{
dump_ = "unop(";
dump_ += op_name();
dump_ += ", " + child->dump() + ")";
set_key_();
}
unop::~unop()