mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-30 18:51:15 +02:00
Add generic SaltedSipHasher
SaltedSipHasher is a generic hasher that can be used with most things we would hash in an unordered container.
This commit is contained in:
@ -10,3 +10,10 @@
|
|||||||
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
||||||
|
|
||||||
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
||||||
|
|
||||||
|
SaltedSipHasher::SaltedSipHasher() : m_k0(GetRand(std::numeric_limits<uint64_t>::max())), m_k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
||||||
|
|
||||||
|
size_t SaltedSipHasher::operator()(const Span<const unsigned char>& script) const
|
||||||
|
{
|
||||||
|
return CSipHasher(m_k0, m_k1).Write(script.data(), script.size()).Finalize();
|
||||||
|
}
|
||||||
|
@ -84,4 +84,16 @@ struct BlockHasher
|
|||||||
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
|
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SaltedSipHasher
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/** Salt */
|
||||||
|
const uint64_t m_k0, m_k1;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SaltedSipHasher();
|
||||||
|
|
||||||
|
size_t operator()(const Span<const unsigned char>& script) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_HASHER_H
|
#endif // BITCOIN_UTIL_HASHER_H
|
||||||
|
Reference in New Issue
Block a user