Skip to content

Add IEnumerable<T> constructor on IntSet and CeleritySet - #70

Merged
marius-bughiu merged 1 commit into
mainfrom
feat/set-ienumerable-ctor
May 11, 2026
Merged

Add IEnumerable<T> constructor on IntSet and CeleritySet#70
marius-bughiu merged 1 commit into
mainfrom
feat/set-ienumerable-ctor

Conversation

@marius-bughiu

Copy link
Copy Markdown
Owner

Summary

Closes #69. Adds an IEnumerable<T> constructor to IntSet, IntSet<THasher>, and CeleritySet<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 equivalent IEnumerable<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 BCL HashSet<T>(IEnumerable<T>).

When the source implements ICollection<T>, its Count is used to size the backing storage; otherwise the caller-supplied capacity parameter is used. The out-of-band default(T) / zero slot is populated correctly via TryAdd on the iteration path.

Test plan

  • dotnet build clean (0 errors)
  • CI runs SetIEnumerableConstructorTests on Linux / Windows / macOS — local runtime is .NET 10 only and the projects target net8.0, so the test execution gate is CI
  • Coverage in SetIEnumerableConstructorTests (mirrors IEnumerableConstructorTests for the dictionaries):
    • Null source throws ArgumentNullException
    • Invalid loadFactor (0f, 1f) still throws ArgumentOutOfRangeException
    • Empty / array / List<T> / non-collection (Enumerable.Range) sources copy correctly
    • Duplicate elements silently dedupe — including duplicate zero / null / default(T) entries
    • Out-of-band zero / null capture from source
    • 500-entry large-source round-trip
    • Source mutated after construction does not affect the set
    • Caller-specified capacity larger than the source count is honored
    • Cross-set copy: build a CeleritySet<int, ...> from an IntSet enumeration
    • Open-generic IntSet<Int32WangNaiveHasher> smoke test

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>
@marius-bughiu
marius-bughiu merged commit 3de885d into main May 11, 2026
3 checks passed
@marius-bughiu
marius-bughiu deleted the feat/set-ienumerable-ctor branch July 24, 2026 22:46
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.

Add IEnumerable<T> constructor on IntSet and CeleritySet

1 participant