size_t SequenceHashFunction::operator()(const Sequence& s) const
{
- size_t ret = 0;
+ uint64_t ret = fnv1a::offsetBasis;
const std::vector<Node>& vec = s.getVec();
for (const Node& n : vec)
{
ret = fnv1a::fnv1a_64(ret, std::hash<Node>()(n));
}
- return ret;
+ return static_cast<size_t>(ret);
}
} // namespace cvc5
namespace fnv1a {
+constexpr uint64_t offsetBasis = 14695981039346656037U;
+
/**
* FNV-1a hash algorithm for 64-bit numbers.
*
* More details here: http://www.isthe.com/chongo/tech/comp/fnv/index.html
*/
-inline uint64_t fnv1a_64(uint64_t v, uint64_t hash = 14695981039346656037U) {
+inline uint64_t fnv1a_64(uint64_t v, uint64_t hash = offsetBasis)
+{
hash ^= v;
// Compute (hash * 1099511628211)
return hash + (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) +
#include "base/check.h"
#include "base/exception.h"
+#include "util/hash.h"
using namespace std;
return Rational(toString());
}
+namespace strings {
+
+size_t StringHashFunction::operator()(const ::cvc5::String& s) const
+{
+ uint64_t ret = fnv1a::offsetBasis;
+ for (unsigned c : s.d_str)
+ {
+ ret = fnv1a::fnv1a_64(c, ret);
+ }
+ return static_cast<size_t>(ret);
+}
+
+} // namespace strings
+
std::ostream &operator<<(std::ostream &os, const String &s) {
return os << "\"" << s.toString() << "\"";
}
namespace cvc5 {
+namespace strings {
+struct StringHashFunction;
+}
+
/** The cvc5 string class
*
* This data structure is the domain of values for the string type. It can also
*/
class String
{
+ friend strings::StringHashFunction;
+
public:
/**
* This is the cardinality of the alphabet that is representable by this
struct StringHashFunction
{
- size_t operator()(const ::cvc5::String& s) const
- {
- return std::hash<std::string>()(s.toString());
- }
+ size_t operator()(const ::cvc5::String& s) const;
}; /* struct StringHashFunction */
} // namespace strings