bardrop opened a new pull request, #532: URL: https://github.com/apache/arrow-js/pull/532
## What's Changed `Vector.indexOf(element, offset)` and `includes(element, offset)` did not respect `offset`: - Single-chunk vectors: the constructor installed `this.indexOf = (index) => indexOf(unchunkedData, index)`, so the offset was dropped. - Chunked vectors: `wrapChunkedIndexOf` started 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 returned `null` from `binarySearch` instead of `-1`. - Searching for `null` with an offset returned an index relative to the offset (`indexOfNull` started counting at 0 and read `data.length` bits from the offset), and the `Null` type ignored the offset. Changes: - The single-chunk `indexOf` passes the offset through. - `chunkedIndexOf` starts the total at the length of the chunks before the start chunk, and an out-of-range offset gives `-1`. - New `toIndexOfStart()` turns the offset into a start index the same way `Array.prototype.indexOf` does (fractions truncated, negative counts back from the end). Without it, passing the offset through would make `indexOf(null, -1)` return `-1`-style garbage on single-chunk vectors, where it used to be ignored. - `indexOfNull` and the `Null` type visitor return indices in the whole data. The new test in `test/unit/vector/vector-tests.ts` compares `indexOf` and `includes` with `Array.prototype.indexOf` / `includes` for one chunk, two chunks, with nulls, and the `Null` type, over offsets like `1.5`, `99`, `-1`, `-99`, `NaN` and `±Infinity`. All 5 cases fail on main and pass with this change. The full `src` jest run (7250 tests), eslint and `tsc` on 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.indexOf` myself, and can answer questions about it. Closes #531. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
