Add struct enumerator and IEnumerable<int> to IntSet - #51
Merged
Conversation
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
Mirrors the dictionary-side enumeration work (PRs #47 / #48) on the set side.
IntSet<THasher>now ships a structEnumerator, a publicGetEnumerator(), andIEnumerable<int>conformance, soforeach (int item in set)works without a wrapper andIntSetis ready for LINQ.The out-of-band zero entry is yielded first when present, matching how the dictionaries surface their out-of-band default-key entry. A
_versioncounter is bumped on every entry-point structural mutation (Add,TryAdd,Remove,Clear); the struct enumerator captures it on construction and re-checks it fromMoveNext/Reset, so concurrent modification fast-fails withInvalidOperationExceptionexactly the way BCLHashSet<T>does. No-op mutations (re-adding an existing item, removing an absent item,Clearon an empty set) deliberately do not bump the version, so active enumerators stay valid across them — also a regression target.This is the first slice of issue #23 —
CeleritySet<T, THasher>follows in a separate PR (the open-genericTpath needsIsDefaultValuecare that's worth its own review). Together they unblock the futureIEnumerable<T>constructor on the sets and the post-1.1.0IReadOnlySet<T>interface.Changes
src/Celerity/Collections/IntSet.cs— addIEnumerable<int>interface,_versionfield, version bumps onTryAdd/Remove/Clear, publicGetEnumerator(), structEnumeratorwithBeforeZero/InArray/Donestate machine.src/Celerity.Tests/Collections/IntSetEnumerationTests.cs— 25 new tests (see test plan).CHANGELOG.md,ROADMAP.md,ISSUES.md— documented under issue Add SIMD optimizations #23.Test plan
dotnet build— 0 errors, no new warnings beyond the existing pre-existing analyzer noise.dotnet test— 431 / 431 pass (25 new tests inIntSetEnumerationTests, all 406 prior tests still green).Clearreflected in subsequent enumeration.capacity: 4).MoveNextandReset(insert, zero-insert, remove, zero-remove, clear).TryAdd, absentRemove, emptyClear) leave active enumerators valid.Resetreusability and post-exhaustionCurrentreset.IEnumerable<int>and non-genericIEnumerableparity.IntSet<Int32Murmur3Hasher>.Count/Sum/Contains) confirming the boxed enumerator path.