`<unordered_meow>`: Should we detect bogus hash/equivalence combos?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
WG21-N4971 [unord.req.general]/5:
Two values
k1andk2are considered equivalent if the container’s key equality predicatepred(k1, k2)is valid and returnstruewhen passed those values. Ifk1andk2are equivalent, the container’s hash function shall return the same value for both.
This is a very important requirement - violating it will corrupt the unordered associative containers, which can be hard to track down later. (Note that the requirement is one way. Equivalent elements must imply identical hashes, but identical hashes need not imply equivalent elements - that's just a hash collision, which degrades performance but not correctness. It sure is funny when someone writes a hash that returns bool, though.)
For the ordered associative containers (and sorting functions), our _Debug_lt_pred() machinery detects bogus less-than comparisons, which have the same potential to corrupt data structures and break algorithms.
We should consider implementing similar debug checks for hash/equivalence. This could affect debug mode perf, which users might notice as a significant regression, so we should consider skipping such debug checks for known combos (e.g. unordered_set<int> should pay zero additional costs), similar to #4377 which I just filed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing _Debug_lt_pred() machinery for ordered associative containers and sorting functions, then compare the proposal with issue #4377. Investigate how debug checks could cover hash/equivalence requirements without regressing known combinations such as unordered_set. Done means an agreed design and performance approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100