Skip to content

Add ContainsValue on IntDictionary, LongDictionary, CelerityDictionary - #74

Merged
marius-bughiu merged 2 commits into
mainfrom
feat/contains-value
May 11, 2026
Merged

Add ContainsValue on IntDictionary, LongDictionary, CelerityDictionary#74
marius-bughiu merged 2 commits into
mainfrom
feat/contains-value

Conversation

@marius-bughiu

Copy link
Copy Markdown
Owner

Summary

  • Adds bool ContainsValue(TValue? value) to all three dictionary types — BCL-parity O(n) linear scan that returns true if any entry's value equals value under EqualityComparer<TValue>.Default, matching Dictionary<TKey, TValue>.ContainsValue.
  • Walks the probe table skipping EMPTY_KEY / default(TKey) slots (so the empty-slot default(TValue) payload is not mistaken for a real entry) and, when present, the out-of-band zero-key / default-key slot.
  • No allocation on the hot path beyond the cached EqualityComparer<TValue>.Default access. 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 ContainsValue had to fall back to the boxed IEnumerable<KeyValuePair<,>> enumeration path, defeating the zero-allocation guarantees the dictionaries otherwise provide.

Closes #73.

Test plan

ContainsValueTests covers all three dictionaries:

  • Empty map returns false (including for the default(TValue) lookup — guards that EMPTY_KEY slots are skipped).
  • Match found in a regular probe-table slot.
  • Match found only in the out-of-band zero-key / default-key / null-string-key slot.
  • Missing value returns false.
  • default(TValue) (0) lookup on a populated dictionary that contains 0 as a value, separate from the empty-dictionary regression check.
  • null-value lookup on a reference-type TValue.
  • Duplicate values short-circuit on the first match.
  • Survives a 100-entry insert from a tiny initial capacity (covers post-resize slot scan).
  • Post-Remove / post-Remove(0) / post-Clear correctly stop reporting the removed values.

Local build: dotnet build clean (no errors). Tests cannot run locally — the SDK on this machine is .NET 10 only and the test project targets net8.0 — but CI runs the matrix on ubuntu-latest, windows-latest, and macos-latest and will exercise them.

🤖 Generated with Claude Code

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>
@marius-bughiu

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: marius-bughiu <11870708+marius-bughiu@users.noreply.github.com>

Copilot AI commented May 11, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done in ec73ccc. The only conflict was in CHANGELOG.md (the [1.2.0] Added section had both the ContainsValue entries from this branch and the IEnumerable<T> set constructor entries from main). Both sets of entries are now preserved in the merged changelog.

@marius-bughiu
marius-bughiu merged commit 59bcb37 into main May 11, 2026
@marius-bughiu
marius-bughiu deleted the feat/contains-value 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 ContainsValue on IntDictionary, LongDictionary, and CelerityDictionary

2 participants