-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from SergeyMakeev/add-wyhash
Replace `identity` hash with `wyhash` To address performance issues with sequentially ordered integer keys, we have transitioned from Identity Hash to WyHash, enhancing overall performance and stability (see updated performance metrics)
- Loading branch information
Showing
24 changed files
with
213 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
build2019 | ||
build2019_32 | ||
build2022 | ||
build2022_32 | ||
build | ||
codecov_report | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "wyhash.h" | ||
|
||
namespace Excalibur | ||
{ | ||
|
||
// generic type (without implementation) | ||
template <typename T> struct KeyInfo | ||
{ | ||
// static inline T getTombstone() noexcept; | ||
// static inline T getEmpty() noexcept; | ||
// static inline size_t hash(const T& key) noexcept; | ||
// static inline bool isEqual(const T& lhs, const T& rhs) noexcept; | ||
// static inline bool isValid(const T& key) noexcept; | ||
}; | ||
|
||
template <> struct KeyInfo<int32_t> | ||
{ | ||
static inline bool isValid(const int32_t& key) noexcept { return key < INT32_C(0x7ffffffe); } | ||
static inline int32_t getTombstone() noexcept { return INT32_C(0x7fffffff); } | ||
static inline int32_t getEmpty() noexcept { return INT32_C(0x7ffffffe); } | ||
static inline size_t hash(const int32_t& key) noexcept { return Excalibur::wyhash::hash(key); } | ||
static inline bool isEqual(const int32_t& lhs, const int32_t& rhs) noexcept { return lhs == rhs; } | ||
}; | ||
|
||
template <> struct KeyInfo<uint32_t> | ||
{ | ||
static inline bool isValid(const uint32_t& key) noexcept { return key < UINT32_C(0xfffffffe); } | ||
static inline uint32_t getTombstone() noexcept {return UINT32_C(0xfffffffe); } | ||
static inline uint32_t getEmpty() noexcept {return UINT32_C(0xffffffff); } | ||
static inline size_t hash(const uint32_t& key) noexcept { return Excalibur::wyhash::hash(key); } | ||
static inline bool isEqual(const uint32_t& lhs, const uint32_t& rhs) noexcept { return lhs == rhs; } | ||
}; | ||
|
||
template <> struct KeyInfo<int64_t> | ||
{ | ||
static inline bool isValid(const int64_t& key) noexcept { return key < INT64_C(0x7ffffffffffffffe); } | ||
static inline int64_t getTombstone() noexcept { return INT64_C(0x7fffffffffffffff); } | ||
static inline int64_t getEmpty() noexcept { return INT64_C(0x7ffffffffffffffe); } | ||
static inline size_t hash(const int64_t& key) noexcept { return Excalibur::wyhash::hash(key); } | ||
static inline bool isEqual(const int64_t& lhs, const int64_t& rhs) noexcept { return lhs == rhs; } | ||
}; | ||
|
||
template <> struct KeyInfo<uint64_t> | ||
{ | ||
static inline bool isValid(const uint64_t& key) noexcept { return key < UINT64_C(0xfffffffffffffffe); } | ||
static inline uint64_t getTombstone() noexcept { return UINT64_C(0xfffffffffffffffe); } | ||
static inline uint64_t getEmpty() noexcept { return UINT64_C(0xffffffffffffffff); } | ||
static inline size_t hash(const uint64_t& key) noexcept { return Excalibur::wyhash::hash(key); } | ||
static inline bool isEqual(const uint64_t& lhs, const uint64_t& rhs) noexcept { return lhs == rhs; } | ||
}; | ||
|
||
template <> struct KeyInfo<std::string> | ||
{ | ||
static inline bool isValid(const std::string& key) noexcept { return !key.empty() && key.data()[0] != char(1); } | ||
static inline std::string getTombstone() noexcept | ||
{ | ||
// and let's hope that small string optimization will do the job | ||
return std::string(1, char(1)); | ||
} | ||
static inline std::string getEmpty() noexcept { return std::string(); } | ||
static inline size_t hash(const std::string& key) noexcept { return std::hash<std::string>{}(key); } | ||
static inline bool isEqual(const std::string& lhs, const std::string& rhs) noexcept { return lhs == rhs; } | ||
}; | ||
|
||
|
||
} // namespace Excalibur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#if defined(_MSC_VER) | ||
#define EXLBR_VISUAL_STUDIO (1) | ||
#define EXLBR_FORCE_INLINE __forceinline | ||
#endif | ||
|
||
#if defined(__clang__) | ||
#define EXLBR_CLANG (1) | ||
#define EXLBR_FORCE_INLINE __attribute__((always_inline)) | ||
#endif | ||
|
||
#if defined(__GNUC__) | ||
#define EXLBR_GCC (1) | ||
#endif | ||
|
||
#if defined(_M_X64) || defined(__aarch64__) || defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || \ | ||
defined(__LP64__) || defined(_WIN64) | ||
#define EXLBR_64 (1) | ||
#else | ||
#define EXLBR_32 (1) | ||
#endif | ||
|
||
#if EXLBR_VISUAL_STUDIO | ||
#include <intrin.h> | ||
#endif | ||
|
||
namespace Excalibur | ||
{ | ||
|
||
namespace wyhash | ||
{ | ||
|
||
#if EXLBR_64 | ||
|
||
inline uint64_t _hash64(uint64_t v) | ||
{ | ||
#if defined(EXLBR_VISUAL_STUDIO) | ||
{ | ||
uint64_t h; | ||
uint64_t l = _umul128(v, UINT64_C(0x9E3779B97F4A7C15), &h); | ||
return l ^ h; | ||
} | ||
#elif defined(EXLBR_CLANG) || defined(EXLBR_GCC) | ||
{ | ||
__uint128_t r = v; | ||
r *= UINT64_C(0x9E3779B97F4A7C15); | ||
return (uint64_t)(r >> 64U) ^ (uint64_t)(r); | ||
} | ||
#else | ||
{ | ||
#error Unsupported compiler | ||
} | ||
#endif | ||
} | ||
|
||
#elif EXLBR_32 | ||
|
||
inline uint32_t _hash32(uint32_t v) | ||
{ | ||
#if EXLBR_VISUAL_STUDIO | ||
{ | ||
uint64_t lh = __emulu(v, UINT32_C(0x9e3779b1)); | ||
return (uint32_t)(lh >> 32U) ^ (uint32_t)(lh); | ||
} | ||
#elif defined(EXLBR_CLANG) || defined(EXLBR_GCC) | ||
{ | ||
uint64_t lh = uint64_t(v) * uint64_t(0x9e3779b1); | ||
return (uint32_t)(lh >> 32U) ^ (uint32_t)(lh); | ||
} | ||
#else | ||
{ | ||
#error Unsupported compiler | ||
} | ||
#endif | ||
} | ||
#else | ||
#error Unsupported platform. Only 64/32-bit platforms supported | ||
#endif | ||
|
||
inline size_t hash(uint64_t v) | ||
{ | ||
#if EXLBR_64 | ||
return _hash64(v); | ||
#elif EXLBR_32 | ||
uint32_t vv = (uint32_t)(v >> 32U) ^ (uint32_t)(v); | ||
return _hash32(vv); | ||
#else | ||
#error Unsupported platform. Only 64/32-bit platforms supported | ||
#endif | ||
} | ||
|
||
inline size_t hash(uint32_t v) | ||
{ | ||
#if EXLBR_64 | ||
return _hash64(uint64_t(v)); | ||
#elif EXLBR_32 | ||
return _hash32(v); | ||
#else | ||
#error Unsupported platform. Only 64/32-bit platforms supported | ||
#endif | ||
} | ||
|
||
|
||
inline size_t hash(int64_t v) { return hash(uint64_t(v)); } | ||
inline size_t hash(int32_t v) { return hash(uint32_t(v)); } | ||
|
||
|
||
} // namespace wyhash | ||
|
||
} // namespace Excalibur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.