Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,62 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the
- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished.
- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object.

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

#### Uint64Array.prototype.filter( predicate\[, thisArg] )

Returns a new array containing the elements of an array which pass a test implemented by a predicate function.

```javascript
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
var Number = require( '@stdlib/number/ctor' );

function predicate( v ) {
return ( isEven( Number( v ) ) );
}

var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] );

var out = arr.filter( predicate );
// returns <Uint64Array>[ 2n, 4n, 6n ]

var len = out.length;
// returns 3
```

The `predicate` function is provided three arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`.

```javascript
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
var Number = require( '@stdlib/number/ctor' );

function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && isEven( Number( v ) ) );
}

var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] );

var context = {
'count': 0
};

var out = arr.filter( predicate, context );
// returns <Uint64Array>[ 2n, 4n, 6n ]

var len = out.length;
// returns 3

var count = context.count;
// returns 6
```

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

#### Uint64Array.prototype.get( i )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @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 isUint64 = require( '@stdlib/assert/is-uint64' );
var isUint64Array = require( '@stdlib/assert/is-uint64array' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

bench( format( '%s:filter', pkg ), function benchmark( b ) {
var arr;
var out;
var i;

arr = new Uint64Array( 10 );

// Benchmark worst case scenario (i.e., the predicate passes for every element, so every element is copied to the output array)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.filter( predicate );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint64Array( out ) ) {
b.fail( 'should return a Uint64Array' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return isUint64( v );
}
});

bench( format( '%s::this_context:filter', pkg ), function benchmark( b ) {
var arr;
var out;
var i;

arr = new Uint64Array( 10 );

// Benchmark worst case scenario (i.e., the predicate passes for every element, so every element is copied to the output array)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.filter( predicate, {} );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint64Array( out ) ) {
b.fail( 'should return a Uint64Array' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return isUint64( v );
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @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 isUint64 = require( '@stdlib/assert/is-uint64' );
var isUint64Array = require( '@stdlib/assert/is-uint64array' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// FUNCTIONS //

/**
* Predicate function.
*
* @private
* @param {Uint64} value - array element
* @returns {boolean} boolean indicating whether a value passes a test
*/
function predicate( value ) {
return isUint64( value );
}

/**
* 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 predicate passes for every element, so every element is copied to the output array)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.filter( predicate );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint64Array( out ) ) {
b.fail( 'should return a Uint64Array' );
}
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:filter:len=%d', pkg, len ), f );
}
}

main();
37 changes: 37 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,43 @@
true


{{alias}}.prototype.filter( predicate[, thisArg] )
Returns a new array containing the elements of an array which pass a test
implemented by a predicate function.

A predicate function is provided the following arguments:

- value: current array element.
- index: current array element index.
- arr: the array on which the method was called.

The returned array has the same data type as the host array.

Parameters
----------
predicate: Function
Predicate function which filters array elements. If a predicate function
returns a truthy value, an array element is included in the output
array; otherwise, an array element is not included in the output array.

thisArg: any (optional)
Execution context.

Returns
-------
out: Uint64Array
A new typed array.

Examples
--------
> function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); };
> var arr = new {{alias}}( [ 1, 2, 3, 4, 5, 6 ] );
> var out = arr.filter( predicate )
returns <Uint64Array>[ 2n, 4n, 6n ]
> var len = out.length
3


{{alias}}.prototype.get( i )
Returns an array element located at integer position (index) `i`.

Expand Down
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import ArrayBuffer = require( '@stdlib/array/buffer' );

// Define a union type representing both iterable and non-iterable iterators:
type Iterator = Iter | IterableIterator;

Check failure on line 31 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Iterator' is defined but never used

// Define a type representing a value from which a 64-bit unsigned integer can be derived:
type Uint = Uint64 | bigint | number;
Expand All @@ -36,7 +36,7 @@
/**
* Locale-specific configuration options.
*/
interface LocaleOptions<T = unknown> {

Check failure on line 39 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'LocaleOptions' is defined but never used
/**
* Configuration property.
*/
Expand Down Expand Up @@ -162,7 +162,7 @@
* @param arr - array on which the method was called
* @returns undefined
*/
type Callback<U> = NullaryCallback<U> | UnaryCallback<U> | BinaryCallback<U> | TernaryCallback<U>;

Check failure on line 165 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Callback' is defined but never used

/**
* Callback invoked for each element in an array.
Expand Down Expand Up @@ -206,7 +206,7 @@
* @param arr - array on which the method was called
* @returns transformed value
*/
type MapFcn<U> = NullaryMapFcn<U> | UnaryMapFcn<U> | BinaryMapFcn<U> | TernaryMapFcn<U>;

Check failure on line 209 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'MapFcn' is defined but never used

/**
* Reducer function invoked for each element in an array.
Expand Down Expand Up @@ -260,7 +260,7 @@
* @param arr - array on which the method was called
* @returns accumulated result
*/
type Reducer<U> = NullaryReducer<U> | UnaryReducer<U> | BinaryReducer<U> | TernaryReducer<U> | QuaternaryReducer<U>;

Check failure on line 263 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Reducer' is defined but never used

/**
* Comparator function.
Expand All @@ -269,7 +269,7 @@
* @param b - second value for comparison
* @returns number indicating comparison result
*/
type CompareFcn = ( a: Uint64, b: Uint64 ) => number;

Check failure on line 272 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'CompareFcn' is defined but never used

/**
* Class for creating a 64-bit unsigned integer array.
Expand Down Expand Up @@ -454,6 +454,31 @@
*/
entries(): TypedIterator<[number, Uint64]>;

/**
* Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
*
* @param predicate - test function
* @param thisArg - execution context
* @returns new array containing elements which pass a test implemented by a predicate function
*
* @example
* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
* var Number = require( '@stdlib/number/ctor' );
*
* function predicate( v ) {
* return ( isEven( Number( v ) ) );
* }
*
* var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] );
*
* var out = arr.filter( predicate );
* // returns <Uint64Array>[ 2n, 4n, 6n ]
*
* var len = out.length;
* // returns 3
*/
filter<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): Uint64Array;

/**
* Returns an array element.
*
Expand Down
50 changes: 50 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,56 @@
}
});

/**
* Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
*
* @name filter
* @memberof Uint64Array.prototype
* @type {Function}
* @param {Function} predicate - test function
* @param {*} [thisArg] - predicate function execution context
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
* @throws {TypeError} first argument must be a function
* @returns {Uint64Array} 64-bit unsigned integer array
*
* @example
* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
* var Number = require( '@stdlib/number/ctor' );
*
* function predicate( v ) {
* return ( isEven( Number( v ) ) );
* }
*
* var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] );
*
* var out = arr.filter( predicate );
* // returns <Uint64Array>[ 2n, 4n, 6n ]
*
* var len = out.length;
* // returns 3
*/
setReadOnly( Uint64Array.prototype, 'filter', function filter( predicate, thisArg ) {
var buf;
var out;
var i;
var u;
if ( !isUint64Array( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' );
}
if ( !isFunction( predicate ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
}
buf = this._buffer;
out = [];
for ( i = 0; i < this._length; i++ ) {
u = getUint64( buf, i );
if ( predicate.call( thisArg, u, i, this ) ) {
out.push( u );
}
}
return new this.constructor( out );
});

/**
* Returns an array element.
*
Expand Down Expand Up @@ -839,7 +889,7 @@
buf[ idx+indices.LOW ] = words[ 1 ];
return;
}
if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) {

Check warning on line 892 in lib/node_modules/@stdlib/array/uint64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 110. Maximum allowed is 80
if ( idx >= this._length ) {
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) );
}
Expand Down
Loading