Skip to content

fix: Equal, Map lookup, and ContainsSeq correctness improvements#30

Merged
freeformz merged 2 commits intomainfrom
quick-fixes
Mar 7, 2026
Merged

fix: Equal, Map lookup, and ContainsSeq correctness improvements#30
freeformz merged 2 commits intomainfrom
quick-fixes

Conversation

@freeformz
Copy link
Copy Markdown
Owner

Summary

  • Equal optimization: Remove redundant Subset(b, a) call — when cardinalities are verified equal, a single Subset(a, b) check is sufficient to prove set equality
  • Map.Add/Remove optimization: Inline map key lookup (_, ok := s.set[m]) instead of calling the Contains method, eliminating a redundant method call per operation
  • ContainsSeq vacuous truth: Return true for empty sequences, matching mathematical convention (universal quantification over an empty domain is vacuously true) and consistent with ContainsAll() behavior
  • CLAUDE.md conventions: Document project patterns (zero-value style, tests-as-spec, mathematical correctness, conventional commits)

Test plan

  • All existing tests pass with -race
  • No gopls diagnostics
  • ContainsSeq behavior now consistent with ContainsAll for empty input

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings March 7, 2026 01:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens correctness and reduces overhead in core set helper functions, while documenting repository conventions in CLAUDE.md.

Changes:

  • Simplifies Equal to a single Subset(a, b) check after verifying equal cardinalities.
  • Makes ContainsSeq return true for an empty sequence (vacuous truth), aligning with ContainsAll.
  • Inlines map key lookups in Map.Add/Remove to avoid a redundant Contains call; documents project conventions in CLAUDE.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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Add writes to s.set without ensuring the map is initialized. If a Map is used via its zero value (e.g., var s Map[int]), Add will panic on s.set[m] = .... Consider initializing s.set when nil (similar to Clear) 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.

@freeformz freeformz merged commit 4fa1986 into main Mar 7, 2026
13 checks passed
@freeformz freeformz deleted the quick-fixes branch March 7, 2026 02:26
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.

2 participants