Skip to content
Merged
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
40 changes: 40 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,44 @@ z = arr.at( -100 );
// returns undefined
```

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

#### Uint64Array.prototype.entries()

Returns an iterator for iterating over array key-value pairs.

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

var arr = [
new Uint64( 1 ),
new Uint64( 2 ),
new Uint64( 3 )
];
arr = new Uint64Array( arr );

// Create an iterator:
var it = arr.entries();

// Iterate over the key-value pairs...
var v = it.next().value;
// returns [ 0, <Uint64>[ 1n ] ]

v = it.next().value;
// returns [ 1, <Uint64>[ 2n ] ]

v = it.next().value;
// returns [ 2, <Uint64>[ 3n ] ]

var bool = it.next().done;
// returns true
```

Comment thread
kgryte marked this conversation as resolved.
The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties:

- **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-get"></a>

#### Uint64Array.prototype.get( i )
Expand Down Expand Up @@ -466,6 +504,8 @@ logEach( '%s', out );

<section class="links">

[mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[@stdlib/array/typed]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/typed
Expand Down
Original file line number Diff line number Diff line change
@@ -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 zeroTo = require( '@stdlib/array/zero-to' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

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

arr = new Uint64Array( zeroTo( 10, 'generic' ) );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.entries();
if ( typeof iter !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) {
b.fail( 'should return an iterator protocol-compliant object' );
}
b.pass( 'benchmark finished' );
b.end();
});
23 changes: 23 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,29 @@
<Uint64>[ 2n ]


{{alias}}.prototype.entries()
Returns an iterator for iterating over array key-value pairs.

Returns
-------
iterator: Iterator
Iterator for iterating over array key-value pairs.

Examples
--------
> var arr = new {{alias}}( [ 1, 2, 3 ] )
<Uint64Array>[ 1n, 2n, 3n ]
> var it = arr.entries();
> var v = it.next().value
[ 0, <Uint64>[ 1n ] ]
> v = it.next().value
[ 1, <Uint64>[ 2n ] ]
> v = it.next().value
[ 2, <Uint64>[ 3n ] ]
> var bool = it.next().done
true


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

Expand Down
35 changes: 34 additions & 1 deletion lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/// <reference types="@stdlib/types"/>

import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
import { Iterator as Iter, IterableIterator, TypedIterator } from '@stdlib/types/iter';
import { ArrayLike, Uint64Array as Uint64ArrayInterface } from '@stdlib/types/array';
import { Uint64 } from '@stdlib/types/number';
import ArrayBuffer = require( '@stdlib/array/buffer' );
Expand Down Expand Up @@ -426,6 +426,39 @@ declare class Uint64Array implements Uint64ArrayInterface {
*/
at( i: number ): Uint64 | void;

/**
* Returns an iterator for iterating over array key-value pairs.
*
* @returns iterator
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var arr = [
* new Uint64( 1 ),
* new Uint64( 2 ),
* new Uint64( 3 )
* ];
* arr = new Uint64Array( arr );
*
* // Create an iterator:
* var it = arr.entries();
*
* // Iterate over the key-value pairs...
* var v = it.next().value;
* // returns [ 0, <Uint64>[ 1n ] ]
*
* v = it.next().value;
* // returns [ 1, <Uint64>[ 2n ] ]
*
* v = it.next().value;
* // returns [ 2, <Uint64>[ 3n ] ]
*
* var bool = it.next().done;
* // returns true
*/
entries(): TypedIterator<[number, Uint64]>;

/**
* Returns an array element.
*
Expand Down
112 changes: 112 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,118 @@
*/
setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_ELEMENT );

/**
* Returns an iterator for iterating over array key-value pairs.
*
* @name entries
* @memberof Uint64Array.prototype
* @type {Function}
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
* @returns {Iterator} iterator
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var arr = [
* new Uint64( 1 ),
* new Uint64( 2 ),
* new Uint64( 3 )
* ];
* arr = new Uint64Array( arr );
*
* // Create an iterator:
* var it = arr.entries();
*
* // Iterate over the key-value pairs...
* var v = it.next().value;
* // returns [ 0, <Uint>[ 1n ] ]
*
* v = it.next().value;
* // returns [ 1, <Uint>[ 2n ] ]
*
* v = it.next().value;
* // returns [ 2, <Uint>[ 3n ] ]
*
* var bool = it.next().done;
* // returns true
*/
setReadOnly( Uint64Array.prototype, 'entries', function entries() {
var buffer;
var self;
var iter;
var len;
var FLG;
var i;
if ( !isUint64Array( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' );
}
self = this;
buffer = this._buffer;
len = this._length;

// Initialize an iteration index:
i = -1;

// Create an iterator protocol-compliant object:
iter = {};
setReadOnly( iter, 'next', next );
setReadOnly( iter, 'return', end );

if ( ITERATOR_SYMBOL ) {
setReadOnly( iter, ITERATOR_SYMBOL, factory );
}
return iter;

/**
* Returns an iterator protocol-compliant object containing the next iterated value.
*
* @private
* @returns {Object} iterator protocol-compliant object
*/
function next() {
i += 1;
if ( FLG || i >= len ) {
return {
'done': true
};
}
return {
'value': [ i, new getUint64( buffer, i ) ],
'done': false
};
}

/**
* Finishes an iterator.
*
* @private
* @param {*} [value] - value to return
* @returns {Object} iterator protocol-compliant object
*/
function end( value ) {
FLG = true;
if ( arguments.length ) {
return {
'value': value,
'done': true
};
}
return {
'done': true
};
}

/**
* Returns a new iterator.
*
* @private
* @returns {Iterator} iterator
*/
function factory() {
return self.entries();
}
});

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

Check warning on line 849 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 Expand Up @@ -797,7 +909,7 @@
// We need to copy source values...
tmp = new Uint32Array( sbuf.length );
for ( i = 0; i < sbuf.length; i++ ) {
tmp[ i ] = sbuf[ i ]; // TODO: handle accessor arrays

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

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: handle accessor arrays'
}
sbuf = tmp;
}
Expand Down
Loading
Loading