Skip to content

Add hash-aware insertion functions with a precalculated hash#94

Merged
Tessil merged 2 commits into
Tessil:masterfrom
mitsuba-renderer:master
Jun 13, 2026
Merged

Add hash-aware insertion functions with a precalculated hash#94
Tessil merged 2 commits into
Tessil:masterfrom
mitsuba-renderer:master

Conversation

@wjakob

@wjakob wjakob commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The precalculated_hash overloads currently exist only on the const lookup functions and erase; none of the insertion functions can accept a caller-provided hash. This commit adds try_emplace_hash(), insert_or_assign_hash() and insert_hash() to robin_map, and insert_hash() to robin_set.

(For context, I am developing a project where the possibility to avoid redundant hash computations leads to a pretty significant speedup when using tsl::robin_map).

The `precalculated_hash` overloads currently exist only on the const
lookup functions and `erase`; none of the insertion functions can accept
a caller-provided hash. This commit adds `try_emplace_hash()`,
`insert_or_assign_hash()` and `insert_hash()` to `robin_map`, and
`insert_hash()` to `robin_set`.
@Tessil

Tessil commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Thank you for the PR.

Yes, I hesitated before to add such functionality as it carries quite a bit of risk of miss use if the wrong hash is provided. But I think it should be alright to add the functionality with enough warning about the potential undefined behaviour in the documentation.

Though I would prefer the name insert_with_hash instead of insert_hash if possible.

@wjakob

wjakob commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@Tessil thanks—I renamed them.

@Tessil Tessil merged commit 91362aa into Tessil:master Jun 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants