Changeset View
Changeset View
Standalone View
Standalone View
src/util/hasher.h
Show All 33 Lines | |||||
private: | private: | ||||
/** Salt */ | /** Salt */ | ||||
const uint64_t k0, k1; | const uint64_t k0, k1; | ||||
public: | public: | ||||
SaltedOutpointHasher(); | SaltedOutpointHasher(); | ||||
/** | /** | ||||
* This *must* return size_t. With Boost 1.46 on 32-bit systems the | |||||
* unordered_map will behave unpredictably if the custom hasher returns a | |||||
* uint64_t, resulting in failures when syncing the chain (#4634). | |||||
* Note: This information above might be outdated as the unordered map | |||||
* container type has meanwhile been switched to the C++ standard library | |||||
* implementation. | |||||
* | |||||
* Having the hash noexcept allows libstdc++'s unordered_map to recalculate | * Having the hash noexcept allows libstdc++'s unordered_map to recalculate | ||||
* the hash during rehash, so it does not have to cache the value. This | * the hash during rehash, so it does not have to cache the value. This | ||||
* reduces node's memory by sizeof(size_t). The required recalculation has | * reduces node's memory by sizeof(size_t). The required recalculation has | ||||
* a slight performance penalty (around 1.6%), but this is compensated by | * a slight performance penalty (around 1.6%), but this is compensated by | ||||
* memory savings of about 9% which allow for a larger dbcache setting. | * memory savings of about 9% which allow for a larger dbcache setting. | ||||
* | * | ||||
* @see | * @see | ||||
* https://gcc.gnu.org/onlinedocs/gcc-9.2.0/libstdc++/manual/manual/unordered_associative.html | * https://gcc.gnu.org/onlinedocs/gcc-9.2.0/libstdc++/manual/manual/unordered_associative.html | ||||
Show All 36 Lines | struct BlockHasher { | ||||
// this used to call `GetCheapHash()` in uint256, which was later moved; the | // this used to call `GetCheapHash()` in uint256, which was later moved; the | ||||
// cheap hash function simply calls ReadLE64() however, so the end result is | // cheap hash function simply calls ReadLE64() however, so the end result is | ||||
// identical | // identical | ||||
size_t operator()(const BlockHash &hash) const { | size_t operator()(const BlockHash &hash) const { | ||||
return ReadLE64(hash.begin()); | return ReadLE64(hash.begin()); | ||||
} | } | ||||
}; | }; | ||||
class SaltedSipHasher { | |||||
private: | |||||
/** Salt */ | |||||
const uint64_t m_k0, m_k1; | |||||
public: | |||||
SaltedSipHasher(); | |||||
size_t operator()(const Span<const uint8_t> &script) const; | |||||
}; | |||||
#endif // BITCOIN_UTIL_HASHER_H | #endif // BITCOIN_UTIL_HASHER_H |