boostorg / boostorg/unordered

Have you considered keeping the calculated hashes in the table entries?

Open
#133 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
92
Forks
88
PR merge metrics
No merged PRs in 30d

Description

If I'm reading it right, it looks like the internal table is not storing the calculated hashes of the node keys. Instead, the hash is calculated on insertion to determine the bucket, and then thrown away. After that, only key-equality is used for things like `find()`, erasure, equality, etc.

That's fine when the key is something small, like an `int`, but is slow when the key is _not_ small. Even for string type keys, if the container happens to have a lot of keys of the same string lengths, then equality checking is not cheap. And of course people use custom types for keys too, with potentially non-trivial equality comparisons.

On the other hand, if you stored the full calculated hash in the nodes, you could skip past entries in the same bucket that don't have a matching full-hash, thereby improving performance. (at the expense of memory, obviously)

Another example is rehashing when the load-factor is exceeded. Right now it looks like it has to re-calc the hash of every single node, whereas if it had stored the full-hash it wouldn't need to.

LLVM/clang's `libc++` unordered containers store the full-hash, and gcc's `libstdc++` does as well in specific cases (e.g., for string-ish types, or if the user specifies the hashing is slow).

So I'm wondering if you've considered doing that, or believe the memory tradeoff isn't worth it?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.