@fluid-experimental/property-common 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229
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/.eslintrc.js +9 -11
- package/.mocharc.json +6 -6
- package/README.md +1 -0
- package/api-extractor.json +2 -2
- package/dist/chronometer.d.ts.map +1 -1
- package/dist/chronometer.js.map +1 -1
- package/dist/consoleUtils.d.ts.map +1 -1
- package/dist/consoleUtils.js +4 -1
- package/dist/consoleUtils.js.map +1 -1
- package/dist/constants.d.ts +6 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -26
- package/dist/constants.js.map +1 -1
- package/dist/datastructures/collection.d.ts.map +1 -1
- package/dist/datastructures/collection.js +5 -4
- package/dist/datastructures/collection.js.map +1 -1
- package/dist/datastructures/dataArray.d.ts.map +1 -1
- package/dist/datastructures/dataArray.js +18 -9
- package/dist/datastructures/dataArray.js.map +1 -1
- package/dist/datastructures/integer64.d.ts.map +1 -1
- package/dist/datastructures/integer64.js +1 -1
- package/dist/datastructures/integer64.js.map +1 -1
- package/dist/datastructures/sortedCollection.d.ts.map +1 -1
- package/dist/datastructures/sortedCollection.js +3 -1
- package/dist/datastructures/sortedCollection.js.map +1 -1
- package/dist/deferredPromise.d.ts +1 -1
- package/dist/deferredPromise.d.ts.map +1 -1
- package/dist/deferredPromise.js +9 -3
- package/dist/deferredPromise.js.map +1 -1
- package/dist/deterministicRandomGenerator.d.ts.map +1 -1
- package/dist/deterministicRandomGenerator.js +6 -6
- package/dist/deterministicRandomGenerator.js.map +1 -1
- package/dist/error_objects/flaggedError.d.ts.map +1 -1
- package/dist/error_objects/flaggedError.js.map +1 -1
- package/dist/error_objects/httpError.d.ts.map +1 -1
- package/dist/error_objects/httpError.js +9 -9
- package/dist/error_objects/httpError.js.map +1 -1
- package/dist/error_objects/httpErrorNoStack.d.ts.map +1 -1
- package/dist/error_objects/httpErrorNoStack.js.map +1 -1
- package/dist/error_objects/operationError.d.ts +7 -7
- package/dist/error_objects/operationError.d.ts.map +1 -1
- package/dist/error_objects/operationError.js +7 -7
- package/dist/error_objects/operationError.js.map +1 -1
- package/dist/guidUtils.d.ts.map +1 -1
- package/dist/guidUtils.js +10 -9
- package/dist/guidUtils.js.map +1 -1
- package/dist/hashCalculator.d.ts.map +1 -1
- package/dist/hashCalculator.js.map +1 -1
- package/dist/joinPaths.d.ts.map +1 -1
- package/dist/joinPaths.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/chronometer.d.ts.map +1 -1
- package/lib/chronometer.js.map +1 -1
- package/lib/consoleUtils.d.ts.map +1 -1
- package/lib/consoleUtils.js +4 -1
- package/lib/consoleUtils.js.map +1 -1
- package/lib/constants.d.ts +6 -6
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +16 -26
- package/lib/constants.js.map +1 -1
- package/lib/datastructures/collection.d.ts.map +1 -1
- package/lib/datastructures/collection.js +5 -4
- package/lib/datastructures/collection.js.map +1 -1
- package/lib/datastructures/dataArray.d.ts.map +1 -1
- package/lib/datastructures/dataArray.js +18 -9
- package/lib/datastructures/dataArray.js.map +1 -1
- package/lib/datastructures/integer64.d.ts.map +1 -1
- package/lib/datastructures/integer64.js +1 -1
- package/lib/datastructures/integer64.js.map +1 -1
- package/lib/datastructures/sortedCollection.d.ts.map +1 -1
- package/lib/datastructures/sortedCollection.js +3 -1
- package/lib/datastructures/sortedCollection.js.map +1 -1
- package/lib/deferredPromise.d.ts +1 -1
- package/lib/deferredPromise.d.ts.map +1 -1
- package/lib/deferredPromise.js +9 -3
- package/lib/deferredPromise.js.map +1 -1
- package/lib/deterministicRandomGenerator.d.ts.map +1 -1
- package/lib/deterministicRandomGenerator.js +6 -6
- package/lib/deterministicRandomGenerator.js.map +1 -1
- package/lib/error_objects/flaggedError.d.ts.map +1 -1
- package/lib/error_objects/flaggedError.js.map +1 -1
- package/lib/error_objects/httpError.d.ts.map +1 -1
- package/lib/error_objects/httpError.js +9 -9
- package/lib/error_objects/httpError.js.map +1 -1
- package/lib/error_objects/httpErrorNoStack.d.ts.map +1 -1
- package/lib/error_objects/httpErrorNoStack.js.map +1 -1
- package/lib/error_objects/operationError.d.ts +7 -7
- package/lib/error_objects/operationError.d.ts.map +1 -1
- package/lib/error_objects/operationError.js +7 -7
- package/lib/error_objects/operationError.js.map +1 -1
- package/lib/guidUtils.d.ts.map +1 -1
- package/lib/guidUtils.js +10 -9
- package/lib/guidUtils.js.map +1 -1
- package/lib/hashCalculator.d.ts.map +1 -1
- package/lib/hashCalculator.js.map +1 -1
- package/lib/joinPaths.d.ts.map +1 -1
- package/lib/joinPaths.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +42 -40
- package/platform-dependent/README.md +1 -0
- package/platform-dependent/browser.js +5 -5
- package/platform-dependent/package.json +14 -14
- package/platform-dependent/server.js +5 -5
- package/prettier.config.cjs +1 -1
- package/src/chronometer.ts +174 -169
- package/src/consoleUtils.ts +16 -11
- package/src/constants.ts +1683 -1640
- package/src/datastructures/collection.ts +417 -416
- package/src/datastructures/dataArray.ts +516 -492
- package/src/datastructures/integer64.ts +102 -99
- package/src/datastructures/sortedCollection.ts +155 -145
- package/src/deferredPromise.ts +43 -42
- package/src/deterministicRandomGenerator.ts +59 -59
- package/src/error_objects/flaggedError.ts +29 -29
- package/src/error_objects/httpError.ts +45 -42
- package/src/error_objects/httpErrorNoStack.ts +17 -17
- package/src/error_objects/operationError.ts +62 -62
- package/src/guidUtils.ts +182 -171
- package/src/hashCalculator.ts +5 -2
- package/src/joinPaths.ts +15 -9
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
|
@@ -15,307 +15,316 @@
|
|
|
15
15
|
* as a backing store for collaborative property sets.
|
|
16
16
|
*/
|
|
17
17
|
class BaseDataArray {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
18
|
+
protected _buffer: any;
|
|
19
|
+
private readonly bufferConstructor;
|
|
20
|
+
protected size: number;
|
|
21
|
+
|
|
22
|
+
constructor(size: number);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param bufferConstructor - This is the constructor to be used to setup the internal buffer of the DataArray.
|
|
26
|
+
* @param size - The initial size with which to allocate the array.
|
|
27
|
+
*/
|
|
28
|
+
constructor(bufferConstructor: any, size: number);
|
|
29
|
+
constructor(a, b?) {
|
|
30
|
+
if (typeof a === "number") {
|
|
31
|
+
this.size = a;
|
|
32
|
+
this.bufferConstructor = this.getBufferCtor();
|
|
33
|
+
} else {
|
|
34
|
+
this.bufferConstructor = a;
|
|
35
|
+
this.size = b;
|
|
36
|
+
}
|
|
37
|
+
// The 'eslint-...' is used to disable the rule that requires
|
|
38
|
+
// constructors to start with a capitalized letter.
|
|
39
|
+
this._buffer = new this.bufferConstructor(this.size);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the value at an index. If no index is passed, return zeroth item.
|
|
44
|
+
* @param in_idx - The specific item in the data array.
|
|
45
|
+
* @returns The value at that index.
|
|
46
|
+
*/
|
|
47
|
+
getValue(in_idx = 0): any {
|
|
48
|
+
if (in_idx >= this.size || in_idx < 0) {
|
|
49
|
+
throw new Error("Trying to access out of bounds!");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this._buffer[in_idx];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Return a range of values in the array.
|
|
57
|
+
* @param in_idxStart - the starting index
|
|
58
|
+
* @param in_idxEnd - the end index
|
|
59
|
+
* @returns the array of values in the range
|
|
60
|
+
*/
|
|
61
|
+
getValueRange(in_idxStart: number, in_idxEnd: number) {
|
|
62
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
63
|
+
throw new Error("Trying to access out of bounds!");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return this._buffer.subarray(in_idxStart, in_idxEnd);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Return the serialized form of Data Arrays.
|
|
71
|
+
* @returns An object containing an array of the values.
|
|
72
|
+
*/
|
|
73
|
+
serialize(): number[] {
|
|
74
|
+
return Array.from(this._buffer.subarray(0, this.size));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Deserialize data from a serialized representation
|
|
79
|
+
* @param in_serialized - the serialized representation
|
|
80
|
+
*/
|
|
81
|
+
deserialize(in_serialized) {
|
|
82
|
+
const values = in_serialized;
|
|
83
|
+
const length = in_serialized.length;
|
|
84
|
+
if (length !== this.size) {
|
|
85
|
+
this.resize(length);
|
|
86
|
+
this.size = length;
|
|
87
|
+
}
|
|
88
|
+
let i;
|
|
89
|
+
for (i = 0; i < length; i++) {
|
|
90
|
+
this._buffer[i] = values[i];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set value at an index.
|
|
96
|
+
* @param in_idx - the index
|
|
97
|
+
* @param in_value - the value we want to set at index
|
|
98
|
+
*/
|
|
99
|
+
setValue(in_idx: number, in_value) {
|
|
100
|
+
if (in_idx < this._buffer.length) {
|
|
101
|
+
this._buffer[in_idx] = in_value;
|
|
102
|
+
} else {
|
|
103
|
+
console.error("DataArray setValue in_idx is out of bounds.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* creates a copy of a typed array with removed elements
|
|
109
|
+
* @param in_arr - the input array (won't be modified)
|
|
110
|
+
* @param in_offset - starting index of range that will be removed
|
|
111
|
+
* @param in_deleteCount - number of removed elements
|
|
112
|
+
* @returns a copy of the input array without the selected range
|
|
113
|
+
*/
|
|
114
|
+
private _removeElementsFromArray(in_arr, in_offset: number, in_deleteCount: number) {
|
|
115
|
+
// TODO: this function can be optimized
|
|
116
|
+
const newSize = this.size - in_deleteCount;
|
|
117
|
+
const splicedArray = new in_arr.constructor(newSize);
|
|
118
|
+
splicedArray.set(in_arr.subarray(0, in_offset));
|
|
119
|
+
splicedArray.set(in_arr.subarray(in_offset + in_deleteCount, this.size), in_offset);
|
|
120
|
+
return splicedArray;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* remove a range of elements from the array
|
|
125
|
+
* @param in_offset - start of the range
|
|
126
|
+
* @param in_deleteCount - number of elements to be removed
|
|
127
|
+
*/
|
|
128
|
+
removeRange(in_offset: number, in_deleteCount: number) {
|
|
129
|
+
if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {
|
|
130
|
+
this._buffer = this._removeElementsFromArray(this._buffer, in_offset, in_deleteCount);
|
|
131
|
+
this.size = this.size - in_deleteCount;
|
|
132
|
+
} else {
|
|
133
|
+
console.error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* copy an array with elements inserted into the copy
|
|
139
|
+
* @param in_arr - the input array (won't be modified)
|
|
140
|
+
* @param in_offset - the index where the new elements will be inserted
|
|
141
|
+
* @param in_addedArray - the array with the elements that will be added
|
|
142
|
+
* @returns the combined array
|
|
143
|
+
*/
|
|
144
|
+
private _insert(in_arr, in_offset: number, in_addedArray) {
|
|
145
|
+
// TODO: this function can be optimized
|
|
146
|
+
const newSize = this.size + (in_addedArray.length as number);
|
|
147
|
+
const insertedArray = new in_arr.constructor(newSize);
|
|
148
|
+
insertedArray.set(in_arr.subarray(0, in_offset));
|
|
149
|
+
insertedArray.set(in_addedArray, in_offset);
|
|
150
|
+
insertedArray.set(
|
|
151
|
+
in_arr.subarray(in_offset, this.size),
|
|
152
|
+
in_offset + (in_addedArray.length as number),
|
|
153
|
+
);
|
|
154
|
+
return insertedArray;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* insert the content of an array into the DataArray
|
|
159
|
+
* @param in_offset - the target index
|
|
160
|
+
* @param in_array - the array to be inserted
|
|
161
|
+
*/
|
|
162
|
+
insertRange(in_offset: number, in_array) {
|
|
163
|
+
this._buffer = this._insert(this._buffer, in_offset, in_array);
|
|
164
|
+
this.size = this.size + (in_array.length as number);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Set this array values to be equal to in_array values.
|
|
169
|
+
* @param in_offset - An optional offset in this array to begin start setting this arrays values to in_array values.
|
|
170
|
+
* @param in_array - The input array.
|
|
171
|
+
*/
|
|
172
|
+
set(in_offset: number, in_array) {
|
|
173
|
+
if (
|
|
174
|
+
in_array instanceof ArrayBuffer ||
|
|
175
|
+
in_array instanceof Array ||
|
|
176
|
+
in_array instanceof this.getBufferCtor()
|
|
177
|
+
) {
|
|
178
|
+
this._buffer.set(in_array, in_offset);
|
|
179
|
+
} else if (in_array instanceof BaseDataArray) {
|
|
180
|
+
this._buffer.set(in_array.getBuffer(), in_offset);
|
|
181
|
+
} else {
|
|
182
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Insert a value at the end of the array, creates a new element at the end and sets the value.
|
|
188
|
+
* @param in_value - The new value.
|
|
189
|
+
*/
|
|
190
|
+
push(in_value) {
|
|
191
|
+
// Adjust the buffer if necessary
|
|
192
|
+
const bufferLength = this._buffer.length;
|
|
193
|
+
if (this.size > bufferLength - 1) {
|
|
194
|
+
this._alloc(this.size * 2 || 1); // grow by a factor of 2x
|
|
195
|
+
}
|
|
196
|
+
// set the value and update size
|
|
197
|
+
this.setValue(this.size, in_value);
|
|
198
|
+
this.size++;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get direct access to the data (for performance reasons) this should be uses read only.
|
|
203
|
+
* @returns The (read only) raw data.
|
|
204
|
+
*/
|
|
205
|
+
getBuffer() {
|
|
206
|
+
return this._buffer;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get the constructor of the underlying `TypedArray`.
|
|
211
|
+
* @returns The constructor for the data buffer.
|
|
212
|
+
*/
|
|
213
|
+
getBufferCtor() {
|
|
214
|
+
return this.bufferConstructor;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Apply a given function to all elements of the array.
|
|
219
|
+
* @param in_fn - The function that will be applied to every element.
|
|
220
|
+
*/
|
|
221
|
+
iterate(in_fn) {
|
|
222
|
+
const l = this.size;
|
|
223
|
+
for (let i = 0; i < l; i++) {
|
|
224
|
+
in_fn(this._buffer[i]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Tet a resized buffer copy.
|
|
230
|
+
* @param in_bufferCtor - The constructor for the returned buffer.
|
|
231
|
+
* @param in_buffer - The input buffer (won't be modified).
|
|
232
|
+
* @param in_newSize - The target size.
|
|
233
|
+
* @returns The buffer with the new size.
|
|
234
|
+
*/
|
|
235
|
+
private resizeBuffer(in_bufferCtor, in_buffer, in_newSize: number) {
|
|
236
|
+
// target buffer with the desired new size
|
|
237
|
+
// The 'eslint-...' is used to disable the rule that requires
|
|
238
|
+
// constructors to start with a capitalized letter.
|
|
239
|
+
const newBuffer = new in_bufferCtor(in_newSize);
|
|
240
|
+
const oldSize = in_buffer.length;
|
|
241
|
+
const oldBuffer = in_buffer;
|
|
242
|
+
const isShrinking = oldSize > in_newSize;
|
|
243
|
+
newBuffer.set(isShrinking ? oldBuffer.subarray(0, in_newSize) : oldBuffer);
|
|
244
|
+
return newBuffer;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Allocate memory for the array (for performance reasons, you can allocate more space than the current length,
|
|
249
|
+
* which makes pushes to the array less expensive later).
|
|
250
|
+
* @param size - The target allocated space.
|
|
251
|
+
* @returns The DataArray itself.
|
|
252
|
+
*/
|
|
253
|
+
protected _alloc(size: number): any {
|
|
254
|
+
this._buffer = this.resizeBuffer(this.bufferConstructor, this._buffer, size);
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Change the size of the array
|
|
260
|
+
* @param size - The target size
|
|
261
|
+
* @returns The DataArray itself
|
|
262
|
+
*/
|
|
263
|
+
resize(size: number) {
|
|
264
|
+
// this can be costly!!!
|
|
265
|
+
this._alloc(size);
|
|
266
|
+
this.size = size;
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
copy() {
|
|
271
|
+
// and this!
|
|
272
|
+
const newBuffer = new this.bufferConstructor(this.size); // buffer with the desired new size
|
|
273
|
+
newBuffer.set(this._buffer);
|
|
274
|
+
return newBuffer;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
get length() {
|
|
278
|
+
return this.size;
|
|
279
|
+
}
|
|
271
280
|
}
|
|
272
281
|
|
|
273
282
|
class Int8DataArray extends BaseDataArray {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
283
|
+
constructor(size: number) {
|
|
284
|
+
super(Int8Array, size);
|
|
285
|
+
}
|
|
277
286
|
}
|
|
278
287
|
|
|
279
288
|
class Int16DataArray extends BaseDataArray {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
289
|
+
constructor(size: number) {
|
|
290
|
+
super(Int16Array, size);
|
|
291
|
+
}
|
|
283
292
|
}
|
|
284
293
|
|
|
285
294
|
class Int32DataArray extends BaseDataArray {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
295
|
+
constructor(size: number) {
|
|
296
|
+
super(Int32Array, size);
|
|
297
|
+
}
|
|
289
298
|
}
|
|
290
299
|
|
|
291
300
|
class Uint8DataArray extends BaseDataArray {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
301
|
+
constructor(size: number) {
|
|
302
|
+
super(Uint8Array, size);
|
|
303
|
+
}
|
|
295
304
|
}
|
|
296
305
|
|
|
297
306
|
class Uint16DataArray extends BaseDataArray {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
307
|
+
constructor(size: number) {
|
|
308
|
+
super(Uint16Array, size);
|
|
309
|
+
}
|
|
301
310
|
}
|
|
302
311
|
|
|
303
312
|
class Uint32DataArray extends BaseDataArray {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
313
|
+
constructor(size: number) {
|
|
314
|
+
super(Uint32Array, size);
|
|
315
|
+
}
|
|
307
316
|
}
|
|
308
317
|
|
|
309
318
|
class Float32DataArray extends BaseDataArray {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
319
|
+
constructor(size: number) {
|
|
320
|
+
super(Float32Array, size);
|
|
321
|
+
}
|
|
313
322
|
}
|
|
314
323
|
|
|
315
324
|
class Float64DataArray extends BaseDataArray {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
325
|
+
constructor(size: number) {
|
|
326
|
+
super(Float64Array, size);
|
|
327
|
+
}
|
|
319
328
|
}
|
|
320
329
|
|
|
321
330
|
/**
|
|
@@ -324,234 +333,249 @@ class Float64DataArray extends BaseDataArray {
|
|
|
324
333
|
* @param size - The initial size with which to allocate the array.
|
|
325
334
|
*/
|
|
326
335
|
class UniversalDataArray extends BaseDataArray {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
336
|
+
constructor(bufferConstructor: any, size: number);
|
|
337
|
+
constructor(size: number);
|
|
338
|
+
constructor(a?, b?) {
|
|
339
|
+
if (b === undefined) {
|
|
340
|
+
super(Array, a);
|
|
341
|
+
} else {
|
|
342
|
+
super(a, b);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Helper function to write array values into another array at a given offset.
|
|
348
|
+
*
|
|
349
|
+
* @param array - The target array.
|
|
350
|
+
* @param values - The values we need to write.
|
|
351
|
+
* @param offset - The starting index in target array.
|
|
352
|
+
*/
|
|
353
|
+
private arraySet(array, values, offset = 0) {
|
|
354
|
+
let index = 0;
|
|
355
|
+
values.forEach(function (value) {
|
|
356
|
+
array[index + offset] = value;
|
|
357
|
+
index++;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Insert the content of an array into the DataArray.
|
|
363
|
+
* @param in_offset - The target index.
|
|
364
|
+
* @param in_array - The array to be inserted.
|
|
365
|
+
*/
|
|
366
|
+
insertRange(in_offset: number, in_array: any[]) {
|
|
367
|
+
this._buffer.splice.call(this._buffer, ...[in_offset, 0].concat(in_array));
|
|
368
|
+
this.size = this.size + in_array.length;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Eemove a range of elements from the array.
|
|
373
|
+
* @param in_offset - The start of the range.
|
|
374
|
+
* @param in_deleteCount - The number of elements to be removed.
|
|
375
|
+
*/
|
|
376
|
+
removeRange(in_offset: number, in_deleteCount: number) {
|
|
377
|
+
if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {
|
|
378
|
+
this._buffer.splice(in_offset, in_deleteCount);
|
|
379
|
+
this.size -= in_deleteCount;
|
|
380
|
+
} else {
|
|
381
|
+
throw Error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Set this array values to be equal to in_array values.
|
|
387
|
+
* @param in_offset - An optional offset in this array to begin start
|
|
388
|
+
* setting this arrays values to in_array values.
|
|
389
|
+
* @param in_array - The input array.
|
|
390
|
+
*/
|
|
391
|
+
set(in_offset: number, in_array) {
|
|
392
|
+
if (
|
|
393
|
+
in_array instanceof ArrayBuffer ||
|
|
394
|
+
in_array instanceof Array ||
|
|
395
|
+
in_array instanceof this.getBufferCtor()
|
|
396
|
+
) {
|
|
397
|
+
this.arraySet(this._buffer, in_array, in_offset);
|
|
398
|
+
} else if (in_array instanceof BaseDataArray) {
|
|
399
|
+
this.arraySet(this._buffer, in_array.getBuffer(), in_offset);
|
|
400
|
+
} else {
|
|
401
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Return a range of values in the array.
|
|
407
|
+
* @param in_idxStart - the starting index
|
|
408
|
+
* @param in_idxEnd - the end index - this offset is exclusive
|
|
409
|
+
* @returns the array of values in the range
|
|
410
|
+
*/
|
|
411
|
+
getValueRange(in_idxStart: number, in_idxEnd: number) {
|
|
412
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
413
|
+
throw new Error("Trying to access out of bounds!");
|
|
414
|
+
}
|
|
415
|
+
return this._buffer.slice(in_idxStart, in_idxEnd);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* change the size of a javascript array and keep the content, if possible. Keeps the input buffer.
|
|
420
|
+
* @param in_buffer - input buffer - not changed
|
|
421
|
+
* @param in_newSize - target size
|
|
422
|
+
* @returns an Array of the new size
|
|
423
|
+
*/
|
|
424
|
+
private resizeBufferArray(in_buffer, in_newSize) {
|
|
425
|
+
// target buffer with the desired new size
|
|
426
|
+
const newBuffer = new Array(in_newSize);
|
|
427
|
+
const oldSize = in_buffer.length;
|
|
428
|
+
const oldBuffer = in_buffer;
|
|
429
|
+
const isShrinking = oldSize > in_newSize;
|
|
430
|
+
this.arraySet(newBuffer, isShrinking ? oldBuffer.slice(0, in_newSize) : oldBuffer);
|
|
431
|
+
return newBuffer;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* allocate memory for the array (for performance reasons, you can allocate more space than the current length,
|
|
436
|
+
* which makes pushes to the array less expensive later)
|
|
437
|
+
* @param size - the target allocated space
|
|
438
|
+
* @returns the DataArray itself
|
|
439
|
+
*/
|
|
440
|
+
protected _alloc(size: number): any {
|
|
441
|
+
this._buffer = this.resizeBufferArray(this._buffer, size);
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
431
444
|
}
|
|
432
445
|
|
|
433
446
|
/**
|
|
434
447
|
* A data container that contains a string
|
|
435
448
|
*/
|
|
436
449
|
class StringDataArray extends BaseDataArray {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
450
|
+
constructor() {
|
|
451
|
+
super(String, 0);
|
|
452
|
+
this.size = 0;
|
|
453
|
+
this._buffer = "";
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* insert the content of a string into the StringDataArray
|
|
457
|
+
* @param in_offset - the target index
|
|
458
|
+
* @param in_string - the string to be inserted
|
|
459
|
+
*/
|
|
460
|
+
insertRange(in_offset: number, in_string: string) {
|
|
461
|
+
this._buffer = `${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(
|
|
462
|
+
in_offset,
|
|
463
|
+
)}`;
|
|
464
|
+
this.size = this.size + in_string.length;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* remove a range of elements from the string
|
|
469
|
+
* @param in_offset - start of the range
|
|
470
|
+
* @param in_deleteCount - number of elements to be removed
|
|
471
|
+
*/
|
|
472
|
+
removeRange(in_offset: number, in_deleteCount: number) {
|
|
473
|
+
if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {
|
|
474
|
+
this._buffer = `${this._buffer.substr(0, in_offset)}${this._buffer.substr(
|
|
475
|
+
in_offset + in_deleteCount,
|
|
476
|
+
)}`;
|
|
477
|
+
this.size -= in_deleteCount;
|
|
478
|
+
} else {
|
|
479
|
+
throw Error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Set this array values to be equal to in_string values.
|
|
485
|
+
* @param in_offset - The offset in this array to begin start setting this arrays values to in_string values.
|
|
486
|
+
* @param in_string - The input string.
|
|
487
|
+
*/
|
|
488
|
+
set(in_offset: number, in_string: string) {
|
|
489
|
+
this._buffer = `${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(
|
|
490
|
+
in_offset + in_string.length,
|
|
491
|
+
)}`;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Return a range of characters in the string.
|
|
496
|
+
* @param in_idxStart - the starting index
|
|
497
|
+
* @param in_idxEnd - the end index - this offset is exclusive
|
|
498
|
+
* @returns the characters in the range
|
|
499
|
+
*/
|
|
500
|
+
getValueRange(in_idxStart: number, in_idxEnd: number): string {
|
|
501
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
502
|
+
throw new Error("Trying to access out of bounds!");
|
|
503
|
+
}
|
|
504
|
+
return this._buffer.slice(in_idxStart, in_idxEnd);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
get length() {
|
|
508
|
+
return this._buffer.length;
|
|
509
|
+
}
|
|
490
510
|
}
|
|
491
511
|
|
|
492
512
|
/**
|
|
493
513
|
* A data container that can contain boolean type
|
|
494
514
|
*/
|
|
495
515
|
class BoolDataArray extends UniversalDataArray {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
516
|
+
/**
|
|
517
|
+
* @param size - The initial size with which to allocate the array.
|
|
518
|
+
*/
|
|
519
|
+
constructor(size: number) {
|
|
520
|
+
super(Array, size);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* helper function to write and cast to boolean array values into another array at a given offset
|
|
525
|
+
* @param array - target array
|
|
526
|
+
* @param values - the values we need to write
|
|
527
|
+
* @param offset - starting index in target array
|
|
528
|
+
*/
|
|
529
|
+
private arraySetBool(array, values, offset = 0) {
|
|
530
|
+
let index = 0;
|
|
531
|
+
values.forEach(function (value) {
|
|
532
|
+
array[index + offset] = !!(value as boolean);
|
|
533
|
+
index++;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* insert the content of an array into the DataArray
|
|
539
|
+
* @param in_offset - the target index
|
|
540
|
+
* @param in_array - the array to be inserted
|
|
541
|
+
*/
|
|
542
|
+
insertRange(in_offset: number, in_array: any[]) {
|
|
543
|
+
const toBeAdded: any[] = in_array.map((val) => !!(val as boolean));
|
|
544
|
+
this._buffer.splice.call(this._buffer, ...[in_offset, 0].concat(toBeAdded));
|
|
545
|
+
this.size = this.size + in_array.length;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Set this array values to be equal to in_array values.
|
|
550
|
+
* @param in_offset - An optional offset in this array to begin start setting this arrays values to in_array values.
|
|
551
|
+
* @param in_array - The input array.
|
|
552
|
+
*/
|
|
553
|
+
set(in_offset: number, in_array) {
|
|
554
|
+
if (
|
|
555
|
+
in_array instanceof ArrayBuffer ||
|
|
556
|
+
in_array instanceof Array ||
|
|
557
|
+
in_array instanceof this.getBufferCtor()
|
|
558
|
+
) {
|
|
559
|
+
this.arraySetBool(this._buffer, in_array, in_offset);
|
|
560
|
+
} else if (in_array instanceof BaseDataArray) {
|
|
561
|
+
this.arraySetBool(this._buffer, in_array.getBuffer(), in_offset);
|
|
562
|
+
} else {
|
|
563
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
564
|
+
}
|
|
565
|
+
}
|
|
542
566
|
}
|
|
543
567
|
|
|
544
568
|
export {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
569
|
+
BaseDataArray,
|
|
570
|
+
Float32DataArray,
|
|
571
|
+
Float64DataArray,
|
|
572
|
+
Int8DataArray,
|
|
573
|
+
Int16DataArray,
|
|
574
|
+
Int32DataArray,
|
|
575
|
+
Uint8DataArray,
|
|
576
|
+
Uint16DataArray,
|
|
577
|
+
Uint32DataArray,
|
|
578
|
+
UniversalDataArray,
|
|
579
|
+
StringDataArray,
|
|
580
|
+
BoolDataArray,
|
|
557
581
|
};
|