@stdlib/array-index 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -371,7 +371,7 @@ var o = idx.toJSON();
371
371
 
372
372
  ```javascript
373
373
  var Uint8Array = require( '@stdlib/array-uint8' );
374
-
374
+
375
375
  var data = new Uint8Array( [ 1, 0, 0, 0 ] );
376
376
  var idx = new ArrayIndex( data );
377
377
 
@@ -388,7 +388,7 @@ var o = idx.toJSON();
388
388
 
389
389
  ```javascript
390
390
  var Uint8Array = require( '@stdlib/array-uint8' );
391
-
391
+
392
392
  var data = new Uint8Array( [ 1, 0, 0, 0 ] );
393
393
  var idx = new ArrayIndex( data );
394
394
 
@@ -420,6 +420,7 @@ var o = idx.toJSON();
420
420
  ```javascript
421
421
  var Uint8Array = require( '@stdlib/array-uint8' );
422
422
  var Int32Array = require( '@stdlib/array-int32' );
423
+ var BooleanArray = require( '@stdlib/array-bool' );
423
424
  var ArrayIndex = require( '@stdlib/array-index' );
424
425
 
425
426
  var x = new Uint8Array( [ 1, 0, 1, 0 ] );
@@ -440,6 +441,15 @@ o = ArrayIndex.get( i.id );
440
441
 
441
442
  console.log( 'Type: %s. Data type: %s.', o.type, o.dtype );
442
443
 
444
+ x = new BooleanArray( [ true, false, true, false ] );
445
+ i = new ArrayIndex( x );
446
+ // returns <ArrayIndex>
447
+
448
+ o = ArrayIndex.get( i.id );
449
+ // returns {...}
450
+
451
+ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype );
452
+
443
453
  x = new Int32Array( [ 1, 3, 4, 7 ] );
444
454
  i = new ArrayIndex( x );
445
455
  // returns <ArrayIndex>
@@ -475,6 +485,12 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype );
475
485
 
476
486
  <section class="related">
477
487
 
488
+ * * *
489
+
490
+ ## See Also
491
+
492
+ - <span class="package-name">[`@stdlib/array-to-fancy`][@stdlib/array/to-fancy]</span><span class="delimiter">: </span><span class="description">convert an array to an object supporting fancy indexing.</span>
493
+
478
494
  </section>
479
495
 
480
496
  <!-- /.related -->
@@ -518,8 +534,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
518
534
  [npm-image]: http://img.shields.io/npm/v/@stdlib/array-index.svg
519
535
  [npm-url]: https://npmjs.org/package/@stdlib/array-index
520
536
 
521
- [test-image]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml/badge.svg?branch=v0.2.0
522
- [test-url]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml?query=branch:v0.2.0
537
+ [test-image]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml/badge.svg?branch=v0.3.0
538
+ [test-url]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml?query=branch:v0.3.0
523
539
 
524
540
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-index/main.svg
525
541
  [coverage-url]: https://codecov.io/github/stdlib-js/array-index?branch=main
package/dist/index.js CHANGED
@@ -1,15 +1,19 @@
1
- "use strict";var o=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=o(function(Z,p){
2
- function A(){return{persist:!1}}p.exports=A
3
- });var g=o(function($,h){
4
- var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('null2o',"persist",r.persist)):null:new TypeError(y('null2V',e));}h.exports=N
5
- });var v=o(function(ee,m){
6
- var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k
7
- });var q=o(function(re,w){
8
- var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F
9
- });var x=o(function(te,_){
10
- var b=-1;function R(){return b+=1,b.toString()}_.exports=R
11
- });var O=o(function(ae,T){
12
- var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,u,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('null2O',r));if(i=z(r),i==="generic"||i===null)if(n=H(r),l=n(r,0),L(l))u="bool";else if(V(l))u="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else if(i==="int32")u="int";else if(i==="uint8")u="mask";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:u,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a
13
- });var X=O();module.exports=X;
14
- /** @license Apache-2.0 */
1
+ "use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){"use strict";function A(){return{persist:!1}}p.exports=A});var g=u(function($,h){"use strict";var I=require("@stdlib/assert-is-plain-object"),S=require("@stdlib/assert-has-own-property"),j=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/string-format");function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):null:new TypeError(y("invalid argument. Options argument must be an object. Value: `%s`.",e))}h.exports=N});var v=u(function(ee,m){"use strict";var P=require("@stdlib/utils-linked-list"),k=new P;m.exports=k});var b=u(function(re,w){"use strict";var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F});var x=u(function(te,_){"use strict";var q=-1;function R(){return q+=1,q.toString()}_.exports=R});var O=u(function(ae,T){"use strict";var d=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),B=require("@stdlib/utils-define-nonenumerable-property"),J=require("@stdlib/assert-is-collection"),L=require("@stdlib/assert-is-boolean").isPrimitive,V=require("@stdlib/assert-is-integer").isPrimitive,G=require("@stdlib/array-base-assert-is-accessor-array"),U=require("@stdlib/array-to-json"),z=require("@stdlib/array-dtype"),D=require("@stdlib/array-base-copy"),H=require("@stdlib/array-base-resolve-getter"),K=require("@stdlib/string-format"),M=c(),Q=g(),f=v(),E=b(),W=x();function a(r){var e,t,n,i,s,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))s="bool";else if(V(l))s="int";else throw new TypeError("invalid argument. First argument must be a valid index array.");else s="int";else if(i==="int32")s="int";else if(i==="uint8")s="mask";else if(i==="bool")s="bool";else throw new TypeError("invalid argument. First argument must be a valid index array.");if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:s,dtype:i,persist:e.persist}),o(this,"_node",f.last()),B(this,"_invalidated",!1),this}o(a,"name","ArrayIndex");o(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,o(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});o(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return this._node.value.type});o(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,"ArrayIndex<"+e.id+">"});o(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error("invalid operation. This array index instance has already been freed and can no longer be used.");return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a});var X=O();module.exports=X;
2
+ /**
3
+ * @license Apache-2.0
4
+ *
5
+ * Copyright (c) 2024 The Stdlib Authors.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
15
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns <string>\n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var v = idx.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var id = idx.id;\n* // returns <string>\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,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,EAKD7B,EAAO,QAAUkB,ICrZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA",
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns <string>\n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var v = idx.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var id = idx.id;\n* // returns <string>\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IAAI,UAAWF,EAAQ,+DAAgE,UAAWE,EAAK,OAAQ,CAAE,EAGnH,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAI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AAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAmBDjB,EAAqBiB,EAAW,UAAW,WAAY,UAAe,CACrE,MAAO,CAAC,KAAK,YACd,CAAC,EAoBDjB,EAAqBiB,EAAW,UAAW,OAAQ,UAAe,CACjE,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAoBDhB,EAAagB,EAAW,UAAW,WAAY,UAAoB,CAClE,IAAIO,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAA,EAAI,KAAK,MAAM,MACR,cAAgBA,EAAE,GAAK,GAC/B,CAAC,EAwBDvB,EAAagB,EAAW,UAAW,SAAU,UAAkB,CAC9D,IAAIO,EACAI,EACJ,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,gGAAiG,EAEnH,OAAAJ,EAAI,KAAK,MAAM,MACVA,EAAE,QAAU,WAAaA,EAAE,QAAU,KACpClB,EAAiBkB,EAAE,IAAK,EAC5BI,EAAInB,EAAMe,EAAE,IAAK,EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,IC3ZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"]
7
7
  }
@@ -20,22 +20,7 @@
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array';
24
-
25
- /**
26
- * Boolean index array.
27
- */
28
- type BooleanIndexArray = Collection<boolean> | AccessorArrayLike<boolean>;
29
-
30
- /**
31
- * Integer index array.
32
- */
33
- type IntegerIndexArray = Collection<number> | AccessorArrayLike<number>;
34
-
35
- /**
36
- * Index array.
37
- */
38
- type IndexArray = BooleanIndexArray | IntegerIndexArray;
23
+ import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject, BooleanArray } from '@stdlib/types/array';
39
24
 
40
25
  /**
41
26
  * Interface describing function options.
@@ -48,245 +33,27 @@ interface Options {
48
33
  }
49
34
 
50
35
  /**
51
- * Interface describing an object containing array index data.
52
- */
53
- interface BaseArrayObject {
54
- /**
55
- * The underlying array associated with an array index.
56
- */
57
- data: IndexArray;
58
-
59
- /**
60
- * The type of array index.
61
- */
62
- type: 'int' | 'bool' | 'mask';
63
-
64
- /**
65
- * The data type of the underlying array.
66
- */
67
- dtype: DataType;
68
- }
69
-
70
- /**
71
- * Interface describing an object containing mask array data.
72
- */
73
- interface MaskArrayObject extends BaseArrayObject {
74
- /**
75
- * The underlying array associated with an array index.
76
- */
77
- data: Uint8Array;
78
-
79
- /**
80
- * The type of array index.
81
- */
82
- type: 'mask';
83
-
84
- /**
85
- * The data type of the underlying array.
86
- */
87
- dtype: 'uint8';
88
- }
89
-
90
- /**
91
- * Interface describing an object containing integer array data.
92
- */
93
- interface Int32ArrayObject extends BaseArrayObject {
94
- /**
95
- * The underlying array associated with an array index.
96
- */
97
- data: Int32Array;
98
-
99
- /**
100
- * The type of array index.
101
- */
102
- type: 'int';
103
-
104
- /**
105
- * The data type of the underlying array.
106
- */
107
- dtype: 'int32';
108
- }
109
-
110
- /**
111
- * Interface describing an object containing integer array data.
112
- */
113
- interface IntegerArrayObject extends BaseArrayObject {
114
- /**
115
- * The underlying array associated with an array index.
116
- */
117
- data: IntegerIndexArray;
118
-
119
- /**
120
- * The type of array index.
121
- */
122
- type: 'int';
123
-
124
- /**
125
- * The data type of the underlying array.
126
- */
127
- dtype: 'generic';
128
- }
129
-
130
- /**
131
- * Interface describing an object containing boolean array data.
132
- */
133
- interface BooleanArrayObject extends BaseArrayObject {
134
- /**
135
- * The underlying array associated with an array index.
136
- */
137
- data: BooleanIndexArray;
138
-
139
- /**
140
- * The type of array index.
141
- */
142
- type: 'bool';
143
-
144
- /**
145
- * The data type of the underlying array.
146
- */
147
- dtype: 'generic';
148
- }
149
-
150
- /**
151
- * Array object data.
152
- */
153
- type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null;
154
-
155
- /**
156
- * Interface describing an array index object.
36
+ * Interface defining an `ArrayIndex` constructor which is both "newable" and "callable".
157
37
  */
158
- interface BaseArrayIndex {
159
- /**
160
- * Read-only property returning the data associated with an `ArrayIndex` instance.
161
- */
162
- data: IndexArray;
163
-
164
- /**
165
- * Read-only property returning the underlying array index data type.
166
- */
167
- dtype: DataType;
168
-
169
- /**
170
- * Read-only property returning the unique identifier associated with an `ArrayIndex` instance.
171
- */
172
- id: string;
173
-
174
- /**
175
- * Boolean indicating if an `ArrayIndex` instance is actively cached.
176
- */
177
- isCached: boolean;
178
-
179
- /**
180
- * Read-only property returning the array index type.
181
- */
182
- type: 'int' | 'bool' | 'mask';
183
-
38
+ interface Constructor {
184
39
  /**
185
- * Serializes an `ArrayIndex` to a string.
40
+ * Array index constructor.
186
41
  *
187
- * @returns serialized string
42
+ * @param x - input array
43
+ * @param options - function options
44
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
45
+ * @returns ArrayIndex instance
188
46
  *
189
47
  * @example
190
48
  * var Uint8Array = require( '@stdlib/array-uint8' );
191
49
  *
192
- * var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );
193
- * // returns <ArrayIndex>
50
+ * var x = new Uint8Array( [ 1, 0, 1, 0 ] );
194
51
  *
195
- * var str = idx.toString();
196
- * // e.g., 'ArrayIndex<0>'
197
- */
198
- toString(): string;
199
- }
200
-
201
- /**
202
- * Interface describing a mask array index object.
203
- */
204
- interface MaskArrayIndex extends BaseArrayIndex {
205
- /**
206
- * Read-only property returning the array index type.
207
- */
208
- type: 'mask';
209
-
210
- /**
211
- * Read-only property returning the underlying array index data type.
212
- */
213
- dtype: 'uint8';
214
-
215
- /**
216
- * Read-only property returning the underlying array data.
217
- */
218
- data: Uint8Array;
219
- }
220
-
221
- /**
222
- * Interface describing an integer array index object.
223
- */
224
- interface Int32ArrayIndex extends BaseArrayIndex {
225
- /**
226
- * Read-only property returning the array index type.
227
- */
228
- type: 'int';
229
-
230
- /**
231
- * Read-only property returning the underlying array index data type.
232
- */
233
- dtype: 'int32';
234
-
235
- /**
236
- * Read-only property returning the underlying array data.
237
- */
238
- data: Int32Array;
239
- }
240
-
241
- /**
242
- * Interface describing a boolean array index object.
243
- */
244
- interface BooleanArrayIndex extends BaseArrayIndex {
245
- /**
246
- * Read-only property returning the array index type.
247
- */
248
- type: 'bool';
249
-
250
- /**
251
- * Read-only property returning the underlying array index data type.
252
- */
253
- dtype: 'generic';
254
-
255
- /**
256
- * Read-only property returning the underlying array data.
257
- */
258
- data: BooleanIndexArray;
259
- }
260
-
261
- /**
262
- * Interface describing an integer array index object.
263
- */
264
- interface IntegerArrayIndex extends BaseArrayIndex {
265
- /**
266
- * Read-only property returning the array index type.
267
- */
268
- type: 'int';
269
-
270
- /**
271
- * Read-only property returning the underlying array index data type.
52
+ * var idx = new ArrayIndex( x );
53
+ * // returns <ArrayIndex>
272
54
  */
273
- dtype: 'generic';
55
+ new( x: Uint8Array, options?: Options ): MaskArrayIndex;
274
56
 
275
- /**
276
- * Read-only property returning the underlying array data.
277
- */
278
- data: IntegerIndexArray;
279
- }
280
-
281
- /**
282
- * Array index object.
283
- */
284
- type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex;
285
-
286
- /**
287
- * Interface defining an `ArrayIndex` constructor which is both "newable" and "callable".
288
- */
289
- interface Constructor {
290
57
  /**
291
58
  * Array index constructor.
292
59
  *
@@ -296,14 +63,14 @@ interface Constructor {
296
63
  * @returns ArrayIndex instance
297
64
  *
298
65
  * @example
299
- * var Uint8Array = require( '@stdlib/array-uint8' );
66
+ * var BooleanArray = require( '@stdlib/array-bool' );
300
67
  *
301
- * var x = new Uint8Array( [ 1, 0, 1, 0 ] );
68
+ * var x = new BooleanArray( [ true, false, true, false ] );
302
69
  *
303
70
  * var idx = new ArrayIndex( x );
304
71
  * // returns <ArrayIndex>
305
72
  */
306
- new( x: Uint8Array, options?: Options ): MaskArrayIndex;
73
+ new( x: BooleanArray, options?: Options ): BooleanArrayIndex;
307
74
 
308
75
  /**
309
76
  * Array index constructor.
@@ -337,7 +104,7 @@ interface Constructor {
337
104
  * var idx = new ArrayIndex( x );
338
105
  * // returns <ArrayIndex>
339
106
  */
340
- new( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex;
107
+ new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex;
341
108
 
342
109
  /**
343
110
  * Array index constructor.
@@ -353,7 +120,7 @@ interface Constructor {
353
120
  * var idx = new ArrayIndex( x );
354
121
  * // returns <ArrayIndex>
355
122
  */
356
- new( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex;
123
+ new( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex;
357
124
 
358
125
  /**
359
126
  * Array index constructor.
@@ -372,6 +139,7 @@ interface Constructor {
372
139
  * // returns <ArrayIndex>
373
140
  */
374
141
  new( x: IndexArray, options?: Options ): ArrayIndex;
142
+
375
143
  /**
376
144
  * Array index constructor.
377
145
  *
@@ -390,6 +158,24 @@ interface Constructor {
390
158
  */
391
159
  ( x: Uint8Array, options?: Options ): MaskArrayIndex;
392
160
 
161
+ /**
162
+ * Array index constructor.
163
+ *
164
+ * @param x - input array
165
+ * @param options - function options
166
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
167
+ * @returns ArrayIndex instance
168
+ *
169
+ * @example
170
+ * var BooleanArray = require( '@stdlib/array-bool' );
171
+ *
172
+ * var x = new BooleanArray( [ true, false, true, false ] );
173
+ *
174
+ * var idx = ArrayIndex( x );
175
+ * // returns <ArrayIndex>
176
+ */
177
+ ( x: BooleanArray, options?: Options ): BooleanArrayIndex;
178
+
393
179
  /**
394
180
  * Array index constructor.
395
181
  *
@@ -422,7 +208,7 @@ interface Constructor {
422
208
  * var idx = ArrayIndex( x );
423
209
  * // returns <ArrayIndex>
424
210
  */
425
- ( x: IntegerIndexArray, options?: Options ): IntegerArrayIndex;
211
+ ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex;
426
212
 
427
213
  /**
428
214
  * Array index constructor.
@@ -438,7 +224,7 @@ interface Constructor {
438
224
  * var idx = ArrayIndex( x );
439
225
  * // returns <ArrayIndex>
440
226
  */
441
- ( x: BooleanIndexArray, options?: Options ): BooleanArrayIndex;
227
+ ( x: GenericBooleanIndexArray, options?: Options ): GenericBooleanArrayIndex;
442
228
 
443
229
  /**
444
230
  * Array index constructor.
@@ -512,7 +298,7 @@ interface Constructor {
512
298
  * var dt = o.dtype;
513
299
  * // returns 'uint8'
514
300
  */
515
- get<T extends BaseArrayObject = ArrayObject>( id: string ): T;
301
+ get<T extends BaseIndexArrayObject = IndexArrayObject>( id: string ): T | null;
516
302
  }
517
303
 
518
304
  /**
package/lib/main.js CHANGED
@@ -83,21 +83,27 @@ function ArrayIndex( x ) {
83
83
 
84
84
  // When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array...
85
85
  if ( dt === 'generic' || dt === null ) {
86
- get = resolveGetter( x );
87
- v = get( x, 0 );
88
-
89
- // Infer the "type" of index array from the first element...
90
- if ( isBoolean( v ) ) {
91
- t = 'bool';
92
- } else if ( isInteger( v ) ) {
93
- t = 'int';
86
+ if ( x.length > 0 ) {
87
+ get = resolveGetter( x );
88
+ v = get( x, 0 );
89
+
90
+ // Infer the "type" of index array from the first element...
91
+ if ( isBoolean( v ) ) {
92
+ t = 'bool';
93
+ } else if ( isInteger( v ) ) {
94
+ t = 'int';
95
+ } else {
96
+ throw new TypeError( 'invalid argument. First argument must be a valid index array.' );
97
+ }
94
98
  } else {
95
- throw new TypeError( 'invalid argument. First argument must be a valid index array.' );
99
+ t = 'int';
96
100
  }
97
101
  } else if ( dt === 'int32' ) {
98
102
  t = 'int';
99
103
  } else if ( dt === 'uint8' ) {
100
104
  t = 'mask';
105
+ } else if ( dt === 'bool' ) {
106
+ t = 'bool';
101
107
  } else {
102
108
  throw new TypeError( 'invalid argument. First argument must be a valid index array.' );
103
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/array-index",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Array index constructor.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,19 +15,12 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "directories": {
18
- "benchmark": "./benchmark",
19
18
  "doc": "./docs",
20
- "example": "./examples",
21
19
  "lib": "./lib",
22
- "test": "./test"
20
+ "dist": "./dist"
23
21
  },
24
22
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
23
+ "scripts": {},
31
24
  "homepage": "https://stdlib.io",
32
25
  "repository": {
33
26
  "type": "git",
@@ -37,36 +30,24 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/array-base-assert-is-accessor-array": "^0.2.0",
41
- "@stdlib/array-base-copy": "^0.2.0",
42
- "@stdlib/array-base-resolve-getter": "^0.2.0",
43
- "@stdlib/array-dtype": "^0.2.0",
44
- "@stdlib/array-to-json": "^0.2.0",
45
- "@stdlib/assert-has-own-property": "^0.2.0",
46
- "@stdlib/assert-is-boolean": "^0.2.0",
47
- "@stdlib/assert-is-collection": "^0.2.0",
48
- "@stdlib/assert-is-integer": "^0.2.0",
49
- "@stdlib/assert-is-plain-object": "^0.2.0",
50
- "@stdlib/string-format": "^0.2.0",
51
- "@stdlib/types": "^0.3.1",
52
- "@stdlib/utils-define-nonenumerable-property": "^0.2.0",
53
- "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0",
54
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
55
- "@stdlib/utils-linked-list": "^0.2.0",
56
- "@stdlib/error-tools-fmtprodmsg": "^0.2.0"
57
- },
58
- "devDependencies": {
59
- "@stdlib/array-base-to-accessor-array": "^0.1.0",
60
- "@stdlib/array-int32": "^0.2.0",
61
- "@stdlib/array-uint8": "^0.2.0",
62
- "@stdlib/assert-instance-of": "^0.2.0",
63
- "@stdlib/assert-is-string": "^0.2.0",
64
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
65
- "istanbul": "^0.4.1",
66
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
67
- "@stdlib/bench-harness": "^0.2.0",
68
- "@stdlib/bench": "^0.3.1"
33
+ "@stdlib/array-base-assert-is-accessor-array": "^0.2.2",
34
+ "@stdlib/array-base-copy": "^0.2.1",
35
+ "@stdlib/array-base-resolve-getter": "^0.2.1",
36
+ "@stdlib/array-dtype": "^0.2.1",
37
+ "@stdlib/array-to-json": "^0.3.0",
38
+ "@stdlib/assert-has-own-property": "^0.2.2",
39
+ "@stdlib/assert-is-boolean": "^0.2.2",
40
+ "@stdlib/assert-is-collection": "^0.2.2",
41
+ "@stdlib/assert-is-integer": "^0.2.2",
42
+ "@stdlib/assert-is-plain-object": "^0.2.2",
43
+ "@stdlib/string-format": "^0.2.2",
44
+ "@stdlib/utils-define-nonenumerable-property": "^0.2.2",
45
+ "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3",
46
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
47
+ "@stdlib/utils-linked-list": "^0.2.2",
48
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
69
49
  },
50
+ "devDependencies": {},
70
51
  "engines": {
71
52
  "node": ">=0.10.0",
72
53
  "npm": ">2.7.0"