Skip to content

Improve detection and enforcement of is_avalanching trait #92

@vmilea

Description

@vmilea

First of all, thanks for making this awesome library!

Is your feature request related to a problem? Please describe.

The mechanism for tagging high quality hashes could be improved a bit, so it's easier to integrate in existing code bases.

Describe the solution you'd like

  1. I prefer to specialize std::hash, but the primary template ankerl::unordered_dense::hash which falls back to std::hash doesn't currently propagate the is_avalanching trait. So it won't be detected unless hashes are moved to ankerl::unordered_dense namespace.
  2. In my project, all hashes are supposed to be high quality, but it's easy to forget to add the is_avalanching trait. It would be nice to have a require_avalanching policy on the container that can be asserted at compile time.
  3. An additional assume_avalanching policy sounds a little dangerous, but would avoid having to litter code with is_avalanching traits.

Describe alternatives you've considered

My approach for (2) is to wrap the default hash type:

template <typename Hash>
struct require_avalanching : Hash
{
    static_assert(requires { typename Hash::is_avalanching; });
};

// alias with default policy
template <class Key, class Hash = require_avalanching<ankerl::unordered_dense::hash<Key>>, ...>
using hash_set = ankerl::unordered_dense::set<Key, Hash, ...>;

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions