Add IEnumerable<T> constructor on IntSet and CeleritySet - #70
Merged
Conversation
Closes #69. Mirrors the IEnumerable<KeyValuePair<,>> ctor that shipped on the dictionaries in 1.1.2. Unlike the dictionary version, duplicate elements (including duplicate default(T) / zero entries) are silently deduped to match BCL HashSet<T>(IEnumerable<T>) semantics — sets have no duplicate-key contract. When the source implements ICollection<T>, its Count seeds the backing storage; otherwise we fall back to the caller-supplied capacity. The out-of-band zero / default(T) slot is populated correctly via TryAdd on the iteration path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Closed
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.
Summary
Closes #69. Adds an
IEnumerable<T>constructor toIntSet,IntSet<THasher>, andCeleritySet<T, THasher>so the sets can be bulk-loaded from an existing sequence — closing the last set-side API-parity gap with the dictionaries (which got the equivalentIEnumerable<KeyValuePair<,>>ctor in 1.1.2).Unlike the dictionary version, duplicate elements (including duplicate
default(T)/ zero entries) are silently deduplicated — sets have no duplicate-key contract, so this matches BCLHashSet<T>(IEnumerable<T>).When the source implements
ICollection<T>, itsCountis used to size the backing storage; otherwise the caller-suppliedcapacityparameter is used. The out-of-banddefault(T)/ zero slot is populated correctly viaTryAddon the iteration path.Test plan
dotnet buildclean (0 errors)SetIEnumerableConstructorTestson Linux / Windows / macOS — local runtime is .NET 10 only and the projects target net8.0, so the test execution gate is CISetIEnumerableConstructorTests(mirrorsIEnumerableConstructorTestsfor the dictionaries):ArgumentNullExceptionloadFactor(0f,1f) still throwsArgumentOutOfRangeExceptionList<T>/ non-collection (Enumerable.Range) sources copy correctlynull/default(T)entriesCeleritySet<int, ...>from anIntSetenumerationIntSet<Int32WangNaiveHasher>smoke test