Add ContainsValue on IntDictionary, LongDictionary, CelerityDictionary - #74
Merged
Conversation
BCL-parity O(n) linear scan. Walks the probe table skipping EMPTY_KEY / default(TKey) slots (so the default(TValue) payload sitting in those slots is not mistaken for a real entry) and, when present, the out-of-band zero-key / default-key slot. Uses EqualityComparer<TValue>.Default to match the BCL. Closes #73. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: marius-bughiu <11870708+marius-bughiu@users.noreply.github.com>
Contributor
Done in ec73ccc. The only conflict was in |
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
bool ContainsValue(TValue? value)to all three dictionary types — BCL-parityO(n)linear scan that returnstrueif any entry's value equalsvalueunderEqualityComparer<TValue>.Default, matchingDictionary<TKey, TValue>.ContainsValue.EMPTY_KEY/default(TKey)slots (so the empty-slotdefault(TValue)payload is not mistaken for a real entry) and, when present, the out-of-band zero-key / default-key slot.EqualityComparer<TValue>.Defaultaccess. Mirrors the implementation pattern already used by the struct enumerator's slot scan.This was the smallest remaining gap in the basic BCL surface: callers reaching for
ContainsValuehad to fall back to the boxedIEnumerable<KeyValuePair<,>>enumeration path, defeating the zero-allocation guarantees the dictionaries otherwise provide.Closes #73.
Test plan
ContainsValueTestscovers all three dictionaries:false(including for thedefault(TValue)lookup — guards thatEMPTY_KEYslots are skipped).false.default(TValue)(0) lookup on a populated dictionary that contains0as a value, separate from the empty-dictionary regression check.null-value lookup on a reference-typeTValue.Remove/ post-Remove(0)/ post-Clearcorrectly stop reporting the removed values.Local build:
dotnet buildclean (no errors). Tests cannot run locally — the SDK on this machine is .NET 10 only and the test project targetsnet8.0— but CI runs the matrix onubuntu-latest,windows-latest, andmacos-latestand will exercise them.🤖 Generated with Claude Code