Skip to content

Commit e6bea97

Browse files
committed
Refactor and rename base array utility to return accessors for each indexed array dtype
1 parent c9e5213 commit e6bea97

File tree

15 files changed

+1155
-292
lines changed

15 files changed

+1155
-292
lines changed

lib/node_modules/@stdlib/array/base/get/docs/repl.txt

-27
This file was deleted.

lib/node_modules/@stdlib/array/base/get/docs/types/index.d.ts

-43
This file was deleted.

lib/node_modules/@stdlib/array/base/get/docs/types/test.ts

-54
This file was deleted.

lib/node_modules/@stdlib/array/base/get/lib/main.js

-43
This file was deleted.

lib/node_modules/@stdlib/array/base/get/test/test.js

-93
This file was deleted.

lib/node_modules/@stdlib/array/base/get/README.md renamed to lib/node_modules/@stdlib/array/base/getter/README.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ limitations under the License.
1818
1919
-->
2020

21-
# get
21+
# getter
2222

23-
> Return an element from an indexed array-like object.
23+
> Return an accessor function for retrieving an element from an indexed array-like object.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -37,20 +37,26 @@ limitations under the License.
3737
## Usage
3838

3939
```javascript
40-
var get = require( '@stdlib/array/base/get' );
40+
var getter = require( '@stdlib/array/base/getter' );
4141
```
4242

43-
#### get( arr, idx )
43+
#### getter( dtype )
4444

45-
Returns an element from an indexed array-like object.
45+
Returns an accessor function for retrieving an element from an indexed array-like object.
4646

4747
```javascript
4848
var arr = [ 1, 2, 3, 4 ];
4949

50+
var get = getter( 'generic' );
5051
var v = get( arr, 2 );
5152
// returns 3
5253
```
5354

55+
The returned accessor function accepts the following arguments:
56+
57+
- **arr**: input array.
58+
- **idx**: element index.
59+
5460
</section>
5561

5662
<!-- /.usage -->
@@ -61,7 +67,9 @@ var v = get( arr, 2 );
6167

6268
## Notes
6369

64-
- The function does **not** perform bounds checking.
70+
- If provided an unrecognized [`dtype`][@stdlib/array/dtypes], the function returns a default accessor function for accessing elements from any indexed array-like object; otherwise, the function returns an accessor function which should **only** be provided an array instance corresponding to `dtype` (e.g., if `dtype` is `'float64'`, the returned accessor function should only be provided instances of `Float64Array`).
71+
- Accessor functions do **not** verify that provided input arrays are array instances corresponding to `dtype`, as doing so would introduce performance overhead. If array instances corresponding to other data types are provided to an accessor function, JavaScript runtimes will consider the function polymorphic, potentially triggering de-optimization. In order to ensure maximum performance, **always** ensure that an accessor function is monomorphic.
72+
- Accessor functions do **not** perform bounds checking.
6573
- An _indexed_ array-like object is a data structure in which one retrieves elements via integer indices via bracket `[]` notation (e.g., `Float64Array`, `Int32Array`, `Array`, etc). This is in contrast to an _accessor_ array-like object in which one retrieves elements using `get` and `set` methods (e.g., `Complex64Array` and `Complex128Array`).
6674

6775
</section>
@@ -78,42 +86,43 @@ var v = get( arr, 2 );
7886

7987
```javascript
8088
var filled = require( '@stdlib/array/filled' );
81-
var get = require( '@stdlib/array/base/get' );
89+
var dtype = require( '@stdlib/array/dtype' );
90+
var getter = require( '@stdlib/array/base/getter' );
8291

8392
var arr = filled( 1.0, 10, 'float64' );
84-
var v = get( arr, 2 );
93+
var v = getter( dtype( arr ) )( arr, 2 );
8594
// returns 1.0
8695

8796
arr = filled( 2.0, 10, 'float32' );
88-
v = get( arr, 2 );
97+
v = getter( dtype( arr ) )( arr, 2 );
8998
// returns 2.0
9099

91100
arr = filled( 3, 10, 'int32' );
92-
v = get( arr, 2 );
101+
v = getter( dtype( arr ) )( arr, 2 );
93102
// returns 3
94103

95104
arr = filled( 4, 10, 'int16' );
96-
v = get( arr, 2 );
105+
v = getter( dtype( arr ) )( arr, 2 );
97106
// returns 4
98107

99108
arr = filled( 5, 10, 'int8' );
100-
v = get( arr, 2 );
109+
v = getter( dtype( arr ) )( arr, 2 );
101110
// returns 5
102111

103112
arr = filled( 6, 10, 'uint32' );
104-
v = get( arr, 2 );
113+
v = getter( dtype( arr ) )( arr, 2 );
105114
// returns 6
106115

107116
arr = filled( 7, 10, 'uint16' );
108-
v = get( arr, 2 );
117+
v = getter( dtype( arr ) )( arr, 2 );
109118
// returns 7
110119

111120
arr = filled( 8, 10, 'uint8' );
112-
v = get( arr, 2 );
121+
v = getter( dtype( arr ) )( arr, 2 );
113122
// returns 8
114123

115124
arr = filled( 9, 10, 'uint8c' );
116-
v = get( arr, 2 );
125+
v = getter( dtype( arr ) )( arr, 2 );
117126
// returns 9
118127
```
119128

@@ -141,6 +150,8 @@ v = get( arr, 2 );
141150

142151
<section class="links">
143152

153+
[@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib
154+
144155
</section>
145156

146157
<!-- /.links -->

0 commit comments

Comments
 (0)