From 59a2763f413b84b3fa1c3efd8947b0556e605cc9 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Tue, 5 Jun 2012 08:05:18 +0200 Subject: [PATCH] * src/tgbaalgos/degen.cc (outgoing_acc): Fill both caches at once. --- src/tgbaalgos/degen.cc | 62 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/tgbaalgos/degen.cc b/src/tgbaalgos/degen.cc index f3a9010a8..b5872ac68 100644 --- a/src/tgbaalgos/degen.cc +++ b/src/tgbaalgos/degen.cc @@ -97,50 +97,48 @@ namespace spot class outgoing_acc { const tgba* a_; - typedef Sgi::hash_map accmap_t; - mutable accmap_t accmap_; - mutable accmap_t accmapu_; + typedef std::pair cache_entry; + typedef Sgi::hash_map cache_t; + cache_t cache_; public: outgoing_acc(const tgba* a): a_(a) { } - bdd common_acc(const state* s) + cache_t::const_iterator fill_cache(const state* s) { - // Lookup cache - accmap_t::const_iterator i = accmap_.find(s); - if (i != accmap_.end()) - return i->second; - bdd common = a_->all_acceptance_conditions(); - tgba_succ_iterator* it = a_->succ_iter(s); - for (it->first(); !it->done() && common != bddfalse; it->next()) - common &= it->current_acceptance_conditions(); - delete it; - - // Populate cache - accmap_[s->clone()] = common; - return common; - } - - bdd union_acc(const state* s) - { - // Lookup cache - accmap_t::const_iterator i = accmapu_.find(s); - if (i != accmapu_.end()) - return i->second; - - bdd common = bddfalse; + bdd union_ = bddfalse; tgba_succ_iterator* it = a_->succ_iter(s); for (it->first(); !it->done(); it->next()) - common |= it->current_acceptance_conditions(); + { + bdd set = it->current_acceptance_conditions(); + common &= set; + union_ |= set; + } delete it; + cache_entry e(common, union_); + return cache_.insert(std::make_pair(s, e)).first; + } - // Populate cache - accmapu_[s->clone()] = common; - return common; + // Intersection of all outgoing acceptance sets + bdd common_acc(const state* s) + { + cache_t::const_iterator i = cache_.find(s); + if (i == cache_.end()) + i = fill_cache(s); + return i->second.first; + } + + // Union of all outgoing acceptance sets + bdd union_acc(const state* s) + { + cache_t::const_iterator i = cache_.find(s); + if (i == cache_.end()) + i = fill_cache(s); + return i->second.second; } }; }