Use a single type alias for indexmap and indexset to enforce hasher#16130
Merged
Conversation
Collaborator
|
One or more of the following people are relevant to this code:
|
Coverage Report for CI Build 26658117959Coverage decreased (-0.003%) to 87.556%Details
Uncovered Changes
Coverage Regressions9 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
Building off of Qiskit#15920 which moved our hasher for IndexMap usage to be foldhash this moves to having a common type alias for IndexMap and IndexSet that has the hasher set. All the internal usage of IndexMap and IndexSet are updated to use this new alias instead which removes the boiler plate around dealing with initializing the hasher for the most part, the only exception is when using `with_capacity_and_hasher()` there is no method to create an empty object with a capacity preallocated and the hasher is initialized from the generic type. To enforce that we're using the correct hasher for all indexmap usage the clippy rules are updated to disallow the indexmap::IndexMap and indexmap::IndexSet types directly. This means that after this commit all indexmap usage with be forced by clippy to leverage our standard pattern using foldhash. The advantage is if we ever need to change the default hasher again in the future we only need to update one central place (and the places using with_capacity_and_hasher).
12f7ed5 to
ab3e81a
Compare
Member
Author
|
This has been rebased on main now that #15920 has merged and is ready for review. |
raynelfss
approved these changes
May 29, 2026
Contributor
raynelfss
left a comment
There was a problem hiding this comment.
LGTM. I can confirm there's no usage of Index{Map, Set}::new() (in favor of Index{Map, Set}::default()), no imports of indexmap::{IndexMap, IndexSet}, and no usage of them as they are now marked as disallowed.
I will have to keep in mind to always use qiskit_utils::{IndexMap, IndexSet} from now on but it at least guarantees that in the future, if we decide to use a different hasher, the changes are not as intrusive. 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building off of #15920 which moved our hasher for IndexMap usage to be
foldhash this moves to having a common type alias for IndexMap and
IndexSet that has the hasher set. All the internal usage of IndexMap and
IndexSet are updated to use this new alias instead which removes the
boiler plate around dealing with initializing the hasher for the most
part, the only exception is when using
with_capacity_and_hasher()there is no method to create an empty object with a capacity
preallocated and the hasher is initialized from the generic type. To
enforce that we're using the correct hasher for all indexmap usage the
clippy rules are updated to disallow the indexmap::IndexMap and
indexmap::IndexSet types directly. This means that after this commit all
indexmap usage with be forced by clippy to leverage our standard pattern
using foldhash. The advantage is if we ever need to change the default
hasher again in the future we only need to update one central place
(and the places using with_capacity_and_hasher).
This PR is based on top of #15920 and will need to be rebased after that is merged. In the meantime you can view the contents of just this PR by looking at the PR branch's HEAD commit: 12f7ed5This has been rebased.AI/LLM disclosure