@fluid-experimental/property-common 0.49.0 → 0.50.0-41540
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/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/chronometer.d.ts +55 -0
- package/lib/chronometer.d.ts.map +1 -0
- package/lib/chronometer.js +185 -0
- package/lib/chronometer.js.map +1 -0
- package/lib/consoleUtils.d.ts +16 -0
- package/lib/consoleUtils.d.ts.map +1 -0
- package/lib/consoleUtils.js +20 -0
- package/lib/consoleUtils.js.map +1 -0
- package/lib/constants.d.ts +1219 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +1274 -0
- package/lib/constants.js.map +1 -0
- package/lib/datastructures/collection.d.ts +203 -0
- package/lib/datastructures/collection.d.ts.map +1 -0
- package/lib/datastructures/collection.js +377 -0
- package/lib/datastructures/collection.js.map +1 -0
- package/lib/datastructures/dataArray.d.ts +275 -0
- package/lib/datastructures/dataArray.d.ts.map +1 -0
- package/lib/datastructures/dataArray.js +497 -0
- package/lib/datastructures/dataArray.js.map +1 -0
- package/lib/datastructures/index.d.ts +9 -0
- package/lib/datastructures/index.d.ts.map +1 -0
- package/lib/datastructures/index.js +9 -0
- package/lib/datastructures/index.js.map +1 -0
- package/lib/datastructures/integer64.d.ts +47 -0
- package/lib/datastructures/integer64.d.ts.map +1 -0
- package/lib/datastructures/integer64.js +140 -0
- package/lib/datastructures/integer64.js.map +1 -0
- package/lib/datastructures/sortedCollection.d.ts +77 -0
- package/lib/datastructures/sortedCollection.d.ts.map +1 -0
- package/lib/datastructures/sortedCollection.js +140 -0
- package/lib/datastructures/sortedCollection.js.map +1 -0
- package/lib/deferredPromise.d.ts +28 -0
- package/lib/deferredPromise.d.ts.map +1 -0
- package/lib/deferredPromise.js +43 -0
- package/lib/deferredPromise.js.map +1 -0
- package/lib/deterministicRandomGenerator.d.ts +39 -0
- package/lib/deterministicRandomGenerator.d.ts.map +1 -0
- package/lib/deterministicRandomGenerator.js +83 -0
- package/lib/deterministicRandomGenerator.js.map +1 -0
- package/lib/error_objects/flaggedError.d.ts +29 -0
- package/lib/error_objects/flaggedError.d.ts.map +1 -0
- package/lib/error_objects/flaggedError.js +45 -0
- package/lib/error_objects/flaggedError.js.map +1 -0
- package/lib/error_objects/httpError.d.ts +31 -0
- package/lib/error_objects/httpError.d.ts.map +1 -0
- package/lib/error_objects/httpError.js +58 -0
- package/lib/error_objects/httpError.js.map +1 -0
- package/lib/error_objects/httpErrorNoStack.d.ts +25 -0
- package/lib/error_objects/httpErrorNoStack.d.ts.map +1 -0
- package/lib/error_objects/httpErrorNoStack.js +29 -0
- package/lib/error_objects/httpErrorNoStack.js.map +1 -0
- package/lib/error_objects/index.d.ts +9 -0
- package/lib/error_objects/index.d.ts.map +1 -0
- package/lib/error_objects/index.js +9 -0
- package/lib/error_objects/index.js.map +1 -0
- package/lib/error_objects/operationError.d.ts +32 -0
- package/lib/error_objects/operationError.d.ts.map +1 -0
- package/lib/error_objects/operationError.js +73 -0
- package/lib/error_objects/operationError.js.map +1 -0
- package/lib/guidUtils.d.ts +16 -0
- package/lib/guidUtils.d.ts.map +1 -0
- package/lib/guidUtils.js +297 -0
- package/lib/guidUtils.js.map +1 -0
- package/lib/hashCalculator.d.ts +6 -0
- package/lib/hashCalculator.d.ts.map +1 -0
- package/lib/hashCalculator.js +14 -0
- package/lib/hashCalculator.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/joinPaths.d.ts +19 -0
- package/lib/joinPaths.d.ts.map +1 -0
- package/lib/joinPaths.js +28 -0
- package/lib/joinPaths.js.map +1 -0
- package/lib/packageVersion.d.ts +9 -0
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/packageVersion.js +9 -0
- package/lib/packageVersion.js.map +1 -0
- package/package.json +22 -2
- package/platform-dependent/package.json +1 -1
- package/src/constants.ts +5 -0
- package/src/packageVersion.ts +1 -1
- package/dist/test/chronometer.spec.js +0 -90
- package/dist/test/chronometer.spec.js.map +0 -1
- package/dist/test/datastructures/collection.spec.js +0 -401
- package/dist/test/datastructures/collection.spec.js.map +0 -1
- package/dist/test/datastructures/dataArray.spec.js +0 -79
- package/dist/test/datastructures/dataArray.spec.js.map +0 -1
- package/dist/test/datastructures/sortedCollection.spec.js +0 -106
- package/dist/test/datastructures/sortedCollection.spec.js.map +0 -1
- package/dist/test/deterministicRandomGenerator.spec.js +0 -18
- package/dist/test/deterministicRandomGenerator.spec.js.map +0 -1
- package/dist/test/error_objects/flaggedError.spec.js +0 -23
- package/dist/test/error_objects/flaggedError.spec.js.map +0 -1
- package/dist/test/error_objects/httpError.spec.js +0 -61
- package/dist/test/error_objects/httpError.spec.js.map +0 -1
- package/dist/test/error_objects/httpErrorNoStack.spec.js +0 -55
- package/dist/test/error_objects/httpErrorNoStack.spec.js.map +0 -1
- package/dist/test/error_objects/operationError.spec.js +0 -132
- package/dist/test/error_objects/operationError.spec.js.map +0 -1
- package/dist/test/guidUtils.spec.js +0 -184
- package/dist/test/guidUtils.spec.js.map +0 -1
- package/dist/test/strings/joinPaths.spec.js +0 -18
- package/dist/test/strings/joinPaths.spec.js.map +0 -1
- package/dist/test/tsconfig.tsbuildinfo +0 -2278
- package/nyc/mocha-junit-report.xml +0 -175
- package/src/test/chronometer.spec.ts +0 -99
- package/src/test/datastructures/collection.spec.ts +0 -567
- package/src/test/datastructures/dataArray.spec.ts +0 -81
- package/src/test/datastructures/sortedCollection.spec.ts +0 -128
- package/src/test/deterministicRandomGenerator.spec.ts +0 -18
- package/src/test/error_objects/flaggedError.spec.ts +0 -22
- package/src/test/error_objects/httpError.spec.ts +0 -68
- package/src/test/error_objects/httpErrorNoStack.spec.ts +0 -64
- package/src/test/error_objects/operationError.spec.ts +0 -152
- package/src/test/guidUtils.spec.ts +0 -213
- package/src/test/strings/joinPaths.spec.ts +0 -17
- package/src/test/tsconfig.json +0 -21
- package/tsconfig.esnext.tsbuildinfo +0 -824
- package/tsconfig.tsbuildinfo +0 -823
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataArray.d.ts","sourceRoot":"","sources":["../../src/datastructures/dataArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AAEH;;;GAGG;AACH,cAAM,aAAa;IACf,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IACnC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEX,IAAI,EAAE,MAAM;IAExB;;;;OAIG;gBACS,iBAAiB,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM;IAchD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,SAAI,GAAG,GAAG;IAQzB;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAQpD;;;OAGG;IACH,SAAS,IAAI,MAAM,EAAE;IAIrB;;;OAGG;IACH,WAAW,CAAC,aAAa,KAAA;IAazB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,KAAA;IAQjC;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IASrD;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAUf;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,KAAA;IAKvC;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,KAAA;IAU/B;;;OAGG;IACH,IAAI,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,KAAA;IAU/B;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAOpD;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;IACH,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;CAItC;AAED;;GAEG;AACH,cAAM,eAAgB,SAAQ,aAAa;;IAMvC;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKhD;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IASrD;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKxC;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAO7D,IAAI,MAAM,QAAkC;CAC/C;AAED;;GAEG;AACH,cAAM,aAAc,SAAQ,kBAAkB;IAC1C;;OAEG;gBACS,IAAI,EAAE,MAAM;IAIxB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAQpB;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE;IAM9C;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,KAAA;CASlC;AAED,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,aAAa,GAChB,CAAC"}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
6
|
+
/* eslint accessor-pairs: [2, { "getWithoutSet": false }] */
|
|
7
|
+
/**
|
|
8
|
+
@fileoverview The data arrays definition file.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A typed data container that is persistable, high-performance, and can be used
|
|
12
|
+
* as a backing store for collaborative property sets.
|
|
13
|
+
*/
|
|
14
|
+
class BaseDataArray {
|
|
15
|
+
constructor(a, b) {
|
|
16
|
+
if (typeof a === "number") {
|
|
17
|
+
this.size = a;
|
|
18
|
+
this.bufferConstructor = this.getBufferCtor();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.bufferConstructor = a;
|
|
22
|
+
this.size = b;
|
|
23
|
+
}
|
|
24
|
+
// The 'eslint-...' is used to disable the rule that requires
|
|
25
|
+
// constructors to start with a capitalized letter.
|
|
26
|
+
this._buffer = new this.bufferConstructor(this.size); // eslint-disable-line new-cap
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the value at an index. If no index is passed, return zeroth item.
|
|
30
|
+
* @param in_idx - the specific item in the data array.
|
|
31
|
+
* @returns the value at that index
|
|
32
|
+
*/
|
|
33
|
+
getValue(in_idx = 0) {
|
|
34
|
+
if (in_idx >= this.size || in_idx < 0) {
|
|
35
|
+
throw new Error("Trying to access out of bounds!");
|
|
36
|
+
}
|
|
37
|
+
return this._buffer[in_idx];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Return a range of values in the array.
|
|
41
|
+
* @param in_idxStart - the starting index
|
|
42
|
+
* @param in_idxEnd - the end index
|
|
43
|
+
* @returns the array of values in the range
|
|
44
|
+
*/
|
|
45
|
+
getValueRange(in_idxStart, in_idxEnd) {
|
|
46
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
47
|
+
throw new Error("Trying to access out of bounds!");
|
|
48
|
+
}
|
|
49
|
+
return this._buffer.subarray(in_idxStart, in_idxEnd);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Return the serialized form of Data Arrays.
|
|
53
|
+
* @returns An object containing an array of the values.
|
|
54
|
+
*/
|
|
55
|
+
serialize() {
|
|
56
|
+
return Array.from(this._buffer.subarray(0, this.size));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Deserialize data from a serialized representation
|
|
60
|
+
* @param in_serialized - the serialized representation
|
|
61
|
+
*/
|
|
62
|
+
deserialize(in_serialized) {
|
|
63
|
+
const values = in_serialized;
|
|
64
|
+
const length = in_serialized.length;
|
|
65
|
+
if (length !== this.size) {
|
|
66
|
+
this.resize(length);
|
|
67
|
+
this.size = length;
|
|
68
|
+
}
|
|
69
|
+
let i;
|
|
70
|
+
for (i = 0; i < length; i++) {
|
|
71
|
+
this._buffer[i] = values[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set value at an index.
|
|
76
|
+
* @param in_idx - the index
|
|
77
|
+
* @param in_value - the value we want to set at index
|
|
78
|
+
*/
|
|
79
|
+
setValue(in_idx, in_value) {
|
|
80
|
+
if (in_idx < this._buffer.length) {
|
|
81
|
+
this._buffer[in_idx] = in_value;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.error("DataArray setValue in_idx is out of bounds.");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* creates a copy of a typed array with removed elements
|
|
89
|
+
* @param in_arr - the input array (won't be modified)
|
|
90
|
+
* @param in_offset - starting index of range that will be removed
|
|
91
|
+
* @param in_deleteCount - number of removed elements
|
|
92
|
+
* @returns a copy of the input array without the selected range
|
|
93
|
+
*/
|
|
94
|
+
_removeElementsFromArray(in_arr, in_offset, in_deleteCount) {
|
|
95
|
+
// TODO: this function can be optimized
|
|
96
|
+
const newSize = this.size - in_deleteCount;
|
|
97
|
+
const splicedArray = new in_arr.constructor(newSize);
|
|
98
|
+
splicedArray.set(in_arr.subarray(0, in_offset));
|
|
99
|
+
splicedArray.set(in_arr.subarray(in_offset + in_deleteCount, this.size), in_offset);
|
|
100
|
+
return splicedArray;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* remove a range of elements from the array
|
|
104
|
+
* @param in_offset - start of the range
|
|
105
|
+
* @param in_deleteCount - number of elements to be removed
|
|
106
|
+
*/
|
|
107
|
+
removeRange(in_offset, in_deleteCount) {
|
|
108
|
+
if (in_offset + in_deleteCount < this._buffer.length + 1) {
|
|
109
|
+
this._buffer = this._removeElementsFromArray(this._buffer, in_offset, in_deleteCount);
|
|
110
|
+
this.size = this.size - in_deleteCount;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* copy an array with elements inserted into the copy
|
|
118
|
+
* @param in_arr - the input array (won't be modified)
|
|
119
|
+
* @param in_offset - the index where the new elements will be inserted
|
|
120
|
+
* @param in_addedArray - the array with the elements that will be added
|
|
121
|
+
* @returns the combined array
|
|
122
|
+
*/
|
|
123
|
+
_insert(in_arr, in_offset, in_addedArray) {
|
|
124
|
+
// TODO: this function can be optimized
|
|
125
|
+
const newSize = this.size + in_addedArray.length;
|
|
126
|
+
const insertedArray = new in_arr.constructor(newSize);
|
|
127
|
+
insertedArray.set(in_arr.subarray(0, in_offset));
|
|
128
|
+
insertedArray.set(in_addedArray, in_offset);
|
|
129
|
+
insertedArray.set(in_arr.subarray(in_offset, this.size), in_offset + in_addedArray.length);
|
|
130
|
+
return insertedArray;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* insert the content of an array into the DataArray
|
|
134
|
+
* @param in_offset - the target index
|
|
135
|
+
* @param in_array - the array to be inserted
|
|
136
|
+
*/
|
|
137
|
+
insertRange(in_offset, in_array) {
|
|
138
|
+
this._buffer = this._insert(this._buffer, in_offset, in_array);
|
|
139
|
+
this.size = this.size + in_array.length;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Set this array values to be equal to in_array values
|
|
143
|
+
* @param in_offset - An optional offset in this array to begin start
|
|
144
|
+
* setting this arrays values to in_array values.
|
|
145
|
+
* @param in_array - the input array
|
|
146
|
+
*/
|
|
147
|
+
set(in_offset, in_array) {
|
|
148
|
+
if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {
|
|
149
|
+
this._buffer.set(in_array, in_offset);
|
|
150
|
+
}
|
|
151
|
+
else if (in_array instanceof BaseDataArray) {
|
|
152
|
+
this._buffer.set(in_array.getBuffer(), in_offset);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* insert a value at the end of the array, creates a new element at the end and sets the value
|
|
160
|
+
* @param in_value - the new value
|
|
161
|
+
*/
|
|
162
|
+
push(in_value) {
|
|
163
|
+
// Adjust the buffer if necessary
|
|
164
|
+
const bufferLength = this._buffer.length;
|
|
165
|
+
if (this.size > bufferLength - 1) {
|
|
166
|
+
this._alloc(this.size * 2 || 1); // grow by a factor of 2x
|
|
167
|
+
}
|
|
168
|
+
// set the value and update size
|
|
169
|
+
this.setValue(this.size, in_value);
|
|
170
|
+
this.size++;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* get direct access to the data (for performance reasons)
|
|
174
|
+
* this should be uses read only
|
|
175
|
+
* @returns the (read only) raw data
|
|
176
|
+
*/
|
|
177
|
+
getBuffer() {
|
|
178
|
+
return this._buffer;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* get the constructor of the underlying TypedArray
|
|
182
|
+
* @returns the constructor for the data buffer
|
|
183
|
+
*/
|
|
184
|
+
getBufferCtor() {
|
|
185
|
+
return this.bufferConstructor;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* apply a given function to all elements of the array
|
|
189
|
+
* @param in_fn - the function that will be applied to every element
|
|
190
|
+
*/
|
|
191
|
+
iterate(in_fn) {
|
|
192
|
+
const l = this.size;
|
|
193
|
+
for (let i = 0; i < l; i++) {
|
|
194
|
+
in_fn(this._buffer[i]);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* get a resized buffer copy
|
|
199
|
+
* @param in_bufferCtor - the constructor for the returned buffer
|
|
200
|
+
* @param in_buffer - the input buffer (won't be modified)
|
|
201
|
+
* @param in_newSize - the target size
|
|
202
|
+
* @returns the buffer with the new size
|
|
203
|
+
*/
|
|
204
|
+
resizeBuffer(in_bufferCtor, in_buffer, in_newSize) {
|
|
205
|
+
// target buffer with the desired new size
|
|
206
|
+
// The 'eslint-...' is used to disable the rule that requires
|
|
207
|
+
// constructors to start with a capitalized letter.
|
|
208
|
+
const newBuffer = new in_bufferCtor(in_newSize); // eslint-disable-line new-cap
|
|
209
|
+
const oldSize = in_buffer.length;
|
|
210
|
+
const oldBuffer = in_buffer;
|
|
211
|
+
const isShrinking = oldSize > in_newSize;
|
|
212
|
+
newBuffer.set(isShrinking ? oldBuffer.subarray(0, in_newSize) : oldBuffer);
|
|
213
|
+
return newBuffer;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* allocate memory for the array (for performance reasons, you can allocate more space than the current length,
|
|
217
|
+
* which makes pushes to the array less expensive later)
|
|
218
|
+
* @param size - the target allocated space
|
|
219
|
+
* @returns the DataArray itself
|
|
220
|
+
*/
|
|
221
|
+
_alloc(size) {
|
|
222
|
+
this._buffer = this.resizeBuffer(this.bufferConstructor, this._buffer, size);
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* change the size of the array
|
|
227
|
+
* @param size - the target size
|
|
228
|
+
* @returns the DataArray itself
|
|
229
|
+
*/
|
|
230
|
+
resize(size) {
|
|
231
|
+
this._alloc(size);
|
|
232
|
+
this.size = size;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
copy() {
|
|
236
|
+
const newBuffer = new this.bufferConstructor(this.size); // buffer with the desired new size
|
|
237
|
+
newBuffer.set(this._buffer);
|
|
238
|
+
return newBuffer;
|
|
239
|
+
}
|
|
240
|
+
get length() {
|
|
241
|
+
return this.size;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class Int8DataArray extends BaseDataArray {
|
|
245
|
+
constructor(size) {
|
|
246
|
+
super(Int8Array, size);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
class Int16DataArray extends BaseDataArray {
|
|
250
|
+
constructor(size) {
|
|
251
|
+
super(Int16Array, size);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
class Int32DataArray extends BaseDataArray {
|
|
255
|
+
constructor(size) {
|
|
256
|
+
super(Int32Array, size);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
class Uint8DataArray extends BaseDataArray {
|
|
260
|
+
constructor(size) {
|
|
261
|
+
super(Uint8Array, size);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
class Uint16DataArray extends BaseDataArray {
|
|
265
|
+
constructor(size) {
|
|
266
|
+
super(Uint16Array, size);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
class Uint32DataArray extends BaseDataArray {
|
|
270
|
+
constructor(size) {
|
|
271
|
+
super(Uint32Array, size);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
class Float32DataArray extends BaseDataArray {
|
|
275
|
+
constructor(size) {
|
|
276
|
+
super(Float32Array, size);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
class Float64DataArray extends BaseDataArray {
|
|
280
|
+
constructor(size) {
|
|
281
|
+
super(Float64Array, size);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* A data container that can contain every native type
|
|
286
|
+
*
|
|
287
|
+
* @param size - The initial size with which to allocate the array.
|
|
288
|
+
*/
|
|
289
|
+
class UniversalDataArray extends BaseDataArray {
|
|
290
|
+
constructor(a, b) {
|
|
291
|
+
if (b === undefined) {
|
|
292
|
+
super(Array, a);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
super(a, b);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* helper function to write array values into another array at a given offset
|
|
300
|
+
* @param array - target array
|
|
301
|
+
* @param values - the values we need to write
|
|
302
|
+
* @param offset - starting index in target array
|
|
303
|
+
*/
|
|
304
|
+
arraySet(array, values, offset = 0) {
|
|
305
|
+
let index = 0;
|
|
306
|
+
values.forEach(function (value) {
|
|
307
|
+
array[index + offset] = value;
|
|
308
|
+
index++;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* insert the content of an array into the DataArray
|
|
313
|
+
* @param in_offset - the target index
|
|
314
|
+
* @param in_array - the array to be inserted
|
|
315
|
+
*/
|
|
316
|
+
insertRange(in_offset, in_array) {
|
|
317
|
+
this._buffer.splice.call(this._buffer, ...[in_offset, 0].concat(in_array));
|
|
318
|
+
this.size = this.size + in_array.length;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* remove a range of elements from the array
|
|
322
|
+
* @param in_offset - start of the range
|
|
323
|
+
* @param in_deleteCount - number of elements to be removed
|
|
324
|
+
*/
|
|
325
|
+
removeRange(in_offset, in_deleteCount) {
|
|
326
|
+
if (in_offset + in_deleteCount < this._buffer.length + 1) {
|
|
327
|
+
this._buffer.splice(in_offset, in_deleteCount);
|
|
328
|
+
this.size -= in_deleteCount;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
throw Error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Set this array values to be equal to in_array values
|
|
336
|
+
* @param in_offset - An optional offset in this array to begin start
|
|
337
|
+
* setting this arrays values to in_array values.
|
|
338
|
+
* @param in_array - the input array
|
|
339
|
+
*/
|
|
340
|
+
set(in_offset, in_array) {
|
|
341
|
+
if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {
|
|
342
|
+
this.arraySet(this._buffer, in_array, in_offset);
|
|
343
|
+
}
|
|
344
|
+
else if (in_array instanceof BaseDataArray) {
|
|
345
|
+
this.arraySet(this._buffer, in_array.getBuffer(), in_offset);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Return a range of values in the array.
|
|
353
|
+
* @param in_idxStart - the starting index
|
|
354
|
+
* @param in_idxEnd - the end index - this offset is exclusive
|
|
355
|
+
* @returns the array of values in the range
|
|
356
|
+
*/
|
|
357
|
+
getValueRange(in_idxStart, in_idxEnd) {
|
|
358
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
359
|
+
throw new Error("Trying to access out of bounds!");
|
|
360
|
+
}
|
|
361
|
+
return this._buffer.slice(in_idxStart, in_idxEnd);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* change the size of a javascript array and keep the content, if possible. Keeps the input buffer.
|
|
365
|
+
* @param in_buffer - input buffer - not changed
|
|
366
|
+
* @param in_newSize - target size
|
|
367
|
+
* @returns an Array of the new size
|
|
368
|
+
*/
|
|
369
|
+
resizeBufferArray(in_buffer, in_newSize) {
|
|
370
|
+
// target buffer with the desired new size
|
|
371
|
+
const newBuffer = new Array(in_newSize);
|
|
372
|
+
const oldSize = in_buffer.length;
|
|
373
|
+
const oldBuffer = in_buffer;
|
|
374
|
+
const isShrinking = oldSize > in_newSize;
|
|
375
|
+
this.arraySet(newBuffer, isShrinking ? oldBuffer.slice(0, in_newSize) : oldBuffer);
|
|
376
|
+
return newBuffer;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* allocate memory for the array (for performance reasons, you can allocate more space than the current length,
|
|
380
|
+
* which makes pushes to the array less expensive later)
|
|
381
|
+
* @param size - the target allocated space
|
|
382
|
+
* @returns the DataArray itself
|
|
383
|
+
*/
|
|
384
|
+
_alloc(size) {
|
|
385
|
+
this._buffer = this.resizeBufferArray(this._buffer, size);
|
|
386
|
+
return this;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* A data container that contains a string
|
|
391
|
+
*/
|
|
392
|
+
class StringDataArray extends BaseDataArray {
|
|
393
|
+
constructor() {
|
|
394
|
+
super(String, 0);
|
|
395
|
+
this.size = 0;
|
|
396
|
+
this._buffer = "";
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* insert the content of a string into the StringDataArray
|
|
400
|
+
* @param in_offset - the target index
|
|
401
|
+
* @param in_string - the string to be inserted
|
|
402
|
+
*/
|
|
403
|
+
insertRange(in_offset, in_string) {
|
|
404
|
+
this._buffer = `${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(in_offset)}`;
|
|
405
|
+
this.size = this.size + in_string.length;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* remove a range of elements from the string
|
|
409
|
+
* @param in_offset - start of the range
|
|
410
|
+
* @param in_deleteCount - number of elements to be removed
|
|
411
|
+
*/
|
|
412
|
+
removeRange(in_offset, in_deleteCount) {
|
|
413
|
+
if (in_offset + in_deleteCount < this._buffer.length + 1) {
|
|
414
|
+
this._buffer = `${this._buffer.substr(0, in_offset)}${this._buffer.substr(in_offset + in_deleteCount)}`;
|
|
415
|
+
this.size -= in_deleteCount;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
throw Error("DataArray removeRange in_offset + in_deleteCount is out of bounds.");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Set this array values to be equal to in_string values
|
|
423
|
+
* @param in_offset - The offset in this array to begin start
|
|
424
|
+
* setting this arrays values to in_string values.
|
|
425
|
+
* @param in_string - the input string
|
|
426
|
+
*/
|
|
427
|
+
set(in_offset, in_string) {
|
|
428
|
+
this._buffer =
|
|
429
|
+
`${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(in_offset + in_string.length)}`;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Return a range of characters in the string.
|
|
433
|
+
* @param in_idxStart - the starting index
|
|
434
|
+
* @param in_idxEnd - the end index - this offset is exclusive
|
|
435
|
+
* @returns the characters in the range
|
|
436
|
+
*/
|
|
437
|
+
getValueRange(in_idxStart, in_idxEnd) {
|
|
438
|
+
if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {
|
|
439
|
+
throw new Error("Trying to access out of bounds!");
|
|
440
|
+
}
|
|
441
|
+
return this._buffer.slice(in_idxStart, in_idxEnd);
|
|
442
|
+
}
|
|
443
|
+
get length() { return this._buffer.length; }
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* A data container that can contain boolean type
|
|
447
|
+
*/
|
|
448
|
+
class BoolDataArray extends UniversalDataArray {
|
|
449
|
+
/**
|
|
450
|
+
* @param size - The initial size with which to allocate the array.
|
|
451
|
+
*/
|
|
452
|
+
constructor(size) {
|
|
453
|
+
super(Array, size);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* helper function to write and cast to boolean array values into another array at a given offset
|
|
457
|
+
* @param array - target array
|
|
458
|
+
* @param values - the values we need to write
|
|
459
|
+
* @param offset - starting index in target array
|
|
460
|
+
*/
|
|
461
|
+
arraySetBool(array, values, offset = 0) {
|
|
462
|
+
let index = 0;
|
|
463
|
+
values.forEach(function (value) {
|
|
464
|
+
array[index + offset] = !!value;
|
|
465
|
+
index++;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* insert the content of an array into the DataArray
|
|
470
|
+
* @param in_offset - the target index
|
|
471
|
+
* @param in_array - the array to be inserted
|
|
472
|
+
*/
|
|
473
|
+
insertRange(in_offset, in_array) {
|
|
474
|
+
const toBeAdded = in_array.map((val) => !!val);
|
|
475
|
+
this._buffer.splice.call(this._buffer, ...([in_offset, 0].concat(toBeAdded)));
|
|
476
|
+
this.size = this.size + in_array.length;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Set this array values to be equal to in_array values
|
|
480
|
+
* @param in_offset - An optional offset in this array to begin start
|
|
481
|
+
* setting this arrays values to in_array values.
|
|
482
|
+
* @param in_array - the input array
|
|
483
|
+
*/
|
|
484
|
+
set(in_offset, in_array) {
|
|
485
|
+
if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {
|
|
486
|
+
this.arraySetBool(this._buffer, in_array, in_offset);
|
|
487
|
+
}
|
|
488
|
+
else if (in_array instanceof BaseDataArray) {
|
|
489
|
+
this.arraySetBool(this._buffer, in_array.getBuffer(), in_offset);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
console.error("DataArray set() must be called with Array, TypedArray or DataArray");
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
export { BaseDataArray, Float32DataArray, Float64DataArray, Int8DataArray, Int16DataArray, Int32DataArray, Uint8DataArray, Uint16DataArray, Uint32DataArray, UniversalDataArray, StringDataArray, BoolDataArray, };
|
|
497
|
+
//# sourceMappingURL=dataArray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataArray.js","sourceRoot":"","sources":["../../src/datastructures/dataArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wDAAwD;AACxD,4DAA4D;AAC5D;;GAEG;AAEH;;;GAGG;AACH,MAAM,aAAa;IAaf,YAAY,CAAC,EAAE,CAAE;QACb,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YACvB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;YACd,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,aAAa,EAAE,CAA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EACd,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,aAAa,GAChB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint accessor-pairs: [2, { \"getWithoutSet\": false }] */\n/**\n @fileoverview The data arrays definition file.\n */\n\n/**\n * A typed data container that is persistable, high-performance, and can be used\n * as a backing store for collaborative property sets.\n */\nclass BaseDataArray {\n protected _buffer: any;\n private readonly bufferConstructor;\n protected size: number;\n\n constructor(size: number);\n\n /**\n * @param bufferConstructor - This is the constructor to be used to\n * setup the internal buffer of the DataArray.\n * @param size - The initial size with which to allocate the array.\n */\n constructor(bufferConstructor: any, size: number);\n constructor(a, b?) {\n if (typeof a === \"number\") {\n this.size = a;\n this.bufferConstructor = this.getBufferCtor();\n } else {\n this.bufferConstructor = a;\n this.size = b;\n }\n // The 'eslint-...' is used to disable the rule that requires\n // constructors to start with a capitalized letter.\n this._buffer = new this.bufferConstructor(this.size); // eslint-disable-line new-cap\n }\n\n /**\n * Get the value at an index. If no index is passed, return zeroth item.\n * @param in_idx - the specific item in the data array.\n * @returns the value at that index\n */\n getValue(in_idx = 0): any {\n if (in_idx >= this.size || in_idx < 0) {\n throw new Error(\"Trying to access out of bounds!\");\n }\n\n return this._buffer[in_idx];\n }\n\n /**\n * Return a range of values in the array.\n * @param in_idxStart - the starting index\n * @param in_idxEnd - the end index\n * @returns the array of values in the range\n */\n getValueRange(in_idxStart: number, in_idxEnd: number) {\n if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {\n throw new Error(\"Trying to access out of bounds!\");\n }\n\n return this._buffer.subarray(in_idxStart, in_idxEnd);\n }\n\n /**\n * Return the serialized form of Data Arrays.\n * @returns An object containing an array of the values.\n */\n serialize(): number[] {\n return Array.from(this._buffer.subarray(0, this.size));\n }\n\n /**\n * Deserialize data from a serialized representation\n * @param in_serialized - the serialized representation\n */\n deserialize(in_serialized) {\n const values = in_serialized;\n const length = in_serialized.length;\n if (length !== this.size) {\n this.resize(length);\n this.size = length;\n }\n let i;\n for (i = 0; i < length; i++) {\n this._buffer[i] = values[i];\n }\n }\n\n /**\n * Set value at an index.\n * @param in_idx - the index\n * @param in_value - the value we want to set at index\n */\n setValue(in_idx: number, in_value) {\n if (in_idx < this._buffer.length) {\n this._buffer[in_idx] = in_value;\n } else {\n console.error(\"DataArray setValue in_idx is out of bounds.\");\n }\n }\n\n /**\n * creates a copy of a typed array with removed elements\n * @param in_arr - the input array (won't be modified)\n * @param in_offset - starting index of range that will be removed\n * @param in_deleteCount - number of removed elements\n * @returns a copy of the input array without the selected range\n */\n private _removeElementsFromArray(in_arr, in_offset: number, in_deleteCount: number) {\n // TODO: this function can be optimized\n const newSize = this.size - in_deleteCount;\n const splicedArray = new in_arr.constructor(newSize);\n splicedArray.set(in_arr.subarray(0, in_offset));\n splicedArray.set(in_arr.subarray(in_offset + in_deleteCount, this.size), in_offset);\n return splicedArray;\n }\n\n /**\n * remove a range of elements from the array\n * @param in_offset - start of the range\n * @param in_deleteCount - number of elements to be removed\n */\n removeRange(in_offset: number, in_deleteCount: number) {\n if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {\n this._buffer = this._removeElementsFromArray(this._buffer, in_offset, in_deleteCount);\n this.size = this.size - in_deleteCount;\n } else {\n console.error(\"DataArray removeRange in_offset + in_deleteCount is out of bounds.\");\n }\n }\n\n /**\n * copy an array with elements inserted into the copy\n * @param in_arr - the input array (won't be modified)\n * @param in_offset - the index where the new elements will be inserted\n * @param in_addedArray - the array with the elements that will be added\n * @returns the combined array\n */\n private _insert(in_arr, in_offset: number, in_addedArray) {\n // TODO: this function can be optimized\n const newSize = this.size + (in_addedArray.length as number);\n const insertedArray = new in_arr.constructor(newSize);\n insertedArray.set(in_arr.subarray(0, in_offset));\n insertedArray.set(in_addedArray, in_offset);\n insertedArray.set(in_arr.subarray(in_offset, this.size), in_offset + (in_addedArray.length as number));\n return insertedArray;\n }\n\n /**\n * insert the content of an array into the DataArray\n * @param in_offset - the target index\n * @param in_array - the array to be inserted\n */\n insertRange(in_offset: number, in_array) {\n this._buffer = this._insert(this._buffer, in_offset, in_array);\n this.size = this.size + (in_array.length as number);\n }\n\n /**\n * Set this array values to be equal to in_array values\n * @param in_offset - An optional offset in this array to begin start\n * setting this arrays values to in_array values.\n * @param in_array - the input array\n */\n set(in_offset: number, in_array) {\n if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {\n this._buffer.set(in_array, in_offset);\n } else if (in_array instanceof BaseDataArray) {\n this._buffer.set(in_array.getBuffer(), in_offset);\n } else {\n console.error(\"DataArray set() must be called with Array, TypedArray or DataArray\");\n }\n }\n\n /**\n * insert a value at the end of the array, creates a new element at the end and sets the value\n * @param in_value - the new value\n */\n push(in_value) {\n // Adjust the buffer if necessary\n const bufferLength = this._buffer.length;\n if (this.size > bufferLength - 1) {\n this._alloc(this.size * 2 || 1); // grow by a factor of 2x\n }\n // set the value and update size\n this.setValue(this.size, in_value);\n this.size++;\n }\n\n /**\n * get direct access to the data (for performance reasons)\n * this should be uses read only\n * @returns the (read only) raw data\n */\n getBuffer() {\n return this._buffer;\n }\n\n /**\n * get the constructor of the underlying TypedArray\n * @returns the constructor for the data buffer\n */\n getBufferCtor() {\n return this.bufferConstructor;\n }\n\n /**\n * apply a given function to all elements of the array\n * @param in_fn - the function that will be applied to every element\n */\n iterate(in_fn) {\n const l = this.size;\n for (let i = 0; i < l; i++) {\n in_fn(this._buffer[i]);\n }\n }\n\n /**\n * get a resized buffer copy\n * @param in_bufferCtor - the constructor for the returned buffer\n * @param in_buffer - the input buffer (won't be modified)\n * @param in_newSize - the target size\n * @returns the buffer with the new size\n */\n private resizeBuffer(in_bufferCtor, in_buffer, in_newSize: number) {\n // target buffer with the desired new size\n // The 'eslint-...' is used to disable the rule that requires\n // constructors to start with a capitalized letter.\n const newBuffer = new in_bufferCtor(in_newSize); // eslint-disable-line new-cap\n const oldSize = in_buffer.length;\n const oldBuffer = in_buffer;\n const isShrinking = oldSize > in_newSize;\n newBuffer.set(isShrinking ? oldBuffer.subarray(0, in_newSize) : oldBuffer);\n return newBuffer;\n }\n\n /**\n * allocate memory for the array (for performance reasons, you can allocate more space than the current length,\n * which makes pushes to the array less expensive later)\n * @param size - the target allocated space\n * @returns the DataArray itself\n */\n protected _alloc(size: number): any {\n this._buffer = this.resizeBuffer(this.bufferConstructor, this._buffer, size);\n return this;\n }\n\n /**\n * change the size of the array\n * @param size - the target size\n * @returns the DataArray itself\n */\n resize(size: number) { // this can be costly!!!\n this._alloc(size);\n this.size = size;\n return this;\n }\n\n copy() { // and this!\n const newBuffer = new this.bufferConstructor(this.size); // buffer with the desired new size\n newBuffer.set(this._buffer);\n return newBuffer;\n }\n\n get length() {\n return this.size;\n }\n}\n\nclass Int8DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Int8Array, size);\n }\n}\n\nclass Int16DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Int16Array, size);\n }\n}\n\nclass Int32DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Int32Array, size);\n }\n}\n\nclass Uint8DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Uint8Array, size);\n }\n}\n\nclass Uint16DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Uint16Array, size);\n }\n}\n\nclass Uint32DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Uint32Array, size);\n }\n}\n\nclass Float32DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Float32Array, size);\n }\n}\n\nclass Float64DataArray extends BaseDataArray {\n constructor(size: number) {\n super(Float64Array, size);\n }\n}\n\n/**\n * A data container that can contain every native type\n *\n * @param size - The initial size with which to allocate the array.\n */\nclass UniversalDataArray extends BaseDataArray {\n constructor(bufferConstructor: any, size: number)\n constructor(size: number);\n constructor(a?, b?) {\n if (b === undefined) {\n super(Array, a);\n } else {\n super(a, b);\n }\n }\n\n /**\n * helper function to write array values into another array at a given offset\n * @param array - target array\n * @param values - the values we need to write\n * @param offset - starting index in target array\n */\n private arraySet(array, values, offset = 0) {\n let index = 0;\n values.forEach(function(value) {\n array[index + offset] = value;\n index++;\n });\n }\n\n /**\n * insert the content of an array into the DataArray\n * @param in_offset - the target index\n * @param in_array - the array to be inserted\n */\n insertRange(in_offset: number, in_array: any[]) {\n this._buffer.splice.call(this._buffer, ...[in_offset, 0].concat(in_array));\n this.size = this.size + in_array.length;\n }\n\n /**\n * remove a range of elements from the array\n * @param in_offset - start of the range\n * @param in_deleteCount - number of elements to be removed\n */\n removeRange(in_offset: number, in_deleteCount: number) {\n if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {\n this._buffer.splice(in_offset, in_deleteCount);\n this.size -= in_deleteCount;\n } else {\n throw Error(\"DataArray removeRange in_offset + in_deleteCount is out of bounds.\");\n }\n }\n\n /**\n * Set this array values to be equal to in_array values\n * @param in_offset - An optional offset in this array to begin start\n * setting this arrays values to in_array values.\n * @param in_array - the input array\n */\n set(in_offset: number, in_array) {\n if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {\n this.arraySet(this._buffer, in_array, in_offset);\n } else if (in_array instanceof BaseDataArray) {\n this.arraySet(this._buffer, in_array.getBuffer(), in_offset);\n } else {\n console.error(\"DataArray set() must be called with Array, TypedArray or DataArray\");\n }\n }\n\n /**\n * Return a range of values in the array.\n * @param in_idxStart - the starting index\n * @param in_idxEnd - the end index - this offset is exclusive\n * @returns the array of values in the range\n */\n getValueRange(in_idxStart: number, in_idxEnd: number) {\n if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {\n throw new Error(\"Trying to access out of bounds!\");\n }\n return this._buffer.slice(in_idxStart, in_idxEnd);\n }\n\n /**\n * change the size of a javascript array and keep the content, if possible. Keeps the input buffer.\n * @param in_buffer - input buffer - not changed\n * @param in_newSize - target size\n * @returns an Array of the new size\n */\n private resizeBufferArray(in_buffer, in_newSize) {\n // target buffer with the desired new size\n const newBuffer = new Array(in_newSize);\n const oldSize = in_buffer.length;\n const oldBuffer = in_buffer;\n const isShrinking = oldSize > in_newSize;\n this.arraySet(newBuffer, isShrinking ? oldBuffer.slice(0, in_newSize) : oldBuffer);\n return newBuffer;\n }\n\n /**\n * allocate memory for the array (for performance reasons, you can allocate more space than the current length,\n * which makes pushes to the array less expensive later)\n * @param size - the target allocated space\n * @returns the DataArray itself\n */\n protected _alloc(size: number): any {\n this._buffer = this.resizeBufferArray(this._buffer, size);\n return this;\n }\n}\n\n/**\n * A data container that contains a string\n */\nclass StringDataArray extends BaseDataArray {\n constructor() {\n super(String, 0);\n this.size = 0;\n this._buffer = \"\";\n }\n /**\n * insert the content of a string into the StringDataArray\n * @param in_offset - the target index\n * @param in_string - the string to be inserted\n */\n insertRange(in_offset: number, in_string: string) {\n this._buffer = `${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(in_offset)}`;\n this.size = this.size + in_string.length;\n }\n\n /**\n * remove a range of elements from the string\n * @param in_offset - start of the range\n * @param in_deleteCount - number of elements to be removed\n */\n removeRange(in_offset: number, in_deleteCount: number) {\n if (in_offset + in_deleteCount < (this._buffer.length as number) + 1) {\n this._buffer = `${this._buffer.substr(0, in_offset)}${this._buffer.substr(in_offset + in_deleteCount)}`;\n this.size -= in_deleteCount;\n } else {\n throw Error(\"DataArray removeRange in_offset + in_deleteCount is out of bounds.\");\n }\n }\n\n /**\n * Set this array values to be equal to in_string values\n * @param in_offset - The offset in this array to begin start\n * setting this arrays values to in_string values.\n * @param in_string - the input string\n */\n set(in_offset: number, in_string: string) {\n this._buffer =\n `${this._buffer.substr(0, in_offset)}${in_string}${this._buffer.substr(in_offset + in_string.length)}`;\n }\n\n /**\n * Return a range of characters in the string.\n * @param in_idxStart - the starting index\n * @param in_idxEnd - the end index - this offset is exclusive\n * @returns the characters in the range\n */\n getValueRange(in_idxStart: number, in_idxEnd: number): string {\n if (in_idxStart >= this.size || in_idxEnd > this.size || in_idxStart < 0 || in_idxEnd < 0) {\n throw new Error(\"Trying to access out of bounds!\");\n }\n return this._buffer.slice(in_idxStart, in_idxEnd);\n }\n\n get length() { return this._buffer.length; }\n}\n\n/**\n * A data container that can contain boolean type\n */\nclass BoolDataArray extends UniversalDataArray {\n /**\n * @param size - The initial size with which to allocate the array.\n */\n constructor(size: number) {\n super(Array, size);\n }\n\n /**\n * helper function to write and cast to boolean array values into another array at a given offset\n * @param array - target array\n * @param values - the values we need to write\n * @param offset - starting index in target array\n */\n private arraySetBool(array, values, offset = 0) {\n let index = 0;\n values.forEach(function(value) {\n array[index + offset] = !!(value as boolean);\n index++;\n });\n }\n\n /**\n * insert the content of an array into the DataArray\n * @param in_offset - the target index\n * @param in_array - the array to be inserted\n */\n insertRange(in_offset: number, in_array: any[]) {\n const toBeAdded: any[] = in_array.map((val) => !!(val as boolean));\n this._buffer.splice.call(this._buffer, ...([in_offset, 0].concat(toBeAdded)));\n this.size = this.size + in_array.length;\n }\n\n /**\n * Set this array values to be equal to in_array values\n * @param in_offset - An optional offset in this array to begin start\n * setting this arrays values to in_array values.\n * @param in_array - the input array\n */\n set(in_offset: number, in_array) {\n if (in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this.getBufferCtor()) {\n this.arraySetBool(this._buffer, in_array, in_offset);\n } else if (in_array instanceof BaseDataArray) {\n this.arraySetBool(this._buffer, in_array.getBuffer(), in_offset);\n } else {\n console.error(\"DataArray set() must be called with Array, TypedArray or DataArray\");\n }\n }\n}\n\nexport {\n BaseDataArray,\n Float32DataArray,\n Float64DataArray,\n Int8DataArray,\n Int16DataArray,\n Int32DataArray,\n Uint8DataArray,\n Uint16DataArray,\n Uint32DataArray,\n UniversalDataArray,\n StringDataArray,\n BoolDataArray,\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./collection";
|
|
6
|
+
export * from "./sortedCollection";
|
|
7
|
+
export * from "./integer64";
|
|
8
|
+
export * from "./dataArray";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datastructures/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./collection";
|
|
6
|
+
export * from "./sortedCollection";
|
|
7
|
+
export * from "./integer64";
|
|
8
|
+
export * from "./dataArray";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/datastructures/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./collection\";\nexport * from \"./sortedCollection\";\nexport * from \"./integer64\";\nexport * from \"./dataArray\";\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A data representation class for 64 bit integer types.
|
|
7
|
+
* This is necessary since js doesn't support 64bit
|
|
8
|
+
* integers natively yet.
|
|
9
|
+
*
|
|
10
|
+
* Please note this class is immutable.
|
|
11
|
+
* There are and there won't be set functions!
|
|
12
|
+
* (see javascript String class)
|
|
13
|
+
*
|
|
14
|
+
* @param low - lower 32 bit
|
|
15
|
+
* @param high - higher 32 bit
|
|
16
|
+
*/
|
|
17
|
+
export declare class Integer64 {
|
|
18
|
+
protected low: number;
|
|
19
|
+
protected high: number;
|
|
20
|
+
constructor(low?: number, high?: number);
|
|
21
|
+
/**
|
|
22
|
+
* @returns the higher 32 bit integer part
|
|
23
|
+
*/
|
|
24
|
+
getValueHigh(): number;
|
|
25
|
+
/**
|
|
26
|
+
* @returns the lower 32 bit integer part
|
|
27
|
+
*/
|
|
28
|
+
getValueLow(): number;
|
|
29
|
+
protected _int64toString(isSigned: boolean, in_radix?: number): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A data representation class for the signed 64 bit integer type
|
|
33
|
+
*/
|
|
34
|
+
export declare class Int64 extends Integer64 {
|
|
35
|
+
static fromString: (in_string: string, radix?: number) => Int64;
|
|
36
|
+
clone(): Int64;
|
|
37
|
+
toString(radix?: number): string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A data representation class for the unsigned 64 bit integer type
|
|
41
|
+
*/
|
|
42
|
+
export declare class Uint64 extends Integer64 {
|
|
43
|
+
static fromString(in_string: string, in_radix?: number): Uint64;
|
|
44
|
+
clone(): Uint64;
|
|
45
|
+
toString(radix: any): string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=integer64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer64.d.ts","sourceRoot":"","sources":["../../src/datastructures/integer64.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS;IACN,SAAS,CAAC,GAAG;IAAM,SAAS,CAAC,IAAI;gBAAvB,GAAG,SAAI,EAAY,IAAI,SAAI;IAGjD;;OAEG;IACH,YAAY;IAIZ;;OAEG;IACH,WAAW;IAIX,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,SAAK,GAAG,MAAM;CAqBrE;AAwDD;;GAEG;AACH,qBAAa,KAAM,SAAQ,SAAS;IAChC,MAAM,CAAC,UAAU,cAAuB,MAAM,2BAG5C;IAEF,KAAK;IAIL,QAAQ,CAAC,KAAK,SAAK;CAGtB;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,SAAS;IACjC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAK;IAKlD,KAAK;IAIL,QAAQ,CAAC,KAAK,KAAA;CAGjB"}
|