Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions src/solvers/bdd/miniBDD/miniBDD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Author: Daniel Kroening, kroening@kroening.com

#include <iostream>

/// 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(
Expand Down Expand Up @@ -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<std::pair<unsigned, unsigned>, 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<unsigned, unsigned> &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<std::pair<unsigned, unsigned>, mini_bddt, node_pair_hasht>
Gt;
Gt G;
};

Expand Down Expand Up @@ -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
Expand Down
Loading