Repository navigation
feat: add fill method to array/uint64
#14173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DivitJain26
wants to merge
10
commits into
stdlib-js:develop
Choose a base branch
from
DivitJain26:feat/add-uint64array-fill
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
86ba66f
feat: add implementation for method fill for uint64array
DivitJain26 a8580ec
chore: add uint64 convertion check
DivitJain26 bc3e2d1
chore: checkpoint
DivitJain26 5fb6955
chore: update exmaples
DivitJain26 70b29ff
bench: add benchmarks
DivitJain26 cd2898a
docs: adds type definition
DivitJain26 3377efe
docs: adds repl text
DivitJain26 da55dab
docs: adds readme
DivitJain26 d3e5139
Merge branch 'develop' into feat/add-uint64array-fill
kgryte b12257e
Apply batched suggestions from code review
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); | ||
| var Uint64 = require( '@stdlib/number/uint64/ctor' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var Uint64Array = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( format( '%s:fill', pkg ), function benchmark( b ) { | ||
| var values; | ||
| var arr; | ||
| var out; | ||
| var i; | ||
|
|
||
| values = [ | ||
| new Uint64( 1 ), | ||
| new Uint64( 2 ), | ||
| new Uint64( 3 ) | ||
| ]; | ||
| arr = new Uint64Array( 5 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| out = arr.fill( values[ i%values.length ] ); | ||
| if ( typeof out !== 'object' ) { | ||
| b.fail( 'should return an object' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !isUint64Array( out ) ) { | ||
| b.fail( 'should return a Uint64Array' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
103 changes: 103 additions & 0 deletions
103
lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); | ||
| var pow = require( '@stdlib/math/base/special/pow' ); | ||
| var Uint64 = require( '@stdlib/number/uint64/ctor' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var Uint64Array = require( './../lib' ); | ||
|
|
||
|
|
||
| // FUNCTIONS // | ||
|
|
||
| /** | ||
| * Creates a benchmark function. | ||
| * | ||
| * @private | ||
| * @param {PositiveInteger} len - array length | ||
| * @returns {Function} benchmark function | ||
| */ | ||
| function createBenchmark( len ) { | ||
| var arr = new Uint64Array( len ); | ||
| return benchmark; | ||
|
|
||
| /** | ||
| * Benchmark function. | ||
| * | ||
| * @private | ||
| * @param {Benchmark} b - benchmark instance | ||
| */ | ||
| function benchmark( b ) { | ||
| var values; | ||
| var out; | ||
| var i; | ||
|
|
||
| values = [ | ||
| new Uint64( 1 ), | ||
| new Uint64( 2 ), | ||
| new Uint64( 3 ) | ||
| ]; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| out = arr.fill( values[ i%values.length ] ); | ||
| if ( typeof out !== 'object' ) { | ||
| b.fail( 'should return an object' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !isUint64Array( out ) ) { | ||
| b.fail( 'should return a Uint64Array' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Main execution sequence. | ||
| * | ||
| * @private | ||
| */ | ||
| function main() { | ||
| var len; | ||
| var min; | ||
| var max; | ||
| var f; | ||
| var i; | ||
|
|
||
| min = 1; // 10^min | ||
| max = 6; // 10^max | ||
|
|
||
| for ( i = min; i <= max; i++ ) { | ||
| len = pow( 10, i ); | ||
| f = createBenchmark( len ); | ||
| bench( format( '%s:fill:len=%d', pkg, len ), f ); | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -702,6 +702,86 @@ | |
| } | ||
| }); | ||
|
|
||
| /** | ||
| * Returns a modified typed array filled with a fill value. | ||
| * | ||
| * @name fill | ||
| * @memberof Uint64Array.prototype | ||
| * @type {Function} | ||
| * @param {(Uint64|bigint|number)} value - fill value | ||
| * @param {integer} [start=0] - starting index (inclusive) | ||
| * @param {integer} [end] - ending index (exclusive) | ||
| * @throws {TypeError} `this` must be a 64-bit unsigned integer array | ||
| * @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @throws {TypeError} third argument must be an integer | ||
| * @returns {Uint64Array} modified array | ||
| * | ||
| * @example | ||
| * var arr = new Uint64Array( 3 ); | ||
| * // returns <Uint64Array>[ 0n , 0n, 0n ] | ||
| * | ||
| * arr = arr.fill( 1, 1 ); | ||
| * // returns <Uint64Array>[ 0n, 1n, 1n ] | ||
| */ | ||
| setReadOnly( Uint64Array.prototype, 'fill', function fill( value, start, end ) { | ||
| var words; | ||
| var buf; | ||
| var len; | ||
| var idx; | ||
| var i; | ||
| if ( !isUint64Array( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); | ||
| } | ||
| if ( !isUint64( value ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DivitJain26 Do you want to use the new |
||
| try { | ||
| value = new Uint64( value ); | ||
| } catch ( err ) { // eslint-disable-line no-unused-vars | ||
| throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', value ) ); | ||
| } | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length > 1 ) { | ||
| if ( !isInteger( start ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); | ||
| } | ||
| if ( start < 0 ) { | ||
| start += len; | ||
| if ( start < 0 ) { | ||
| start = 0; | ||
| } | ||
| } | ||
| if ( arguments.length > 2 ) { | ||
| if ( !isInteger( end ) ) { | ||
| throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); | ||
| } | ||
| if ( end < 0 ) { | ||
| end += len; | ||
| if ( end < 0 ) { | ||
| end = 0; | ||
| } | ||
| } | ||
| if ( end > len ) { | ||
| end = len; | ||
| } | ||
| } else { | ||
| end = len; | ||
| } | ||
| } else { | ||
| start = 0; | ||
| end = len; | ||
| } | ||
| words = [ 0, 0 ]; | ||
| toWords( value, words, 1, 0 ); | ||
| for ( i = start; i < end; i++ ) { | ||
| idx = 2*i; | ||
| buf[ idx+indices.HIGH ] = words[ 0 ]; | ||
| buf[ idx+indices.LOW ] = words[ 1 ]; | ||
| } | ||
| return this; | ||
| }); | ||
|
|
||
| /** | ||
| * Returns an array element. | ||
| * | ||
|
|
@@ -839,7 +919,7 @@ | |
| buf[ idx+indices.LOW ] = words[ 1 ]; | ||
| return; | ||
| } | ||
| if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) { | ||
| if ( idx >= this._length ) { | ||
| throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the description used in
array/float64, rather than the less descriptive description in, e.g.,array/complex128. Also applies to the other places in the docs where the method is described.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to submit a small clean-up PR updating the corresponding descriptions in the complex and bool array packages, if applicable.