refactor: dedupe narrowest-unsigned-ptype selection into one helper#273
Merged
Conversation
Three writer-side encoders each hand-rolled byte-for-byte identical logic to pick the narrowest unsigned PType (U8/U16/U32) that fits a non-negative value: BitpackedEncodingEncoder.chooseIdxPtype, SparseEncodingEncoder. chooseIdxPtype, and FsstEncodingEncoder.narrowestUnsignedPType. A future tiering change (e.g. a U64 tier) would have to touch three sites and could silently drift. Extract once as PType.narrowestUnsigned(long), matching the enum's existing static-factory/classification idiom (fromOrdinal, isUnsigned). The long parameter accepts all current int call sites unchanged and leaves room for a wider tier. Delete the three private duplicates; all five call sites now delegate. Boundary tests (0, 0xFF, 0x100, 0xFFFF, 0x10000, 0xFFFFFFFF) added to PTypeTest. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
BitpackedEncodingEncoder,SparseEncodingEncoder,FsstEncodingEncoder) each hand-rolled byte-for-byte identical logic to pick the narrowest unsignedPType(U8/U16/U32) fitting a value — flagged in review of Raincloud triage round 268 269 #271.PType.narrowestUnsigned(long), matching the enum's existing static-factory/classification idiom (fromOrdinal,isUnsigned). All 5 call sites now delegate; the three private duplicates are deleted.Test plan
./mvnw test -pl core,writer -am— BUILD SUCCESS, 1702 tests, 0 failures./mvnw verify -pl core,writer -am -DskipITs— BUILD SUCCESS (checkstyle-bound run)./mvnw javadoc:javadoc -pl core— zero warnings on the new methodPTypeTest(0, 0xFF, 0x100, 0xFFFF, 0x10000, 0xFFFFFFFF)🤖 Generated with Claude Code