Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andres Noetzli, Morgan Deters, Aina Niemetz 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 by the authors listed in the file AUTHORS 8 : : * in the top-level source directory and their institutional affiliations. 9 : : * All rights reserved. See the file COPYING in the top-level source 10 : : * directory for licensing information. 11 : : * **************************************************************************** 12 : : * 13 : : * cvc5 hash utilities. 14 : : */ 15 : : 16 : : #include "cvc5_public.h" 17 : : 18 : : #ifndef CVC5__HASH_H 19 : : #define CVC5__HASH_H 20 : : 21 : : #include <functional> 22 : : #include <string> 23 : : 24 : : namespace std { 25 : : 26 : : #ifdef CVC5_NEED_HASH_UINT64_T 27 : : // on some versions and architectures of GNU C++, we need a 28 : : // specialization of hash for 64-bit values 29 : : template <> 30 : : struct hash<uint64_t> { 31 : : size_t operator()(uint64_t v) const { 32 : : return v; 33 : : } 34 : : };/* struct hash<uint64_t> */ 35 : : #endif /* CVC5_NEED_HASH_UINT64_T */ 36 : : 37 : : }/* std namespace */ 38 : : 39 : : namespace cvc5::internal { 40 : : 41 : : namespace fnv1a { 42 : : 43 : : constexpr uint64_t offsetBasis = 14695981039346656037U; 44 : : 45 : : /** 46 : : * FNV-1a hash algorithm for 64-bit numbers. 47 : : * 48 : : * More details here: http://www.isthe.com/chongo/tech/comp/fnv/index.html 49 : : */ 50 : 1428240000 : inline uint64_t fnv1a_64(uint64_t v, uint64_t hash = offsetBasis) 51 : : { 52 : 1428240000 : hash ^= v; 53 : : // Compute (hash * 1099511628211) 54 : 1428240000 : return hash + (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) + 55 : 1428240000 : (hash << 8) + (hash << 40); 56 : : } 57 : : 58 : : } // namespace fnv1a 59 : : 60 : : template <class T, class U, class HashT = std::hash<T>, class HashU = std::hash<U> > 61 : : struct PairHashFunction { 62 : 460970539 : size_t operator()(const std::pair<T, U>& pr) const { 63 : 460970539 : uint64_t hash = fnv1a::fnv1a_64(HashT()(pr.first)); 64 : 460970539 : return static_cast<size_t>(fnv1a::fnv1a_64(HashU()(pr.second), hash)); 65 : : } 66 : : };/* struct PairHashFunction */ 67 : : 68 : : } // namespace cvc5::internal 69 : : 70 : : #endif /* CVC5__HASH_H */