Repository navigation
Conversation
`Counter<T, N, S>` gained its hasher parameter in coriolinus#51, but four items were left pinned to the default hasher and so silently disappeared from counters built with any other one: - `Counter::into_map` - `Counter::total` - `FromIterator<(T, N)>` - `SubAssign<I>` Generalize the three impl blocks which hold them. `into_map` now returns `HashMap<T, N, S>`, handing back the counter's own hasher rather than forcing `RandomState`; the type is unchanged for the default hasher. The type parameter of `total` is renamed from `S` to `Total`, since `S` now names the hasher of the enclosing impl. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
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.
Problem
#51 made
Countergeneric over its hasher, but four items were left in impl blocks written asCounter<T, N>, which resolves to `Countsimply do not exist on acounter built with any other hasher:
Counter::into_mapCounter::totalimpl FromIterator<(T, N)>impl SubAssign<I>So swapping in a faster hasher silently c
,counter.total(),counter.into_map(), and collecting from(item, count)` pairs, with nothing to suggest therestriction is unintended.
Changes
Generalize the three impl blocks which ho
into_mapnow returnsHashMap<T, N, Ss own hasher rather than forcingRandomState`. For the default hasher the type is unchanged.total's type parameter is renamed froow names the hasher of theenclosing impl. Call sites are unaffected.
FromIterator<(T, N)>gainsS: BuildHe existingFromIterator` impl.SubAssign<I>gainsS: BuildHasher, ` impl.Compatibility
Non-breaking for annotated code, which ised
(
collect::<Counter<_>>(),let c: Counter<char> = ...).One inference caveat, the same one
stdaccepts:Counter::from_iter(pairs)with no annotationused to resolve
StoRandomStatebecad now needsSpinned bycontext.
stdmade the same trade-off forimpl<K, V, S: Default + BuildHasher> Fro<K, V, S>.Relationship to the constructor PR
Independent of #59 — either can merge firsts next to each other in
tests/tests.rs, so whichever merges second needs a trivial conflict resolution there (keepboth tests).
To keep that true,
FromIterator<(T, N)>ruct literal rather than aconstructor:
Counter::new()would returnCounter<T, N, RandomState>once #59 lands, andCounter::with_hasherdoes not exist untis the only form whichcompiles either way. Once both are in, that body can be simplified to
Counter::with_hasher(S::default())and p` import dropped — happyto fold that into whichever branch merges second.
cargo test --all-features(18 unit + 19 integration + 47 doctests) andcargo clippy --all-features --all-targetsare clean. r locally also builds andpasses (21 + 20 + 51).