Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 30, 2024
1 parent 1bebb2c commit c73f7c6
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 7 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<section class="release" id="unreleased">

## Unreleased (2024-11-27)
## Unreleased (2024-11-30)

<section class="features">

### Features

- [`c8143c4`](https://github.com/stdlib-js/stdlib/commit/c8143c4f1f5254c67916bb1548aa5443d282e263) - add `lastIndexOf` method to `array/fixed-endian-factory` [(#3281)](https://github.com/stdlib-js/stdlib/pull/3281)
- [`9db1815`](https://github.com/stdlib-js/stdlib/commit/9db181520dc74f28aab70a73aac64202cf7560ce) - add `indexOf` method to `array/fixed-endian-factory` [(#3279)](https://github.com/stdlib-js/stdlib/pull/3279)
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270)
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241)
Expand All @@ -26,9 +27,9 @@

### Closed Issues

A total of 5 issues were closed in this release:
A total of 6 issues were closed in this release:

[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3146](https://github.com/stdlib-js/stdlib/issues/3146), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3146](https://github.com/stdlib-js/stdlib/issues/3146), [#3149](https://github.com/stdlib-js/stdlib/issues/3149), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)

</section>

Expand All @@ -40,6 +41,7 @@ A total of 5 issues were closed in this release:

<details>

- [`c8143c4`](https://github.com/stdlib-js/stdlib/commit/c8143c4f1f5254c67916bb1548aa5443d282e263) - **feat:** add `lastIndexOf` method to `array/fixed-endian-factory` [(#3281)](https://github.com/stdlib-js/stdlib/pull/3281) _(by Aditya Sapra, Philipp Burckhardt)_
- [`9db1815`](https://github.com/stdlib-js/stdlib/commit/9db181520dc74f28aab70a73aac64202cf7560ce) - **feat:** add `indexOf` method to `array/fixed-endian-factory` [(#3279)](https://github.com/stdlib-js/stdlib/pull/3279) _(by Aditya Sapra, Athan Reines)_
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - **feat:** add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270) _(by Aayush Khanna, Athan Reines)_
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - **feat:** add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241) _(by Kshitij-Dale, Athan Reines)_
Expand All @@ -62,12 +64,13 @@ A total of 5 issues were closed in this release:

### Contributors

A total of 4 people contributed to this release. Thank you to the following contributors:
A total of 5 people contributed to this release. Thank you to the following contributors:

- Aayush Khanna
- Aditya Sapra
- Athan Reines
- Kshitij-Dale
- Philipp Burckhardt

</section>

Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,38 @@ var idx = arr.indexOf( 5.0 );
// returns -1
```

<a name="method-last-index-of"></a>

#### TypedArrayFE.prototype.lastIndexOf( searchElement\[, fromIndex] )

Returns the last index at which a given element can be found in the array.

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );

var idx = arr.lastIndexOf( 2.0 );
// returns 4

idx = arr.lastIndexOf( 2.0, 3 );
// returns 1

idx = arr.lastIndexOf( 2.0, -2 );
// returns 1
```

If `searchElement` is not present in the array, the method returns `-1`.

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );

var idx = arr.lastIndexOf( 5.0 );
// returns -1
```

<a name="method-map"></a>

#### TypedArray.prototype.map( callbackFn\[, thisArg] )
Expand Down
56 changes: 56 additions & 0 deletions benchmark/benchmark.last-index-of.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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-harness' );
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
var factory = require( './../lib' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// MAIN //

bench( pkg+':lastIndexOf', function benchmark( b ) {
var arr;
var idx;
var i;

arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = arr.lastIndexOf( 5.0, arr.length - 1 );
if ( typeof idx !== 'number' ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( idx ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});
103 changes: 103 additions & 0 deletions benchmark/benchmark.last-index-of.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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-harness' );
var pow = require( '@stdlib/math-base-special-pow' );
var zeroTo = require( '@stdlib/array-zero-to' );
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
var factory = require( './../lib' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var idx;
var v;
var i;

v = len - 1;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = arr.lastIndexOf( v );
if ( typeof idx !== 'number' ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( idx ) ) {
b.fail( 'should return an integer' );
}
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( pkg+':lastIndexOf:len='+len, f );
}
}

main();
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,51 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
return -1;
});

/**
* Returns the index of the last occurrence of a given element.
*
* @private
* @name lastIndexOf
* @memberof TypedArray.prototype
* @type {Function}
* @param {*} searchElement - element to search for
* @param {integer} [fromIndex=this._length-1] - starting index (inclusive)
* @throws {TypeError} `this` must be a typed array instance
* @throws {TypeError} second argument must be an integer
* @returns {integer} index or -1
*/
setReadOnly( TypedArray.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) {
var buf;
var i;

if ( !isTypedArray( this ) ) {
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[ 0 ] ], CTOR_NAME ) );
}
if ( arguments.length > 1 ) {
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
if ( fromIndex < 0 ) {
fromIndex += this._length;
}
if ( fromIndex < 0 ) {
return -1;
}
if ( fromIndex >= this._length ) {
fromIndex = this._length - 1;
}
} else {
fromIndex = this._length - 1;
}
buf = this._buffer;
for ( i = fromIndex; i >= 0; i-- ) {
if ( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) === searchElement ) {
return i;
}
}
return -1;
});

/**
* Number of array elements.
*
Expand Down
Loading

0 comments on commit c73f7c6

Please sign in to comment.