mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 22:57:56 +02:00
optimization: migrate SipHashUint256 to PresaltedSipHasher
Replaces standalone `SipHashUint256` with an `operator()` overload in `PresaltedSipHasher`. Updates all hasher classes (`SaltedUint256Hasher`, `SaltedTxidHasher`, `SaltedWtxidHasher`) to use `PresaltedSipHasher` internally, enabling the same constant-state caching optimization while keeping behavior unchanged. Benchmark was also adjusted to cache the salting part.
This commit is contained in:
@@ -7,17 +7,20 @@
|
||||
#include <span.h>
|
||||
#include <util/hasher.h>
|
||||
|
||||
SaltedUint256Hasher::SaltedUint256Hasher() :
|
||||
k0{FastRandomContext().rand64()},
|
||||
k1{FastRandomContext().rand64()} {}
|
||||
SaltedUint256Hasher::SaltedUint256Hasher() : m_hasher{
|
||||
FastRandomContext().rand64(),
|
||||
FastRandomContext().rand64()}
|
||||
{}
|
||||
|
||||
SaltedTxidHasher::SaltedTxidHasher() :
|
||||
k0{FastRandomContext().rand64()},
|
||||
k1{FastRandomContext().rand64()} {}
|
||||
SaltedTxidHasher::SaltedTxidHasher() : m_hasher{
|
||||
FastRandomContext().rand64(),
|
||||
FastRandomContext().rand64()}
|
||||
{}
|
||||
|
||||
SaltedWtxidHasher::SaltedWtxidHasher() :
|
||||
k0{FastRandomContext().rand64()},
|
||||
k1{FastRandomContext().rand64()} {}
|
||||
SaltedWtxidHasher::SaltedWtxidHasher() : m_hasher{
|
||||
FastRandomContext().rand64(),
|
||||
FastRandomContext().rand64()}
|
||||
{}
|
||||
|
||||
SaltedOutpointHasher::SaltedOutpointHasher(bool deterministic) : m_hasher{
|
||||
deterministic ? 0x8e819f2607a18de6 : FastRandomContext().rand64(),
|
||||
|
||||
@@ -17,47 +17,43 @@
|
||||
|
||||
class SaltedUint256Hasher
|
||||
{
|
||||
private:
|
||||
/** Salt */
|
||||
const uint64_t k0, k1;
|
||||
const PresaltedSipHasher m_hasher;
|
||||
|
||||
public:
|
||||
SaltedUint256Hasher();
|
||||
|
||||
size_t operator()(const uint256& hash) const {
|
||||
return SipHashUint256(k0, k1, hash);
|
||||
size_t operator()(const uint256& hash) const
|
||||
{
|
||||
return m_hasher(hash);
|
||||
}
|
||||
};
|
||||
|
||||
class SaltedTxidHasher
|
||||
{
|
||||
private:
|
||||
/** Salt */
|
||||
const uint64_t k0, k1;
|
||||
const PresaltedSipHasher m_hasher;
|
||||
|
||||
public:
|
||||
SaltedTxidHasher();
|
||||
|
||||
size_t operator()(const Txid& txid) const {
|
||||
return SipHashUint256(k0, k1, txid.ToUint256());
|
||||
size_t operator()(const Txid& txid) const
|
||||
{
|
||||
return m_hasher(txid.ToUint256());
|
||||
}
|
||||
};
|
||||
|
||||
class SaltedWtxidHasher
|
||||
{
|
||||
private:
|
||||
/** Salt */
|
||||
const uint64_t k0, k1;
|
||||
const PresaltedSipHasher m_hasher;
|
||||
|
||||
public:
|
||||
SaltedWtxidHasher();
|
||||
|
||||
size_t operator()(const Wtxid& wtxid) const {
|
||||
return SipHashUint256(k0, k1, wtxid.ToUint256());
|
||||
size_t operator()(const Wtxid& wtxid) const
|
||||
{
|
||||
return m_hasher(wtxid.ToUint256());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SaltedOutpointHasher
|
||||
{
|
||||
const PresaltedSipHasher m_hasher;
|
||||
@@ -80,8 +76,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct FilterHeaderHasher
|
||||
{
|
||||
struct FilterHeaderHasher {
|
||||
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user