diff options
author | vadim-xd <vadim-xd@yandex-team.com> | 2023-10-05 16:30:56 +0300 |
---|---|---|
committer | vadim-xd <vadim-xd@yandex-team.com> | 2023-10-05 17:02:36 +0300 |
commit | 762a22f887e56e471cb1196f503d47588a761490 (patch) | |
tree | ee8623466fcdd8fc0731466f05632dbe021e4af0 /library | |
parent | cbdefbc325eedf2f0c84b4ddc5dae8df48191f10 (diff) | |
download | ydb-762a22f887e56e471cb1196f503d47588a761490.tar.gz |
Allow other types in GetBucketForKey
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/containers/concurrent_hash/concurrent_hash.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/library/cpp/containers/concurrent_hash/concurrent_hash.h b/library/cpp/containers/concurrent_hash/concurrent_hash.h index b11deb6254..042bf0c040 100644 --- a/library/cpp/containers/concurrent_hash/concurrent_hash.h +++ b/library/cpp/containers/concurrent_hash/concurrent_hash.h @@ -5,6 +5,13 @@ #include <array> +namespace NPrivate { + template <typename T, typename THash> + concept CHashableBy = requires (const THash& hash, const T& t) { + hash(t); + }; +} + template <typename K, typename V, size_t BucketCount = 64, typename L = TAdaptiveLock> class TConcurrentHashMap { public: @@ -69,11 +76,13 @@ public: std::array<TBucket, BucketCount> Buckets; public: - TBucket& GetBucketForKey(const K& key) { + template <NPrivate::CHashableBy<THash<K>> TKey> + TBucket& GetBucketForKey(const TKey& key) { return Buckets[THash<K>()(key) % BucketCount]; } - const TBucket& GetBucketForKey(const K& key) const { + template <NPrivate::CHashableBy<THash<K>> TKey> + const TBucket& GetBucketForKey(const TKey& key) const { return Buckets[THash<K>()(key) % BucketCount]; } |