Skip to content

Commit

Permalink
HashTraitsBucketSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Jul 21, 2024
1 parent db92cf1 commit c4a0314
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
5 changes: 1 addition & 4 deletions include/momo/HashSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,7 @@ class HashSet

typedef internal::HashSetBucketItemTraits<ItemTraits> BucketItemTraits;

static const bool useHashCodePartGetter = !HashTraits::isFastNothrowHashable;

typedef typename HashTraits::HashBucket HashBucket;
typedef typename HashBucket::template Bucket<BucketItemTraits, useHashCodePartGetter> Bucket;
typedef typename internal::HashTraitsBucketSelector<HashTraits, BucketItemTraits>::Bucket Bucket;

typedef typename Bucket::Params BucketParams;

Expand Down
31 changes: 26 additions & 5 deletions include/momo/HashTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ namespace internal
: public std::true_type
{
};

template<typename HashTraits, typename ItemTraits,
typename = void>
struct HashTraitsBucketSelector
{
MOMO_DEPRECATED typedef typename HashTraits::HashBucket
::template Bucket<ItemTraits, !HashTraits::isFastNothrowHashable> Bucket;
};

template<typename HashTraits, typename ItemTraits>
struct HashTraitsBucketSelector<HashTraits, ItemTraits,
Void<typename HashTraits::template Bucket<ItemTraits>>>
{
typedef typename HashTraits::template Bucket<ItemTraits> Bucket;
};
}

template<typename Key>
Expand Down Expand Up @@ -114,12 +129,15 @@ class HashTraits
typedef THashBucket HashBucket;
typedef TKeyArgBase KeyArgBase;

static const bool isFastNothrowHashable = IsFastNothrowHashable<KeyArgBase>::value;

template<typename ItemTraits>
using Bucket = typename HashBucket::template Bucket<ItemTraits, !isFastNothrowHashable>;

template<typename KeyArg>
using IsValidKeyArg = typename std::conditional<std::is_same<KeyArgBase, Key>::value,
std::false_type, std::is_convertible<const KeyArg&, const KeyArgBase&>>::type; //?

static const bool isFastNothrowHashable = IsFastNothrowHashable<KeyArgBase>::value;

public:
explicit HashTraits() noexcept
{
Expand Down Expand Up @@ -182,13 +200,16 @@ class HashTraitsStd
typedef TEqualFunc EqualFunc;
typedef THashBucket HashBucket;

template<typename KeyArg>
using IsValidKeyArg = internal::HashTraitsStdIsValidKeyArg<HashFunc, EqualFunc>;

static const bool isFastNothrowHashable = IsFastNothrowHashable<Key>::value
&& (std::is_same<HashFunc, HashCoder<Key>>::value
|| std::is_same<HashFunc, std::hash<Key>>::value);

template<typename ItemTraits>
using Bucket = typename HashBucket::template Bucket<ItemTraits, !isFastNothrowHashable>;

template<typename KeyArg>
using IsValidKeyArg = internal::HashTraitsStdIsValidKeyArg<HashFunc, EqualFunc>;

public:
explicit HashTraitsStd(size_t startBucketCount = size_t{1} << HashBucket::logStartBucketCount,
const HashFunc& hashFunc = HashFunc(),
Expand Down

0 comments on commit c4a0314

Please sign in to comment.