From e30fb57df858448ac96e9067c2611c6161b0c89e Mon Sep 17 00:00:00 2001 From: Divit Date: Fri, 5 Jun 2026 18:46:41 +0000 Subject: [PATCH 01/15] feat: add isUintArray type guard --- .../@stdlib/array/uint64/lib/main.js | 83 +++++++++++++++++++ .../@stdlib/array/uint64/package.json | 70 ++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/uint64/package.json diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js new file mode 100644 index 000000000000..a51c17bcd8ca --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -0,0 +1,83 @@ +/** +* @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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isString = require( '@stdlib/assert/is-string' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isEven = require( '@stdlib/math/base/assert/is-even' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var getter = require( '@stdlib/array/base/getter' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); +var format = require( '@stdlib/string/format' ); +var fromIterator = require( './from_iterator.js' ); +var fromIteratorMap = require( './from_iterator_map.js' ); +var fromArray = require( './from_array.js' ); + + +// VARIABLES // + +var BYTES_PER_ELEMENT = Uint32Array.BYTES_PER_ELEMENT * 2; +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating if a value is a unsigned typed array. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a unsigned typed array +*/ +function isUintArray( value ) { + return ( + value instanceof Uint64Array || + ( + typeof value === 'object' && + value !== null && + ( + value.constructor.name === 'Uint8Array' || + value.constructor.name === 'Uint16Array' || + value.constructor.name === 'Uint32Array' || + value.constructor.name === 'Uint64Array' + ) && + typeof value._length === 'number' && // eslint-disable-line no-underscore-dangle + + // NOTE: we don't perform a more rigorous test here for a typed array for performance reasons, as robustly checking for a typed array instance could require walking the prototype tree and performing relatively expensive constructor checks... + typeof value._buffer === 'object' // eslint-disable-line no-underscore-dangle + ) + ); +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/uint64/package.json b/lib/node_modules/@stdlib/array/uint64/package.json new file mode 100644 index 000000000000..4613f632c32e --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/array/uint64", + "version": "0.0.0", + "description": "Uint64Array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "uint64array", + "uint64", + "uint64_t", + "integer", + "int", + "uint", + "unsigned", + "long" + ] +} From 719217cc63e2fb0b3587eb499dbbc98f124c264a Mon Sep 17 00:00:00 2001 From: Divit Date: Tue, 9 Jun 2026 08:59:29 +0000 Subject: [PATCH 02/15] feat: add constructor --- .../@stdlib/array/uint64/lib/main.js | 257 +++++++++++++++++- 1 file changed, 254 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index a51c17bcd8ca..0906f784ec44 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable no-restricted-syntax, no-invalid-this */ - 'use strict'; // MODULES // @@ -31,6 +29,8 @@ var isArray = require( '@stdlib/assert/is-array' ); var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; var isString = require( '@stdlib/assert/is-string' ); var isFunction = require( '@stdlib/assert/is-function' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isBigInt = require( '@stdlib/assert/is-bigint' ).isPrimitive; var isEven = require( '@stdlib/math/base/assert/is-even' ); var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); @@ -38,6 +38,7 @@ var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); var Uint32Array = require( '@stdlib/array/uint32' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); var floor = require( '@stdlib/math/base/special/floor' ); var getter = require( '@stdlib/array/base/getter' ); var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); @@ -70,6 +71,7 @@ function isUintArray( value ) { value !== null && ( value.constructor.name === 'Uint8Array' || + value.constructor.name === 'Uint8ClampedArray' || value.constructor.name === 'Uint16Array' || value.constructor.name === 'Uint32Array' || value.constructor.name === 'Uint64Array' @@ -80,4 +82,253 @@ function isUintArray( value ) { typeof value._buffer === 'object' // eslint-disable-line no-underscore-dangle ) ); -} \ No newline at end of file +} + +/** +* Returns a boolean indicating if a value is a unsigned 32-bit typed array constructor. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a unsigned 32-bit typed array constructor +*/ +function isComplexArrayConstructor( value ) { + return ( + value === Uint64Array || + + // NOTE: weaker test in order to avoid a circular dependency with Uint32Array... + value.name === 'Uint32Array' + ); +} + +/** +* Retrieves a unsigned 64-bit integer from a unsigned 32-bit array buffer. +* +* @private +* @param {Uint32Array} buf - array buffer +* @param {NonNegativeInteger} idx - element index +* @returns {Uint64} unsigned 64-bit integer +*/ +function getUint64( buf, idx ) { + idx *= 2; + return new Uint64( buf[ idx ], buf[ idx+1 ] ); +} + + +// MAIN // + +/** +* unsigned 64-bit integer array constructor. +* +* @constructor +* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or iterable +* @param {NonNegativeInteger} [byteOffset=0] - byte offset +* @param {NonNegativeInteger} [length] - view length +* @throws {RangeError} ArrayBuffer byte length must be a multiple of `8` +* @throws {RangeError} array-like object and typed array input arguments must have a length which is a multiple of two +* @throws {TypeError} if provided only a single argument, must provide a valid argument +* @throws {TypeError} byte offset must be a nonnegative integer +* @throws {RangeError} byte offset must be a multiple of `8` +* @throws {TypeError} view length must be a positive multiple of `8` +* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements +* @throws {TypeError} an iterator must return a two element array containing high and low word or a unsigned 64-bit integer +* @returns {Uint64Array} unsigned 64-bit integer array +* +* @example +* var arr = new Uint64Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Uint64Array( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Uint64Array( [ 1234, 5678 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Uint64Array( buf ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Uint64Array( buf, 16 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 64 ); +* var arr = new Uint64Array( buf, 16, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +function Uint64Array() { + var byteOffset; + var nargs; + var buf; + var len; + + nargs = arguments.length; + if ( !(this instanceof Uint64Array) ) { + if ( nargs === 0 ) { + return new Uint64Array(); + } + if ( nargs === 1 ) { + return new Uint64Array( arguments[0] ); + } + if ( nargs === 2 ) { + return new Uint64Array( arguments[0], arguments[1] ); + } + return new Uint64Array( arguments[0], arguments[1], arguments[2] ); + } + // Create the underlying data buffer... + if ( nargs === 0 ) { + buf = new Uint32Array( 0 ); // backward-compatibility + } else if ( nargs === 1 ) { + if ( isNonNegativeInteger( arguments[0] ) ) { + buf = new Uint32Array( arguments[0]*2 ); + } else if ( isCollection( arguments[0] ) ) { + buf = arguments[ 0 ]; + len = buf.length; + + // If provided a "generic" array, peak at the first value, and, if the value is a unsigned 64-bit integer, try to process as an array of unsigned 64-bit integer, falling back to "normal" typed array initialization if we fail and ensuring consistency if the first value had not been a unsigned 64-bit integer... + if ( len && isArray( buf ) && isBigInt( buf[0] ) ) { + buf = fromArray( new Uint32Array( len*2 ), buf ); + if ( buf === null ) { + // We failed and we are now forced to allocate a new array :-( + if ( !isEven( len ) ) { + throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); + } + // We failed, so fall back to directly setting values... + buf = new Uint32Array( arguments[0] ); + } + } else { + if ( Uint8Array( buf ) ) { + + } else if ( Uint8ClampedArray( buf ) ) { + + } else if ( Uint16Array( buf ) ) { + + } else if ( Uint32Array( buf ) ) { + + } else if ( Uint64Array( buf ) ) { + + } else if ( !isEven( len ) ) { + throw new RangeError( format( 'invalid argument. Array-like object and typed array arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); + } + buf = new Uint32Array( buf ); + } + } else if ( isArrayBuffer( arguments[0] ) ) { + buf = arguments[ 0 ]; + if ( !isInteger( buf.byteLength/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, buf.byteLength ) ); + } + buf = new Uint32Array( buf ); + } else if ( isObject( arguments[0] ) ) { + buf = arguments[ 0 ]; + if ( HAS_ITERATOR_SYMBOL === false ) { + throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', buf ) ); + } + if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = buf[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = fromIterator( buf ); + if ( buf instanceof Error ) { + throw buf; + } + buf = new Uint32Array( buf ); + } else { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arguments[0] ) ); + } + } else { + buf = arguments[ 0 ]; + if ( !isArrayBuffer( buf ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) ); + } + byteOffset = arguments[ 1 ]; + if ( !isNonNegativeInteger( byteOffset ) ) { + throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) ); + } + if ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) ); + } + if ( nargs === 2 ) { + len = buf.byteLength - byteOffset; + if ( !isInteger( len/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) ); + } + buf = new Uint32Array( buf, byteOffset ); + } else { + len = arguments[ 2 ]; + if ( !isNonNegativeInteger( len ) ) { + throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) ); + } + if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len*BYTES_PER_ELEMENT ) ); + } + buf = new Uint32Array( buf, byteOffset, len*2 ); + } + } + setReadOnly( this, '_buffer', buf ); + setReadOnly( this, '_length', buf.length/2 ); + + return this; +} + +/** +* Size (in bytes) of each array element. +* +* @name BYTES_PER_ELEMENT +* @memberof Uint64Array +* @readonly +* @type {PositiveInteger} +* @default 16 +* +* @example +* var nbytes = Uint64Array.BYTES_PER_ELEMENT; +* // returns 16 +*/ +setReadOnly( Uint64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); + +/** +* Constructor name. +* +* @name name +* @memberof Uint64Array +* @readonly +* @type {string} +* @default 'Uint64Array' +* +* @example +* var name = Uint64Array.name; +* // returns 'Uint64Array' +*/ +setReadOnly( Uint64Array, 'name', 'Uint64Array' ); + + From 599874815be943d318b33729c978603c6b936a2b Mon Sep 17 00:00:00 2001 From: Divit Date: Tue, 9 Jun 2026 10:06:37 +0000 Subject: [PATCH 03/15] feat: add constructor --- lib/node_modules/@stdlib/array/uint64/lib/main.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 0906f784ec44..ba759b0a387d 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -20,6 +20,7 @@ // MODULES // +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); var isCollection = require( '@stdlib/assert/is-collection' ); @@ -91,7 +92,7 @@ function isUintArray( value ) { * @param {*} value - value to test * @returns {boolean} boolean indicating if a value is a unsigned 32-bit typed array constructor */ -function isComplexArrayConstructor( value ) { +function isUint64ArrayConstructor( value ) { return ( value === Uint64Array || @@ -230,7 +231,7 @@ function Uint64Array() { } else if ( Uint8ClampedArray( buf ) ) { } else if ( Uint16Array( buf ) ) { - + } else if ( Uint32Array( buf ) ) { } else if ( Uint64Array( buf ) ) { @@ -330,5 +331,3 @@ setReadOnly( Uint64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); * // returns 'Uint64Array' */ setReadOnly( Uint64Array, 'name', 'Uint64Array' ); - - From c63d91a4b89701800678cb90762e0684d7215268 Mon Sep 17 00:00:00 2001 From: Divit Date: Thu, 11 Jun 2026 06:03:27 +0000 Subject: [PATCH 04/15] feat: static methods --- .../@stdlib/array/uint64/lib/main.js | 202 +++++++++++++++++- 1 file changed, 199 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index ba759b0a387d..b16da74febd2 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -30,8 +30,8 @@ var isArray = require( '@stdlib/assert/is-array' ); var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; var isString = require( '@stdlib/assert/is-string' ); var isFunction = require( '@stdlib/assert/is-function' ); +var isBigUint64Array = require( '@stdlib/assert/is-biguint64array' ); var isUint64 = require( '@stdlib/assert/is-uint64' ); -var isBigInt = require( '@stdlib/assert/is-bigint' ).isPrimitive; var isEven = require( '@stdlib/math/base/assert/is-even' ); var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); @@ -53,6 +53,8 @@ var fromArray = require( './from_array.js' ); var BYTES_PER_ELEMENT = Uint32Array.BYTES_PER_ELEMENT * 2; var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); +var HAS_BIGINT = hasBigIntSupport(); +var TWO_32 = 0x100000000; // 2^32 // FUNCTIONS // @@ -92,7 +94,7 @@ function isUintArray( value ) { * @param {*} value - value to test * @returns {boolean} boolean indicating if a value is a unsigned 32-bit typed array constructor */ -function isUint64ArrayConstructor( value ) { +function isUintArrayConstructor( value ) { return ( value === Uint64Array || @@ -215,7 +217,7 @@ function Uint64Array() { len = buf.length; // If provided a "generic" array, peak at the first value, and, if the value is a unsigned 64-bit integer, try to process as an array of unsigned 64-bit integer, falling back to "normal" typed array initialization if we fail and ensuring consistency if the first value had not been a unsigned 64-bit integer... - if ( len && isArray( buf ) && isBigInt( buf[0] ) ) { + if ( len && isArray( buf ) && isBigUint64Array( buf[0] ) ) { buf = fromArray( new Uint32Array( len*2 ), buf ); if ( buf === null ) { // We failed and we are now forced to allocate a new array :-( @@ -331,3 +333,197 @@ setReadOnly( Uint64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); * // returns 'Uint64Array' */ setReadOnly( Uint64Array, 'name', 'Uint64Array' ); + +/** +* Size (in bytes) of the array. +* +* @name byteLength +* @memberof Uint64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var byteLength = arr.byteLength; +* // returns 160 +*/ +setReadOnlyAccessor( Uint64Array.prototype, 'byteLength', function get() { + return this._buffer.byteLength; +}); + +/** +* Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. +* +* @name byteOffset +* @memberof Uint64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var byteOffset = arr.byteOffset; +* // returns 0 +*/ +setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { + return this._buffer.byteOffset; +}); + +/** +* Creates a new unsigned 64-bit integer array from an array-like object or an iterable. +* +* @name from +* @memberof Uint64Array +* @type {Function} +* @param {(Collection|Object)} src - array-like object or iterable +* @param {Function} [clbk] - callback to invoke for each source element +* @param {*} [thisArg] - context +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a unsigned 64-bit integer array +* @throws {TypeError} first argument must be an array-like object or an iterable +* @throws {TypeError} second argument must be a function +* @throws {RangeError} array-like objects must have a length which is a multiple of two +* @throws {TypeError} an iterator must return either a two element array containing high and low word or a unsigned 64-bit integer +* @throws {TypeError} when provided an iterator, a callback must return either a two element array containing high and low word or a unsigned 64-bit integer +* @returns {Uint64Array} unsigned 64-bit integer array +* +* @example +* var arr = Uint64Array.from( [ 1234, 5678 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = Uint64Array.from( [ new Uint64( 1234, 5678 ) ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* function clbk( v ) { +* return new Uint64( v.hi*2, v.lo*2 ); +* } +* +* var arr = Uint64Array.from( [ new Uint64( 1234, 5678 ) ], clbk ); +* // returns +* +* var len = arr.length; +* // returns 1 +*/ +setReadOnly( Uint64Array, 'from', function from( src ) { + var thisArg; + var nargs; + var clbk; + var out; + var buf; + var tmp; + var get; + var len; + var flg; + var v; + var i; + var j; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isUintArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a unsigned 64-bit integer array.' ); + } + nargs = arguments.length; + if ( nargs > 1 ) { + clbk = arguments[ 1 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + } + if ( nargs > 2 ) { + thisArg = arguments[ 2 ]; + } + } + if ( isUintArray( src ) ) { + len = src.length; + if ( clbk ) { + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + j = 0; + for ( i = 0; i < len; i++ ) { + v = clbk.call( thisArg, src.get( i ), i ); + if ( isUint64( v ) ) { + buf[ j + indices.HIGH ] = v.hi; + buf[ j + indices.LOW ] = v.lo; + } else if ( isArrayLikeObject( v ) && v.length >= 2 ) { + buf[ j + indices.HIGH ] = v[ 0 ]; + buf[ j + indices.LOW ] = v[ 1 ]; + } else { + throw new TypeError( format( 'invalid argument. Callback must return either a two element array containing high and low word or a unsigned 64-bit integer. Value: `%s`.', v ) ); + } + j += 2; // stride + } + return out; + } + return new this( src ); + } + if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len + buf = src[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + } + if ( clbk ) { + tmp = fromIteratorMap( buf, clbk, thisArg ); + } else { + tmp = fromIterator( buf ); + } + if ( tmp instanceof Error ) { + throw tmp; + } + len = tmp.length / 2; + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ (i*2) + indices.HIGH ] = tmp[ i*2 ]; + buf[ (i*2) + indices.LOW ] = tmp[ (i*2)+1 ]; + } + return out; + } + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); +}); + +/** +* Creates a new unsigned 64-bit integer array from a variable number of arguments. +* +* @name of +* @memberof Uint64Array +* @type {Function} +* @param {...*} element - array elements +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a unsigned 64-bit integer array +* @returns {Uint64Array} 128-bit unsigned 64-bit integer array +* +* @example +* var arr = Uint64Array.of( 1234, 5678, 4321, 8765 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +setReadOnly( Uint64Array, 'of', function of() { + var args; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isUintArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a unsigned 64-bit integer array.' ); + } + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return new this( args ); +}); \ No newline at end of file From b329b2b81a83f69485171e854a108400974ce4ed Mon Sep 17 00:00:00 2001 From: Divit Date: Thu, 11 Jun 2026 07:56:34 +0000 Subject: [PATCH 05/15] feat: add helpers --- .../@stdlib/array/uint64/lib/from_array.js | 60 ++++++++++++++++ .../@stdlib/array/uint64/lib/from_iterator.js | 63 +++++++++++++++++ .../array/uint64/lib/from_iterator_map.js | 68 +++++++++++++++++++ .../@stdlib/array/uint64/lib/indices.js | 47 +++++++++++++ .../@stdlib/array/uint64/lib/main.js | 1 + 5 files changed, 239 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/from_array.js create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/indices.js diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_array.js b/lib/node_modules/@stdlib/array/uint64/lib/from_array.js new file mode 100644 index 000000000000..20aa3e428161 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_array.js @@ -0,0 +1,60 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var indices = require( './indices.js' ); + + +// MAIN // + +/** +* Returns a strided array of high and low words.. +* +* @private +* @param {Uint32Array} buf - output array +* @param {Array} arr - array containing unsigned 64-bit integers +* @returns {(Uint32Array|null)} output array or null +*/ +function fromArray( buf, arr ) { + var len; + var v; + var i; + var j; + + len = arr.length; + j = 0; + for ( i = 0; i < len; i++ ) { + v = arr[ i ]; + if ( !isUint64( v ) ) { + return null; + } + buf[ j + indices.HIGH ] = v.hi; + buf[ j + indices.LOW ] = v.lo; + j += 2; // stride + } + return buf; +} + + +// EXPORTS // + +module.exports = fromArray; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js new file mode 100644 index 000000000000..e6be0306897d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js @@ -0,0 +1,63 @@ +/** +* @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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @returns {(Array|TypeError)} array or an error +*/ +function fromIterator( it ) { + var out; + var v; + var z; + + out = []; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + z = v.value; + if ( isArrayLikeObject( z ) && z.length >= 2 ) { + out.push( z[ 0 ], z[ 1 ] ); + } else if ( isUint64( z ) ) { + out.push( z.hi, z.lo ); + } else { + return new TypeError( format( 'invalid argument. An iterator must return either a two-element array containing high and low word or a unsigned 64-bit integer. Value: `%s`.', z ) ); + } + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js new file mode 100644 index 000000000000..2921fcde41ad --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @param {Function} clbk - callback to invoke for each iterated value +* @param {*} thisArg - invocation context +* @returns {(Array|TypeError)} array or an error +*/ +function fromIteratorMap( it, clbk, thisArg ) { + var out; + var v; + var z; + var i; + + out = []; + i = -1; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + i += 1; + z = clbk.call( thisArg, v.value, i ); + if ( isArrayLikeObject( z ) && z.length >= 2 ) { + out.push( z[ 0 ], z[ 1 ] ); + } else if ( isUint64( z ) ) { + out.push( z.hi, z.lo ); + } else { + return new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', z ) ); + } + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/indices.js b/lib/node_modules/@stdlib/array/uint64/lib/indices.js new file mode 100644 index 000000000000..57341d75b278 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/indices.js @@ -0,0 +1,47 @@ +/** +* @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 isLittleEndian = require( '@stdlib/assert/is-little-endian' ); + + +// MAIN // + +var indices; +var HIGH; +var LOW; + +if ( isLittleEndian === true ) { + HIGH = 1; // second index + LOW = 0; // first index +} else { + HIGH = 0; // first index + LOW = 1; // second index +} +indices = { + 'HIGH': HIGH, + 'LOW': LOW +}; + + +// EXPORTS // + +module.exports = indices; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index b16da74febd2..c8142cd58b3e 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -44,6 +44,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); var getter = require( '@stdlib/array/base/getter' ); var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); var format = require( '@stdlib/string/format' ); +var indices = require( './indices.js' ); var fromIterator = require( './from_iterator.js' ); var fromIteratorMap = require( './from_iterator_map.js' ); var fromArray = require( './from_array.js' ); From d7e1be2c714a2c3412b9e36b0af7f9a6a563b560 Mon Sep 17 00:00:00 2001 From: Divit Date: Thu, 11 Jun 2026 08:47:15 +0000 Subject: [PATCH 06/15] feat: add getter and setter --- .../@stdlib/array/uint64/lib/main.js | 216 +++++++++++++++++- 1 file changed, 215 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index c8142cd58b3e..0cebf7eb04d8 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -527,4 +527,218 @@ setReadOnly( Uint64Array, 'of', function of() { args.push( arguments[ i ] ); } return new this( args ); -}); \ No newline at end of file +}); + +/** +* Returns an array element. +* +* @name get +* @memberof Uint64Array.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - element index +* @throws {TypeError} `this` must be a unsigned 64-bit integer array +* @throws {TypeError} must provide a nonnegative integer +* @returns {(Uint64|void)} array element +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var z = arr.get( 0 ); +* // returns [ 0, 0 ] +* +* arr.set( [ 1234, 5678 ], 0 ); +* +* z = arr.get( 0 ); +* // returns [ 1234, 5678 ] +* +* z = arr.get( 100 ); +* // returns undefined +*/ +setReadOnly( Uint64Array.prototype, 'get', function get( idx ) { + if ( !isUintArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a unsigned 64-bit integer array.' ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + return getUint64( this._buffer, idx ); +}); + +/** +* Sets an array element. +* +* ## Notes +* +* - When provided a typed array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. +* +* In the other overlapping scenario, +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values as intended. +* +* @name set +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Collection|Complex|ComplexArray)} value - value(s) +* @param {NonNegativeInteger} [i=0] - element index at which to start writing values +* @throws {TypeError} `this` must be a unsigned 64-bit integer array +* @throws {TypeError} first argument must be either a unsigned 64-bit integer, an array-like object, or a unsigned 64-bit integer array +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} array-like objects must have a length which is a multiple of two +* @throws {RangeError} index argument is out-of-bounds +* @throws {RangeError} target array lacks sufficient storage to accommodate source values +* @returns {void} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var z = arr.get( 0 ); +* // returns [ 0, 0 ] +* +* arr.set( [ 1234, 5678 ], 0 ); +* +* z = arr.get( 0 ); +* // returns [ 1234, 5678 ] +*/ +setReadOnly( Uint64Array.prototype, 'set', function set( value ) { + /* eslint-disable no-underscore-dangle */ + var sbuf; + var idx; + var buf; + var tmp; + var flg; + var N; + var v; + var i; + var j; + if ( !isUintArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a unsigned 64-bit integer array.' ); + } + buf = this._buffer; + if ( arguments.length > 1 ) { + idx = arguments[ 1 ]; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + } else { + idx = 0; + } + if ( isUint64( value ) ) { + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + idx *= 2; + buf[ idx + indices.HIGH ] = value.hi; + buf[ idx + indices.LOW ] = value.lo; + return; + } + if ( isUintArray( value ) ) { + N = value._length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + sbuf = value._buffer; + + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = new Uint32Array( sbuf.length ); + for ( i = 0; i < sbuf.length; i++ ) { + tmp[ i ] = sbuf[ i ]; + } + sbuf = tmp; + } + idx *= 2; + j = 0; + for ( i = 0; i < N; i++ ) { + buf[ idx ] = sbuf[ j ]; + buf[ idx+1 ] = sbuf[ j+1 ]; + idx += 2; // stride + j += 2; // stride + } + return; + } + if ( isCollection( value ) ) { + // Detect whether we've been provided an array of unsigned 64-bit integers... + N = value.length; + for ( i = 0; i < N; i++ ) { + if ( !isUint64( value[ i ] ) ) { + flg = true; + break; + } + } + // If an array does not contain only unsigned 64-bit integers, then we assume interleaved real and imaginary components... + if ( flg ) { + if ( !isEven( N ) ) { + throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', N ) ); + } + if ( idx+(N/2) > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + sbuf = value; + + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = new Uint32Array( N ); + for ( i = 0; i < N; i++ ) { + tmp[ i ] = sbuf[ i ]; + } + sbuf = tmp; + } + idx *= 2; + N /= 2; + j = 0; + for ( i = 0; i < N; i++ ) { + buf[ idx ] = sbuf[ j ]; + buf[ idx+1 ] = sbuf[ j+1 ]; + idx += 2; // stride + j += 2; // stride + } + return; + } + // If an array contains only unsigned 64-bit integers, then we need to extract real and imaginary components... + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + idx *= 2; + for ( i = 0; i < N; i++ ) { + v = value[ i ]; + buf[ idx + indices.HIGH ] = sbuf[ j ]; + buf[ idx + indices.LOW ] = sbuf[ j+1 ]; + idx += 2; // stride + } + return; + } + throw new TypeError( format( 'invalid argument. First argument must be either a unsigned 64-bit integer, an array-like object, or a unsigned 64-bit integer array. Value: `%s`.', value ) ); + + /* eslint-enable no-underscore-dangle */ +}); From 2d1b4d9a3d4d622a29b0a2388618da92f7f5287b Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 09:29:06 +0000 Subject: [PATCH 07/15] fix: fixes high and low words assignment in constructor --- .../@stdlib/array/uint64/lib/main.js | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 0cebf7eb04d8..583863613e89 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -114,7 +114,7 @@ function isUintArrayConstructor( value ) { */ function getUint64( buf, idx ) { idx *= 2; - return new Uint64( buf[ idx ], buf[ idx+1 ] ); + return Uint64.of( buf[ idx + indices.HIGH ], buf[ idx + indices.LOW ] ); } @@ -193,6 +193,11 @@ function Uint64Array() { var nargs; var buf; var len; + var tmp; + var idx; + var N; + var i; + var j; nargs = arguments.length; if ( !(this instanceof Uint64Array) ) { @@ -229,20 +234,23 @@ function Uint64Array() { buf = new Uint32Array( arguments[0] ); } } else { - if ( Uint8Array( buf ) ) { - - } else if ( Uint8ClampedArray( buf ) ) { - - } else if ( Uint16Array( buf ) ) { - - } else if ( Uint32Array( buf ) ) { - - } else if ( Uint64Array( buf ) ) { - + if ( buf instanceof Uint64Array ) { + buf = buf._buffer; // eslint-disable-line no-underscore-dangle } else if ( !isEven( len ) ) { throw new RangeError( format( 'invalid argument. Array-like object and typed array arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); + } else { + tmp = new Uint32Array( len ); + N = len / 2; + idx = 0; + j = 0; + for ( i = 0; i < N; i++ ) { + tmp[ idx + indices.HIGH ] = buf[ j ]; + tmp[ idx + indices.LOW ] = buf[ j+1 ]; + idx += 2; // stride + j += 2; // stride + } + buf = tmp; } - buf = new Uint32Array( buf ); } } else if ( isArrayBuffer( arguments[0] ) ) { buf = arguments[ 0 ]; @@ -672,8 +680,8 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { idx *= 2; j = 0; for ( i = 0; i < N; i++ ) { - buf[ idx ] = sbuf[ j ]; - buf[ idx+1 ] = sbuf[ j+1 ]; + buf[ idx + indices.HIGH ] = sbuf[ j ]; + buf[ idx + indices.LOW ] = sbuf[ j+1 ]; idx += 2; // stride j += 2; // stride } @@ -718,8 +726,8 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { N /= 2; j = 0; for ( i = 0; i < N; i++ ) { - buf[ idx ] = sbuf[ j ]; - buf[ idx+1 ] = sbuf[ j+1 ]; + buf[ idx + indices.HIGH ] = sbuf[ j ]; + buf[ idx + indices.LOW ] = sbuf[ j+1 ]; idx += 2; // stride j += 2; // stride } @@ -732,8 +740,8 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { idx *= 2; for ( i = 0; i < N; i++ ) { v = value[ i ]; - buf[ idx + indices.HIGH ] = sbuf[ j ]; - buf[ idx + indices.LOW ] = sbuf[ j+1 ]; + buf[ idx + indices.HIGH ] = v.hi; + buf[ idx + indices.LOW ] = v.low; idx += 2; // stride } return; @@ -742,3 +750,8 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { /* eslint-enable no-underscore-dangle */ }); + + +// EXPORTS // + +module.exports = Uint64Array; From f457469e8ccca581184d52303131d1bcbfff7caf Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 09:34:24 +0000 Subject: [PATCH 08/15] fix: add collection suppoet in .from method --- .../@stdlib/array/uint64/lib/main.js | 79 ++++++++++++++++--- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 583863613e89..3e63efb32e11 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -223,7 +223,7 @@ function Uint64Array() { len = buf.length; // If provided a "generic" array, peak at the first value, and, if the value is a unsigned 64-bit integer, try to process as an array of unsigned 64-bit integer, falling back to "normal" typed array initialization if we fail and ensuring consistency if the first value had not been a unsigned 64-bit integer... - if ( len && isArray( buf ) && isBigUint64Array( buf[0] ) ) { + if ( len && isArray( buf ) && ( isUint64( buf[0] ) || isBigUint64Array( buf[0] ) ) ) { buf = fromArray( new Uint32Array( len*2 ), buf ); if ( buf === null ) { // We failed and we are now forced to allocate a new array :-( @@ -240,8 +240,8 @@ function Uint64Array() { throw new RangeError( format( 'invalid argument. Array-like object and typed array arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); } else { tmp = new Uint32Array( len ); - N = len / 2; - idx = 0; + N = len / 2; + idx = 0; j = 0; for ( i = 0; i < N; i++ ) { tmp[ idx + indices.HIGH ] = buf[ j ]; @@ -249,7 +249,7 @@ function Uint64Array() { idx += 2; // stride j += 2; // stride } - buf = tmp; + buf = tmp; } } } else if ( isArrayBuffer( arguments[0] ) ) { @@ -320,11 +320,11 @@ function Uint64Array() { * @memberof Uint64Array * @readonly * @type {PositiveInteger} -* @default 16 +* @default 8 * * @example * var nbytes = Uint64Array.BYTES_PER_ELEMENT; -* // returns 16 +* // returns 8 */ setReadOnly( Uint64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); @@ -355,7 +355,7 @@ setReadOnly( Uint64Array, 'name', 'Uint64Array' ); * var arr = new Uint64Array( 10 ); * * var byteLength = arr.byteLength; -* // returns 160 +* // returns 80 */ setReadOnlyAccessor( Uint64Array.prototype, 'byteLength', function get() { return this._buffer.byteLength; @@ -407,7 +407,7 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { * @example * var Uint64 = require( '@stdlib/number/uint64/ctor' ); * -* var arr = Uint64Array.from( [ new Uint64( 1234, 5678 ) ] ); +* var arr = Uint64Array.from( [ Uint64.of( 1234, 5678 ) ] ); * // returns * * var len = arr.length; @@ -417,10 +417,10 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { * var Uint64 = require( '@stdlib/number/uint64/ctor' ); * * function clbk( v ) { -* return new Uint64( v.hi*2, v.lo*2 ); +* return Uint64.of( v.hi*2, v.lo*2 ); * } * -* var arr = Uint64Array.from( [ new Uint64( 1234, 5678 ) ], clbk ); +* var arr = Uint64Array.from( [ Uint64.of( 1234, 5678 ) ], clbk ); * // returns * * var len = arr.length; @@ -478,6 +478,59 @@ setReadOnly( Uint64Array, 'from', function from( src ) { } return new this( src ); } + if ( isCollection( src ) ) { + if ( clbk ) { + // Note: array contents affect how we iterate over a provided data source. If only unsigned 64-bit integer objects, we can extract high and low words. Otherwise, for non-unsigned 64-bit integer arrays (e.g., `Float64Array`, etc), we assume a strided array where high and low words are interleaved. In the former case, we expect a callback to return high and low words (possibly as a unsigned 64-bit integer). In the latter case, we expect a callback to return *either* a high or low word. + + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + // Detect whether we've been provided an array which returns unsigned 64-bit integer objects... + for ( i = 0; i < len; i++ ) { + if ( !isUint64( get( src, i ) ) ) { + flg = true; + break; + } + } + // If an array does not contain only unsigned 64-bit integer objects, then we assume interleaved high and low words... + if ( flg ) { + if ( !isEven( len ) ) { + throw new RangeError( format( 'invalid argument. First argument must have a length which is a multiple of two. Length: `%u`.', len ) ); + } + out = new this( len/2 ); + j = 0; + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i += 2 ) { + buf[ j + indices.HIGH ] = clbk.call( thisArg, get( src, i ), i ); + buf[ j + indices.LOW ] = clbk.call( thisArg, get( src, i+1 ), i+1 ); + j += 2; + } + return out; + } + // If an array contains only unsigned 64-bit integer objects, then we need to extract high and low words... + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + j = 0; + for ( i = 0; i < len; i++ ) { + v = clbk.call( thisArg, get( src, i ), i ); + if ( isUint64( v ) ) { + buf[ j + indices.HIGH ] = v.hi; + buf[ j + indices.LOW ] = v.lo; + } else if ( isArrayLikeObject( v ) && v.length >= 2 ) { + buf[ j + indices.HIGH ] = v[ 0 ]; + buf[ j + indices.LOW ] = v[ 1 ]; + } else { + throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing high and low words or a unsigned 64-bit integer. Value: `%s`.', v ) ); + } + j += 2; // stride + } + return out; + } + return new this( src ); + } if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len buf = src[ ITERATOR_SYMBOL ](); if ( !isFunction( buf.next ) ) { @@ -681,7 +734,7 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { j = 0; for ( i = 0; i < N; i++ ) { buf[ idx + indices.HIGH ] = sbuf[ j ]; - buf[ idx + indices.LOW ] = sbuf[ j+1 ]; + buf[ idx + indices.LOW ] = sbuf[ j+1 ]; idx += 2; // stride j += 2; // stride } @@ -727,7 +780,7 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { j = 0; for ( i = 0; i < N; i++ ) { buf[ idx + indices.HIGH ] = sbuf[ j ]; - buf[ idx + indices.LOW ] = sbuf[ j+1 ]; + buf[ idx + indices.LOW ] = sbuf[ j+1 ]; idx += 2; // stride j += 2; // stride } @@ -741,7 +794,7 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { for ( i = 0; i < N; i++ ) { v = value[ i ]; buf[ idx + indices.HIGH ] = v.hi; - buf[ idx + indices.LOW ] = v.low; + buf[ idx + indices.LOW ] = v.lo; idx += 2; // stride } return; From 30725717ad6c65d680f2ce06f882da5560807453 Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 11:26:18 +0000 Subject: [PATCH 09/15] fix: corrects examples --- lib/node_modules/@stdlib/array/uint64/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 3e63efb32e11..862c3e4d5f23 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -605,12 +605,12 @@ setReadOnly( Uint64Array, 'of', function of() { * var arr = new Uint64Array( 10 ); * * var z = arr.get( 0 ); -* // returns [ 0, 0 ] +* // returns * * arr.set( [ 1234, 5678 ], 0 ); * * z = arr.get( 0 ); -* // returns [ 1234, 5678 ] +* // returns * * z = arr.get( 100 ); * // returns undefined From 0137613e4e97e0f96e10169fc5397cc190ae3c21 Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 11:26:41 +0000 Subject: [PATCH 10/15] fix: corrects examples --- lib/node_modules/@stdlib/array/uint64/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 862c3e4d5f23..c2cdffc01f76 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -668,12 +668,12 @@ setReadOnly( Uint64Array.prototype, 'get', function get( idx ) { * var arr = new Uint64Array( 10 ); * * var z = arr.get( 0 ); -* // returns [ 0, 0 ] +* // returns * * arr.set( [ 1234, 5678 ], 0 ); * * z = arr.get( 0 ); -* // returns [ 1234, 5678 ] +* // returns */ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { /* eslint-disable no-underscore-dangle */ From 319e3279313ae3557b5d4b485641e4ad7247f0e6 Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 11:54:49 +0000 Subject: [PATCH 11/15] feat: add entry point --- .../@stdlib/array/uint64/lib/index.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/lib/index.js diff --git a/lib/node_modules/@stdlib/array/uint64/lib/index.js b/lib/node_modules/@stdlib/array/uint64/lib/index.js new file mode 100644 index 000000000000..860dec58ff21 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/index.js @@ -0,0 +1,94 @@ +/** +* @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'; + +/** +* 64-bit unsigned integer array. +* +* @module @stdlib/array/uint64 +* +* @example +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var arr = new Uint64Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var arr = new Uint64Array( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var arr = new Uint64Array( [ 1234, 5678 ] ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Uint64Array( buf ); +* // returns +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Uint64Array( buf, 16 ); +* // returns +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Uint64Array = require( '@stdlib/array/uint64' ); +* +* var buf = new ArrayBuffer( 64 ); +* var arr = new Uint64Array( buf, 16, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; From 881eb7f3d44c9e826c8ff468165c54bd948f6b8e Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 14:46:56 +0000 Subject: [PATCH 12/15] feat: add length method --- .../@stdlib/array/uint64/lib/main.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index c2cdffc01f76..8d068aa13c03 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -166,7 +166,7 @@ function getUint64( buf, idx ) { * // returns * * var len = arr.length; -* // returns 2 +* // returns 4 * * @example * var ArrayBuffer = require( '@stdlib/array/buffer' ); @@ -176,7 +176,7 @@ function getUint64( buf, idx ) { * // returns * * var len = arr.length; -* // returns 1 +* // returns 2 * * @example * var ArrayBuffer = require( '@stdlib/array/buffer' ); @@ -804,6 +804,24 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { /* eslint-enable no-underscore-dangle */ }); +/** +* Number of array elements. +* +* @name length +* @memberof Uint64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var len = arr.length; +* // returns 10 +*/ +setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { + return this._length; +}); + // EXPORTS // From f6651137804c700487ddd76432437dd3133438df Mon Sep 17 00:00:00 2001 From: Divit Date: Sun, 14 Jun 2026 17:01:20 +0000 Subject: [PATCH 13/15] feat: add bytes method --- .../@stdlib/array/uint64/lib/main.js | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 8d068aa13c03..886a92d028ae 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -313,6 +313,21 @@ function Uint64Array() { return this; } +/** +* Constructor name. +* +* @name name +* @memberof Uint64Array +* @readonly +* @type {string} +* @default 'Uint64Array' +* +* @example +* var name = Uint64Array.name; +* // returns 'Uint64Array' +*/ +setReadOnly( Uint64Array, 'name', 'Uint64Array' ); + /** * Size (in bytes) of each array element. * @@ -329,22 +344,24 @@ function Uint64Array() { setReadOnly( Uint64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); /** -* Constructor name. +* Size (in bytes) of each array element. * -* @name name -* @memberof Uint64Array +* @name BYTES_PER_ELEMENT +* @memberof Uint64Array.prototype * @readonly -* @type {string} -* @default 'Uint64Array' +* @type {PositiveInteger} +* @default 8 * * @example -* var name = Uint64Array.name; -* // returns 'Uint64Array' +* var arr = new Uint64Array( 10 ); +* +* var nbytes = arr.BYTES_PER_ELEMENT; +* // returns 8 */ -setReadOnly( Uint64Array, 'name', 'Uint64Array' ); +setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_ELEMENT ); /** -* Size (in bytes) of the array. + * Size (in bytes) of the array. * * @name byteLength * @memberof Uint64Array.prototype @@ -362,7 +379,7 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteLength', function get() { }); /** -* Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. + * Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. * * @name byteOffset * @memberof Uint64Array.prototype @@ -379,6 +396,24 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { return this._buffer.byteOffset; }); +/** +* Pointer to the underlying data buffer. +* +* @name buffer +* @memberof Uint64Array.prototype +* @readonly +* @type {ArrayBuffer} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var buf = arr.buffer; +* // returns +*/ +setReadOnlyAccessor( Uint64Array.prototype, 'buffer', function get() { + return this._buffer.buffer; +}); + /** * Creates a new unsigned 64-bit integer array from an array-like object or an iterable. * From 30b8f3f218b1ceab0e6ce220997066c6f071bb49 Mon Sep 17 00:00:00 2001 From: Divit Date: Mon, 15 Jun 2026 18:10:55 +0000 Subject: [PATCH 14/15] test: adds base 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 --- --- .../@stdlib/array/uint64/test/test.js | 941 ++++++++++++++++++ 1 file changed, 941 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/test/test.js diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.js b/lib/node_modules/@stdlib/array/uint64/test/test.js new file mode 100644 index 000000000000..0426ef9038f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.js @@ -0,0 +1,941 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Uint64Array = require( './../lib' ); + + +// 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( 'the function is a constructor', function test( t ) { + var arr = new Uint64Array( 0 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( 0 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (no argument)', function test( t ) { + var arr = new Uint64Array(); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (no argument, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor(); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (length)', function test( t ) { + var arr = new Uint64Array( 10 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( 10 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (array)', function test( t ) { + var arr = new Uint64Array( [] ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( [] ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (typed array)', function test( t ) { + var arr = new Uint64Array( new Uint32Array( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (typed array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( new Uint32Array( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (unsigned integer typed array)', function test( t ) { + var arr = new Uint64Array( new Uint64Array( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (unsigned integer typed array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( new Uint64Array( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (iterable)', function test( t ) { + var Uint64Array; + var arr; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = new Uint64Array( createIterable() ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (iterable, no new)', function test( t ) { + var ctor; + var arr; + + ctor = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = ctor( createIterable() ); + t.strictEqual( arr instanceof ctor, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer)', function test( t ) { + var arr = new Uint64Array( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer, byte offset)', function test( t ) { + var arr = new Uint64Array( new ArrayBuffer( 16 ), 16 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer, byte offset, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( new ArrayBuffer( 16 ), 16 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer, byte offset, length)', function test( t ) { + var arr = new Uint64Array( new ArrayBuffer( 16 ), 16, 0 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit unsigned integer array (ArrayBuffer, byte offset, length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Uint64Array; + + arr = ctor( new ArrayBuffer( 16 ), 16, 0 ); + t.strictEqual( arr instanceof Uint64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Uint64Array.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array, 'name' ), true, 'has property' ); + t.strictEqual( Uint64Array.name, 'Uint64Array', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Uint64Array.prototype.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + + arr = new Uint64Array( 0 ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { + var arr; + var buf; + + arr = new Uint64Array( 0 ); + buf = arr.buffer; + t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { + var arr; + var v; + + arr = new Uint64Array( 0 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 16 ); + v = arr.byteLength; + t.strictEqual( v, 112, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { + var arr; + var v; + + arr = new Uint64Array( 0 ); + v = arr.byteOffset; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 64 ); + v = arr.byteOffset; + t.strictEqual( v, 64, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.byteOffset; + t.strictEqual( v, 128, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { + var arr; + var v; + + // No arguments: + arr = new Uint64Array(); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Explicit array length: + arr = new Uint64Array( 0 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( 10 ); + v = arr.length; + t.strictEqual( v, 10, 'returns expected value' ); + + // Generic array: + arr = new Uint64Array( [] ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Generic array Uint64 objects: + arr = new Uint64Array( [ Uint64.of( 1, 1 ) ] ); + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + // Typed array: + arr = new Uint64Array( new Uint32Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new Uint32Array( [ 1, 1 ] ) ); + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + // Unsigned 64-bit typed array: + arr = new Uint64Array( new Uint64Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new Uint64Array( [ 1, 1 ] ) ); + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = new Uint64Array( new Uint64Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new Uint64Array( [ 1, 1 ] ) ); + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + // ArrayBuffer: + arr = new Uint64Array( new ArrayBuffer( 128 ), 64 ); + v = arr.length; + t.strictEqual( v, 8, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Uint64Array( new ArrayBuffer( 128 ), 64, 2 ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements (iterable)', function test( t ) { + var Uint64Array; + var iter1; + var iter2; + var arr; + var v; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter1 = { + 'next': next1, + 'i': 0, + 'N': 4 + }; + arr = new Uint64Array( createIterable( iter1 ) ); + v = arr.length; + t.strictEqual( v, iter1.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + arr = new Uint64Array( createIterable( iter2 ) ); + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next1() { + iter1.i += 1; + if ( iter1.i <= iter1.N ) { + return { + 'value': [ 1, 1 ] + }; + } + return { + 'done': true + }; + } + + function next2() { + iter2.i += 1; + if ( iter2.i <= iter2.N ) { + return { + 'value': new Uint64( 1, 1 ) + }; + } + return { + 'done': true + }; + } +}); + +tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 9, + 21, + 74, + 801 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Uint64Array( new ArrayBuffer( value ) ); + }; + } +}); + +tape( 'the constructor throws an error if provided an array-like object having an odd length', function test( t ) { + var values; + var i; + + values = [ + [ 1, 2, 3 ], + new Uint32Array( [ 1, 2, 3 ] ), + { + 'length': 3, + '0': 1, + '1': 2, + '2': 3 + }, + [ new Uint64( 1, 1 ), 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an array-like object having a length equal to '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Uint64Array( value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { + var Uint64Array; + var values; + var i; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + } + ]; + 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 new Uint64Array( value ); + }; + } + + function hasSupport() { + return false; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (ES2015+)', function test( t ) { + var Uint64Array; + var values; + var i; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + }, + { + '__SYMBOL_ITERATOR__': null + }, + { + '__SYMBOL_ITERATOR__': 'beep' + }, + { + '__SYMBOL_ITERATOR__': nonIterable1 + }, + { + '__SYMBOL_ITERATOR__': nonIterable2 + } + ]; + 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 new Uint64Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function nonIterable1() { + return null; + } + + function nonIterable2() { + return {}; + } +}); + +tape( 'the constructor throws an error if provided an iterable object which does not return unsigned 64-bit integer or arrays of high and low words', function test( t ) { + var Uint64Array; + var values; + var i; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + { + '__SYMBOL_ITERATOR__': createIterable( next1 ) + }, + { + '__SYMBOL_ITERATOR__': createIterable( next2 ) + } + ]; + 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 new Uint64Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function createIterable( next ) { + return iterable; + + function iterable() { + return { + 'next': next + }; + } + } + + function next1() { + return { + 'value': 1.0 + }; + } + + function next2() { + return { + 'value': '1 + 1' + }; + } +}); + +tape( 'the constructor throws an error if provided an iterable object which does not return array containing at least two elements', function test( t ) { + var Uint64Array; + var values; + var i; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + { + '__SYMBOL_ITERATOR__': createIterable( next1 ) + }, + { + '__SYMBOL_ITERATOR__': createIterable( next2 ) + } + ]; + 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 new Uint64Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function createIterable( next ) { + return iterable; + + function iterable() { + return { + 'next': next + }; + } + } + + function next1() { + return { + 'value': [] + }; + } + + function next2() { + return { + 'value': [ 1 ] + }; + } +}); + +tape( 'the constructor throws an error if not provided a length, iterable, array-like object, or ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + -1, + 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 new Uint64Array( value ); + }; + } +}); + +tape( 'the constructor throws an error if provided more than one argument and the first argument is not an ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 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 new Uint64Array( value, 0 ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a nonnegative integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 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 new Uint64Array( new ArrayBuffer( 64 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 9, + 21, + 65, + 78, + 801 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Uint64Array( new ArrayBuffer( 64 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 8, + 16, + 24, + 32, + 48, + 56, + 64, + 72, + 80, + 88, + 100 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Uint64Array( new ArrayBuffer( 102 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a length argument which is not a nonnegative integer (ArrayBuffer)', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 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 new Uint64Array( new ArrayBuffer( 128 ), 0, value ); + }; + } +}); + +tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { + var values; + var i; + + values = [ + 16, + 24, + 32, + 48 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Uint64Array( new ArrayBuffer( 100 ), value, 1e3 ); + }; + } +}); From 86bd46bdd77333bc3efd12577de250af1d347258 Mon Sep 17 00:00:00 2001 From: Divit Date: Tue, 16 Jun 2026 10:02:52 +0000 Subject: [PATCH 15/15] chore: restructure --- .../array/uint64/lib/from_iterator_map.js | 2 +- .../@stdlib/array/uint64/lib/index.js | 2 +- .../@stdlib/array/uint64/lib/main.js | 36 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js index 2921fcde41ad..5d2a85a9205a 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/uint64/lib/index.js b/lib/node_modules/@stdlib/array/uint64/lib/index.js index 860dec58ff21..195ab2c7095e 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/index.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/index.js @@ -70,7 +70,7 @@ * // returns * * var len = arr.length; -* // returns 1 +* // returns 2 * * @example * var ArrayBuffer = require( '@stdlib/array/buffer' ); diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 886a92d028ae..b9435009d2a2 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -414,6 +414,24 @@ setReadOnlyAccessor( Uint64Array.prototype, 'buffer', function get() { return this._buffer.buffer; }); +/** +* Number of array elements. +* +* @name length +* @memberof Uint64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Uint64Array( 10 ); +* +* var len = arr.length; +* // returns 10 +*/ +setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { + return this._length; +}); + /** * Creates a new unsigned 64-bit integer array from an array-like object or an iterable. * @@ -839,24 +857,6 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { /* eslint-enable no-underscore-dangle */ }); -/** -* Number of array elements. -* -* @name length -* @memberof Uint64Array.prototype -* @readonly -* @type {NonNegativeInteger} -* -* @example -* var arr = new Uint64Array( 10 ); -* -* var len = arr.length; -* // returns 10 -*/ -setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { - return this._length; -}); - // EXPORTS //