Repository navigation
Conversation
Single-chunk vectors dropped the offset argument. Chunked vectors returned an index relative to the chunk the search started in, and returned null when the offset was past the end. Offsets now follow Array.prototype.indexOf: fractions are truncated and negative values count back from the end. Searching for null with an offset also returns the index in the whole vector. Closes apache#531.
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.
What's Changed
Vector.indexOf(element, offset)andincludes(element, offset)did not respectoffset:this.indexOf = (index) => indexOf(unchunkedData, index), so the offset was dropped.wrapChunkedIndexOfstarted its running total at 0 even when the search began in a later chunk, so the result was chunk-local. An offset past the end returnednullfrombinarySearchinstead of-1.nullwith an offset returned an index relative to the offset (indexOfNullstarted counting at 0 and readdata.lengthbits from the offset), and theNulltype ignored the offset.Changes:
indexOfpasses the offset through.chunkedIndexOfstarts the total at the length of the chunks before the start chunk, and an out-of-range offset gives-1.toIndexOfStart()turns the offset into a start index the same wayArray.prototype.indexOfdoes (fractions truncated, negative counts back from the end). Without it, passing the offset through would let a negative offset reach the visitors (for exampleindexOf(null, -2)on a single chunk returned-2), where it used to be ignored.indexOfNulland theNulltype visitor return indices in the whole data.The new test in
test/unit/vector/vector-tests.tscomparesindexOfandincludeswithArray.prototype.indexOf/includesfor one chunk, two chunks, with nulls, and theNulltype, over offsets like1.5,99,-1,-99,NaNand±Infinity. All 5 cases fail on main and pass with this change. The fullsrcjest run (7250 tests), eslint andtscon the build tsconfigs pass.AI usage: I used an AI coding assistant (Claude) to help find the cause, write the fix and the test. I reviewed every line, checked the before/after output against
Array.prototype.indexOfmyself, and can answer questions about it.Closes #531.