fix: Equal, Map lookup, and ContainsSeq correctness improvements#30
Merged
fix: Equal, Map lookup, and ContainsSeq correctness improvements#30
Conversation
…uous truth - Equal: remove redundant Subset(b,a) call — when cardinalities match, a single Subset(a,b) is sufficient to prove equality. - Map.Add/Remove: inline map lookup instead of calling Contains method, eliminating a redundant method call per operation. - ContainsSeq: return true for empty sequences (vacuous truth), matching mathematical convention and consistent with ContainsAll behavior. - CLAUDE.md: add Conventions section documenting project patterns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens correctness and reduces overhead in core set helper functions, while documenting repository conventions in CLAUDE.md.
Changes:
- Simplifies
Equalto a singleSubset(a, b)check after verifying equal cardinalities. - Makes
ContainsSeqreturntruefor an empty sequence (vacuous truth), aligning withContainsAll. - Inlines map key lookups in
Map.Add/Removeto avoid a redundantContainscall; documents project conventions inCLAUDE.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| set.go | Optimizes Equal and updates ContainsSeq empty-sequence semantics. |
| map.go | Inlines map lookups in Add/Remove to avoid extra method calls. |
| CLAUDE.md | Adds documented conventions (zero-value style, tests-as-spec, math semantics, conventional commits). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add test for ContainsSeq(nonEmptySet, emptySeq) returning true to lock in vacuous truth semantics. - Equal: inline iteration instead of calling Subset to avoid redundant Cardinality() calls (significant for SyncMap where Cardinality is O(n)). - CLAUDE.md: clarify zero-value style wording per Copilot suggestion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
map.go:66
Addwrites tos.setwithout ensuring the map is initialized. If aMapis used via its zero value (e.g.,var s Map[int]),Addwill panic ons.set[m] = .... Consider initializings.setwhen nil (similar toClear) before doing lookups/writes.
func (s *Map[M]) Add(m M) bool {
if _, ok := s.set[m]; ok {
return false
}
s.set[m] = struct{}{}
return true
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Equaloptimization: Remove redundantSubset(b, a)call — when cardinalities are verified equal, a singleSubset(a, b)check is sufficient to prove set equalityMap.Add/Removeoptimization: Inline map key lookup (_, ok := s.set[m]) instead of calling theContainsmethod, eliminating a redundant method call per operationContainsSeqvacuous truth: Returntruefor empty sequences, matching mathematical convention (universal quantification over an empty domain is vacuously true) and consistent withContainsAll()behaviorCLAUDE.mdconventions: Document project patterns (zero-value style, tests-as-spec, mathematical correctness, conventional commits)Test plan
-raceContainsSeqbehavior now consistent withContainsAllfor empty input🤖 Generated with Claude Code