From 1e0ecc5abe83399dc253f2b5a87d3d36060623b9 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Sat, 3 Oct 2026 07:13:17 +0000 Subject: [PATCH 1/5] feat: add lastIndexOf method to array/uint64 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/lib/main.js | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index dd158c90cb94..23c09dba789b 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -749,6 +749,75 @@ setReadOnly( Uint64Array.prototype, 'get', function get( idx ) { return getUint64( this._buffer, idx ); }); +/** +* Returns the last index at which a given element can be found. +* +* @name lastIndexOf +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Uint64|bigint|number)} searchElement - element to find +* @param {integer} [fromIndex] - index at which to start searching backward (inclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); +* +* var idx = arr.lastIndexOf( new Uint64( 3 ) ); +* // returns 4 +* +* idx = arr.lastIndexOf( 3, 3 ); +* // returns 2 +* +* idx = arr.lastIndexOf( 5, 3 ); +* // returns -1 +* +* idx = arr.lastIndexOf( 2n, -3 ); +* // returns 1 +*/ +setReadOnly( Uint64Array.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) { + var words; + var buf; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( searchElement ) ) { + try { + searchElement = new Uint64( searchElement ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', searchElement ) ); + } + } + if ( arguments.length > 1 ) { + if ( !isIntegerPrimitive( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex >= this._length ) { + fromIndex = this._length - 1; + } else if ( fromIndex < 0 ) { + fromIndex += this._length; + } + } else { + fromIndex = this._length - 1; + } + words = [ 0, 0 ]; + toWords( searchElement, words, 1, 0 ); + buf = this._buffer; + for ( i = fromIndex; i >= 0; i-- ) { + idx = 2 * i; + if ( words[ 0 ] === buf[ idx+indices.HIGH ] && words[ 1 ] === buf[ idx+indices.LOW ] ) { // eslint-disable-line max-len + return i; + } + } + return -1; +}); + /** * Number of array elements. * From 2a2ccaedf42cd2b26fbcdd3be789ccfd28d29b11 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Sat, 3 Oct 2026 07:19:08 +0000 Subject: [PATCH 2/5] test: add test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../array/uint64/test/test.last_index_of.js | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js b/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js new file mode 100644 index 000000000000..a34a4d837f9d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js @@ -0,0 +1,251 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINTS = hasBigIntSupport(); +var opts = { + 'skip': !HAS_BIGINTS +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `lastIndexOf` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'lastIndexOf' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.lastIndexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 3.14, + -5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array(); + idx = arr.lastIndexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a 64-bit unsigned integer is not found', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( 10 ); + idx = arr.lastIndexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + idx = arr.lastIndexOf( new Uint64( 2 ) ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a nonnegative integer', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + + idx = arr.lastIndexOf( 2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( 4 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a bigint', opts, function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + + idx = arr.lastIndexOf( BigInt( 2 ) ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( BigInt( 4 ) ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 3 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 4 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 2 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 3 ), 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), -3 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 3 ), -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 10 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 4 ), 10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); From 7efa81c8d95cd6be0631d0a692cc243a39b11386 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Sat, 3 Oct 2026 07:20:19 +0000 Subject: [PATCH 3/5] bench: add benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark/benchmark.last_index_of.js | 52 ++++++++++ .../benchmark.last_index_of.length.js | 95 +++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js new file mode 100644 index 000000000000..8f97527581e8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:lastIndexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js new file mode 100644 index 000000000000..15a8167d6183 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:lastIndexOf:len=%d', pkg, len ), f ); + } +} + +main(); From aaedbab51765917ea9e57c77e24ed3f99eaf98c9 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Sat, 3 Oct 2026 07:23:45 +0000 Subject: [PATCH 4/5] docs: add docs --- .../@stdlib/array/uint64/docs/repl.txt | 30 +++++++++++++++++++ .../array/uint64/docs/types/index.d.ts | 26 ++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index 6dd3c27d5987..046ab6427d6c 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -299,6 +299,36 @@ [ 2n ] +{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) + Returns the last index at which a given element can be found. + + If method does not find a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: Uint64|number|bigint + Search element. + + fromIndex: integer (optional) + Array index at which to start the search backward. If provided a + negative value, the method resolves the start index relative to the + last array element. Default: -1. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3, 2 ] ) + [ 1n, 2n, 3n, 2n ] + > var idx = arr.lastIndexOf( new {{alias:@stdlib/number/uint64/ctor}}( 2 ) ) + 3 + > idx = arr.lastIndexOf( 2, 2 ) + 1 + + {{alias}}.prototype.set( v[, i] ) Sets one or more array elements. diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 73e7941a80c5..06cb3c484c81 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts @@ -482,6 +482,32 @@ declare class Uint64Array implements Uint64ArrayInterface { */ get( i: number ): Uint64 | void; + /** + * Returns the last index at which a given element can be found. + * + * @param searchElement - element to find + * @param fromIndex - index at which to start searching backward (inclusive) + * @returns index or -1 + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); + * + * var idx = arr.lastIndexOf( new Uint64( 3 ) ); + * // returns 4 + * + * idx = arr.lastIndexOf( 3, 3 ); + * // returns 2 + * + * idx = arr.lastIndexOf( 5, 3 ); + * // returns -1 + * + * idx = arr.lastIndexOf( 2n, -3 ); + * // returns 1 + */ + lastIndexOf( searchElement: Uint, fromIndex?: number ): number; + /** * Sets an array element. * From 715ca23beba09781ac03b998226a3f18657d4ed9 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Sat, 3 Oct 2026 07:24:44 +0000 Subject: [PATCH 5/5] docs: add readme --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/README.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index f0d84ef9697c..9873c2b71c53 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -342,6 +342,39 @@ var z = arr.get( 100 ); // returns undefined ``` + + +#### Uint64Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) + +Returns the last index at which a given element can be found. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); + +var idx = arr.lastIndexOf( new Uint64( 3 ) ); +// returns 4 + +idx = arr.lastIndexOf( 3, 3 ); +// returns 2 + +idx = arr.lastIndexOf( 2, -3 ); +// returns 1 +``` + +If `searchElement` is not present in the array, the method returns `-1`. + +```javascript +var arr = new Uint64Array( [ 1, 2 ] ); + +var idx = arr.lastIndexOf( 3 ); +// returns -1 + +idx = arr.lastIndexOf( 2, 0 ); +// returns -1 +``` + #### Uint64Array.prototype.set( value\[, i] )