Skip to content

Preserve destination bits outside BitSet.Copy's logical range - #243

Draft
liuyinchu wants to merge 1 commit into
bits-and-blooms:masterfrom
liuyinchu:fix-copy-preserve-tail
Draft

liuyinchu wants to merge 1 commit into
bits-and-blooms:masterfrom
liuyinchu:fix-copy-preserve-tail

Conversation

@liuyinchu

Copy link
Copy Markdown

Summary

Copy promises Go array-copy semantics and returns the smaller logical bit length, but it currently copies entire backing words. Copying a one-bit source into an already populated 64-bit destination therefore clears bits 1–63 even though it reports that only one bit was copied.

Copy only complete words within the logical range, then merge the remaining low bits into the destination's partial word. Save that source word before the bulk copy so overlapping backing slices retain Go copy semantics. Keep the existing destination padding cleanup.

This does not grow the destination or change the return count. CopyFull is unchanged.

Regression coverage

  • 72 source/destination length combinations around 0, 64 and 128 bits.
  • Exact copied bits, preserved destination tail, source immutability, destination length and cardinality.
  • Same-start and both shifted overlapping backing slices, including extra backing words beyond the source's logical length.
  • The tests fail in 23 subcases before the production change and pass after it.

Validation

Go 1.26.10, Linux amd64: go test -race -cover -count=1 ./..., go vet ./..., gofmt and git diff --check pass. Root statement coverage: 99.4%; generator: 94.2%. Linux/386 test binaries compile, but this host cannot execute them (exec format error). No claim is made that the entire upstream OS/Go-version CI matrix was executed.

Prepared with OpenAI Codex assistance and independently reviewed by a second agent. No human review is claimed.

This branch has not been deployed

No deployments
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.

1 participant