diff --git a/src/solvers/bdd/miniBDD/miniBDD.cpp b/src/solvers/bdd/miniBDD/miniBDD.cpp index bd7c3faf268..7557edd84bc 100644 --- a/src/solvers/bdd/miniBDD/miniBDD.cpp +++ b/src/solvers/bdd/miniBDD/miniBDD.cpp @@ -17,6 +17,16 @@ Author: Daniel Kroening, kroening@kroening.com #include +/// Combine \p value into the hash \p seed of the values so far: multiply +/// the seed by an odd constant, then add the next value. 0x9e3779b1 +/// (2654435761) is the prime closest to 2^32 / phi, a common multiplier in +/// multiplicative hashing (Knuth, TAOCP vol. 3, section 6.4). +/// \return The combined hash +static std::size_t combine_hash(std::size_t seed, unsigned value) +{ + return seed * 0x9e3779b1 + value; +} + void mini_bdd_nodet::remove_reference() { PRECONDITION_WITH_DIAGNOSTICS( @@ -198,7 +208,20 @@ class mini_bdd_applyt mini_bddt APP_rec(const mini_bddt &x, const mini_bddt &y); mini_bddt APP_non_rec(const mini_bddt &x, const mini_bddt &y); - typedef std::map, mini_bddt> Gt; + /// Hash of a pair of node numbers, the key of the computed table + struct node_pair_hasht + { + std::size_t operator()(const std::pair &key) const + { + return combine_hash(key.first, key.second); + } + }; + + // Computed table: the result for each pair of node numbers. It is + // consulted at every step, so it is a hash table rather than a tree. + typedef std:: + unordered_map, mini_bddt, node_pair_hasht> + Gt; Gt G; }; @@ -475,14 +498,7 @@ bool mini_bdd_mgrt::reverse_keyt::operator==( std::size_t mini_bdd_mgrt::reverse_key_hasht::operator()( const mini_bdd_mgrt::reverse_keyt &key) const { - // Mix var, low and high into one value: multiply the value so far by an - // odd constant, then add the next component. 0x9e3779b1 (2654435761) is - // the prime closest to 2^32 / phi, a common multiplier in multiplicative - // hashing (Knuth, TAOCP vol. 3, section 6.4). - std::size_t h = key.var; - h = h * 0x9e3779b1 + key.low; - h = h * 0x9e3779b1 + key.high; - return h; + return combine_hash(combine_hash(key.var, key.low), key.high); } void mini_bdd_mgrt::DumpTable(std::ostream &out) const