From d0faa2b676130119c5d01e00851427fa97f44464 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Mon, 2 Oct 2017 22:48:00 -0700 Subject: Unify hash functions for pairs (#1161) CVC4 was implementing multiple, slightly different hash functions for pairs. With pull request #1157, we have a decent generic hash function for pairs. This commit replaces the existing hash function implementations with a typedef of the generic hash function. --- src/theory/ite_utilities.h | 11 +++-------- src/theory/theory_engine.h | 4 +++- src/theory/uf/equality_engine_types.h | 18 +++++++++--------- 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'src/theory') diff --git a/src/theory/ite_utilities.h b/src/theory/ite_utilities.h index 4aad9a3f0..096393de2 100644 --- a/src/theory/ite_utilities.h +++ b/src/theory/ite_utilities.h @@ -26,6 +26,7 @@ #include #include "expr/node.h" +#include "util/hash.h" #include "util/statistics_registry.h" namespace CVC4 { @@ -240,14 +241,8 @@ private: uint32_t d_citeEqConstApplications; typedef std::pair NodePair; - struct NodePairHashFunction { - size_t operator () (const NodePair& pair) const { - size_t hash = 0; - hash = 0x9e3779b9 + NodeHashFunction().operator()(pair.first); - hash ^= 0x9e3779b9 + NodeHashFunction().operator()(pair.second) + (hash << 6) + (hash >> 2); - return hash; - } - };/* struct ITESimplifier::NodePairHashFunction */ + using NodePairHashFunction = + PairHashFunction; typedef std::unordered_map NodePairMap; NodePairMap d_constantIteEqualsConstantCache; NodePairMap d_replaceOverCache; diff --git a/src/theory/theory_engine.h b/src/theory/theory_engine.h index 3ae0b840b..a897f9456 100644 --- a/src/theory/theory_engine.h +++ b/src/theory/theory_engine.h @@ -44,6 +44,7 @@ #include "theory/theory.h" #include "theory/uf/equality_engine.h" #include "theory/valuation.h" +#include "util/hash.h" #include "util/statistics_registry.h" #include "util/unsafe_interrupt_exception.h" @@ -74,7 +75,8 @@ struct NodeTheoryPairHashFunction { NodeHashFunction hashFunction; // Hash doesn't take into account the timestamp size_t operator()(const NodeTheoryPair& pair) const { - return hashFunction(pair.node)*0x9e3779b9 + pair.theory; + uint64_t hash = fnv1a::fnv1a_64(NodeHashFunction()(pair.node)); + return static_cast(fnv1a::fnv1a_64(pair.theory, hash)); } };/* struct NodeTheoryPairHashFunction */ diff --git a/src/theory/uf/equality_engine_types.h b/src/theory/uf/equality_engine_types.h index ed0afa904..b3b8ac7d6 100644 --- a/src/theory/uf/equality_engine_types.h +++ b/src/theory/uf/equality_engine_types.h @@ -17,10 +17,15 @@ #include "cvc4_private.h" +#ifndef __CVC4__THEORY__UF__EQUALITY_ENGINE_TYPES_H +#define __CVC4__THEORY__UF__EQUALITY_ENGINE_TYPES_H + #include #include #include +#include "util/hash.h" + namespace CVC4 { namespace theory { namespace eq { @@ -264,15 +269,8 @@ public: /** A pair of ids */ typedef std::pair EqualityPair; - -struct EqualityPairHashFunction { - size_t operator () (const EqualityPair& pair) const { - size_t hash = 0; - hash = 0x9e3779b9 + pair.first; - hash ^= 0x9e3779b9 + pair.second + (hash << 6) + (hash >> 2); - return hash; - } -}; +using EqualityPairHashFunction = + PairHashFunction; enum FunctionApplicationType { /** This application is an equality a = b */ @@ -362,3 +360,5 @@ struct TriggerInfo { } // namespace eq } // namespace theory } // namespace CVC4 + +#endif /* __CVC4__THEORY__UF__EQUALITY_ENGINE_TYPES_H */ -- cgit v1.2.3