Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,38 @@ var idx = arr.indexOf( 5.0 );
// returns -1
```

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

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

Returns `true` if the specified `searchElement` is present 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.includes( 2.0 );
// returns true

idx = arr.includes( 2.0, 2 );
// returns true

idx = arr.includes( 2.0, -4 );
// returns true
```

If the specified `searchElement` is not present in the array, the method returns `false`.

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

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

var idx = arr.includes( 5.0 );
// returns false
```

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

#### TypedArray.prototype.map( callbackFn\[, thisArg] )
Expand Down
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' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var factory = require( './../lib' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// MAIN //

bench( pkg+':includes', function benchmark( b ) {
var result;
var arr;
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++ ) {
result = arr.includes( 5.0, 0 );
if ( typeof result !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( result ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
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' );
var pow = require( '@stdlib/math/base/special/pow' );
var zeroTo = require( '@stdlib/array/zero-to' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).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 result;
var v;
var i;

v = len - 1;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
result = arr.includes( v );
if ( typeof result !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( result ) ) {
b.fail( 'should return a boolean' );
}
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+':includes:len='+len, f );
}
}

main();
41 changes: 41 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,47 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
}
return -1;
});
/**
* Returns `true` if the specified `searchElement` is present in the array.
*
* @private
* @name includes
* @memberof TypedArray.prototype
* @type {Function}
* @param {*} searchElement - element to search for
* @param {integer} [fromIndex=0] - starting index (inclusive)
* @throws {TypeError} `this` must be a typed array instance
* @throws {TypeError} second argument must be an integer
* @returns {boolean} boolean indicating that `searchElement` is found
*/
setReadOnly( TypedArray.prototype, 'includes', function includes( 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 ) {
fromIndex = 0;
}
}
} else {
fromIndex = 0;
}
buf = this._buffer;
for ( i = fromIndex; i < this._length; i++ ) {
if ( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) === searchElement ) {
return true;
}
}
return false;
});

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