Remove set items from storage using the set's comparer - #63
Merged
Merged
Conversation
ContiguousSet.Remove and InsertionOrderSet.Remove removed the item from the
comparer-aware uniqueness HashSet, then searched the ordered backing store
with default equality. With a custom comparer such as OrdinalIgnoreCase,
Remove("APPLE") on a set holding "Apple" dropped the hash entry but left the
stored item, so it still enumerated, Count did not change, and a later Add
stored a duplicate. Both now locate the stored item with uniquenessSet.Comparer.
Fixes #61
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UHW69XTeuuLbfVdQdJ8uQh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UHW69XTeuuLbfVdQdJ8uQh
|
This was referenced Sep 26, 2026
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.



Fixes #61
Problem
ContiguousSet<T>.RemoveandInsertionOrderSet<T>.Removeremoved the item from the comparer-awareuniquenessSet, then searched the ordered backing store with default equality (Array.IndexOf/List<T>.Remove). With a custom comparer such asStringComparer.OrdinalIgnoreCase,Remove("APPLE")on a set holding"Apple"returnedtruebut left"Apple"in storage. It still enumerated,Countstayed the same, and a laterAdd("apple")stored a duplicate.Fix
Both methods now find the stored item with
uniquenessSet.Comparer:ContiguousSet: a linear scan with the comparer replacesArray.IndexOfInsertionOrderSet:FindIndexwith the comparer, thenRemoveAt, replacesList<T>.RemoveTests
I added two regression tests to each of
ContiguousSetTestsandInsertionOrderSetTests:Remove_WithCustomComparer_RemovesItemEqualOnlyUnderComparerRemove_WithCustomComparer_ThenAdd_KeepsSingleElementWith the fix reverted, all 4 fail. With it, the full suite passes (377/377, net9.0 test project on Linux).
🤖 Generated with Claude Code
https://claude.ai/code/session_01UHW69XTeuuLbfVdQdJ8uQh
Generated by Claude Code