Skip to content

Commit

Permalink
Upgrade to SIMD implementation of xxhash
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Jan 19, 2024
1 parent 23464fb commit 1cb418e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/ripple/beast/hash/xxhasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class xxhasher
// requires 64-bit std::size_t
static_assert(sizeof(std::size_t) == 8, "");

XXH64_state_t* state_;
XXH3_state_t* state_;

public:
using result_type = std::size_t;
Expand All @@ -47,42 +47,42 @@ class xxhasher

xxhasher() noexcept
{
state_ = XXH64_createState();
XXH64_reset(state_, 1);
state_ = XXH3_createState();
XXH3_64bits_reset(state_);
}

~xxhasher() noexcept
{
XXH64_freeState(state_);
XXH3_freeState(state_);
}

template <
class Seed,
std::enable_if_t<std::is_unsigned<Seed>::value>* = nullptr>
explicit xxhasher(Seed seed)
{
state_ = XXH64_createState();
XXH64_reset(state_, seed);
state_ = XXH3_createState();
XXH3_64bits_reset_withSeed(state_, seed);
}

template <
class Seed,
std::enable_if_t<std::is_unsigned<Seed>::value>* = nullptr>
xxhasher(Seed seed, Seed)
{
state_ = XXH64_createState();
XXH64_reset(state_, seed);
state_ = XXH3_createState();
XXH3_64bits_reset_withSeed(state_, seed);
}

void
operator()(void const* key, std::size_t len) noexcept
{
XXH64_update(state_, key, len);
XXH3_64bits_update(state_, key, len);
}

explicit operator std::size_t() noexcept
{
return XXH64_digest(state_);
return XXH3_64bits_digest(state_);
}
};

Expand Down

0 comments on commit 1cb418e

Please sign in to comment.