@itwin/core-bentley 3.4.0-dev.8 → 3.4.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/CHANGELOG.md +49 -1
- package/lib/cjs/ByteStream.d.ts.map +1 -1
- package/lib/cjs/ByteStream.js +14 -4
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +18 -6
- package/lib/cjs/Compare.js.map +1 -1
- package/lib/cjs/Dictionary.d.ts.map +1 -1
- package/lib/cjs/Dictionary.js.map +1 -1
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +15 -5
- package/lib/cjs/Id.js.map +1 -1
- package/lib/cjs/JsonUtils.d.ts.map +1 -1
- package/lib/cjs/JsonUtils.js +34 -16
- package/lib/cjs/JsonUtils.js.map +1 -1
- package/lib/cjs/LRUMap.d.ts.map +1 -1
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/OneAtATimeAction.d.ts.map +1 -1
- package/lib/cjs/OneAtATimeAction.js +4 -1
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/SortedArray.d.ts.map +1 -1
- package/lib/cjs/SortedArray.js +3 -1
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StringUtils.d.ts.map +1 -1
- package/lib/cjs/StringUtils.js +3 -1
- package/lib/cjs/StringUtils.js.map +1 -1
- package/lib/cjs/Time.d.ts +1 -1
- package/lib/cjs/Time.d.ts.map +1 -1
- package/lib/cjs/Time.js +9 -3
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.d.ts +2 -2
- package/lib/cjs/Tracing.d.ts.map +1 -1
- package/lib/cjs/Tracing.js +4 -1
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.d.ts +98 -0
- package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -0
- package/lib/cjs/TypedArrayBuilder.js +135 -0
- package/lib/cjs/TypedArrayBuilder.js.map +1 -0
- package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +5 -2
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/core-bentley.d.ts +1 -0
- package/lib/cjs/core-bentley.d.ts.map +1 -1
- package/lib/cjs/core-bentley.js +1 -0
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/esm/ByteStream.d.ts.map +1 -1
- package/lib/esm/ByteStream.js +14 -4
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +18 -6
- package/lib/esm/Compare.js.map +1 -1
- package/lib/esm/Dictionary.d.ts.map +1 -1
- package/lib/esm/Dictionary.js.map +1 -1
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +15 -5
- package/lib/esm/Id.js.map +1 -1
- package/lib/esm/JsonUtils.d.ts.map +1 -1
- package/lib/esm/JsonUtils.js +34 -16
- package/lib/esm/JsonUtils.js.map +1 -1
- package/lib/esm/LRUMap.d.ts.map +1 -1
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/OneAtATimeAction.d.ts.map +1 -1
- package/lib/esm/OneAtATimeAction.js +4 -1
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/SortedArray.d.ts.map +1 -1
- package/lib/esm/SortedArray.js +3 -1
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StringUtils.d.ts.map +1 -1
- package/lib/esm/StringUtils.js +3 -1
- package/lib/esm/StringUtils.js.map +1 -1
- package/lib/esm/Time.d.ts +1 -1
- package/lib/esm/Time.d.ts.map +1 -1
- package/lib/esm/Time.js +9 -3
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.d.ts +2 -2
- package/lib/esm/Tracing.d.ts.map +1 -1
- package/lib/esm/Tracing.js +4 -1
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.d.ts +98 -0
- package/lib/esm/TypedArrayBuilder.d.ts.map +1 -0
- package/lib/esm/TypedArrayBuilder.js +128 -0
- package/lib/esm/TypedArrayBuilder.js.map +1 -0
- package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
- package/lib/esm/UnexpectedErrors.js +5 -2
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/core-bentley.d.ts +1 -0
- package/lib/esm/core-bentley.d.ts.map +1 -1
- package/lib/esm/core-bentley.js +1 -0
- package/lib/esm/core-bentley.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Collections
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Uint32ArrayBuilder = exports.Uint16ArrayBuilder = exports.Uint8ArrayBuilder = exports.TypedArrayBuilder = void 0;
|
|
11
|
+
const Assert_1 = require("./Assert");
|
|
12
|
+
/** Incrementally builds a [TypedArray] of unsigned 8-, 16-, or 32-bit integers.
|
|
13
|
+
* Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.
|
|
14
|
+
* `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.
|
|
15
|
+
*
|
|
16
|
+
* `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two "size" properties":
|
|
17
|
+
* - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and
|
|
18
|
+
* - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].
|
|
19
|
+
* When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.
|
|
20
|
+
*
|
|
21
|
+
* Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].
|
|
22
|
+
* @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class TypedArrayBuilder {
|
|
26
|
+
/** Constructs a new builder from the specified options, with a [[length]] of zero. */
|
|
27
|
+
constructor(constructor, options) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
this._constructor = constructor;
|
|
30
|
+
this._data = new constructor((_a = options === null || options === void 0 ? void 0 : options.initialCapacity) !== null && _a !== void 0 ? _a : 0);
|
|
31
|
+
this.growthFactor = Math.max(1.0, (_b = options === null || options === void 0 ? void 0 : options.growthFactor) !== null && _b !== void 0 ? _b : 1.5);
|
|
32
|
+
this._length = 0;
|
|
33
|
+
}
|
|
34
|
+
/** The number of elements currently in the array. */
|
|
35
|
+
get length() {
|
|
36
|
+
return this._length;
|
|
37
|
+
}
|
|
38
|
+
/** The number of elements that can fit into the memory currently allocated for the array. */
|
|
39
|
+
get capacity() {
|
|
40
|
+
return this._data.length;
|
|
41
|
+
}
|
|
42
|
+
/** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),
|
|
43
|
+
* returns the element at the specified index, with negative integers counting back from the end of the array.
|
|
44
|
+
* @note It is your responsibility to ensure the index falls within the bounds of the array.
|
|
45
|
+
*/
|
|
46
|
+
at(index) {
|
|
47
|
+
if (index < 0)
|
|
48
|
+
index = this.length - index;
|
|
49
|
+
const value = this._data[index];
|
|
50
|
+
(0, Assert_1.assert)(value !== undefined, "index out of bounds");
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
/** Ensure that [[capacity]] is at least equal to `newCapacity`.
|
|
54
|
+
* This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.
|
|
55
|
+
* It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
|
|
56
|
+
*
|
|
57
|
+
* If `newCapacity` is not greater than the current [[capacity]], this function does nothing.
|
|
58
|
+
* Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.
|
|
59
|
+
* [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.
|
|
60
|
+
*/
|
|
61
|
+
ensureCapacity(newCapacity) {
|
|
62
|
+
if (this.capacity >= newCapacity)
|
|
63
|
+
return this.capacity;
|
|
64
|
+
(0, Assert_1.assert)(this.growthFactor >= 1.0);
|
|
65
|
+
newCapacity = Math.ceil(newCapacity * this.growthFactor);
|
|
66
|
+
const prevData = this._data;
|
|
67
|
+
this._data = new this._constructor(newCapacity);
|
|
68
|
+
this._data.set(prevData, 0);
|
|
69
|
+
(0, Assert_1.assert)(this.capacity === newCapacity);
|
|
70
|
+
return this.capacity;
|
|
71
|
+
}
|
|
72
|
+
/** Append the specified value, resizing if necessary. */
|
|
73
|
+
push(value) {
|
|
74
|
+
this.ensureCapacity(this.length + 1);
|
|
75
|
+
this._data[this.length] = value;
|
|
76
|
+
++this._length;
|
|
77
|
+
}
|
|
78
|
+
/** Append an array of values, resizing (at most once) if necessary. */
|
|
79
|
+
append(values) {
|
|
80
|
+
const newLength = this.length + values.length;
|
|
81
|
+
this.ensureCapacity(newLength);
|
|
82
|
+
this._data.set(values, this.length);
|
|
83
|
+
this._length = newLength;
|
|
84
|
+
}
|
|
85
|
+
/** Obtain the finished array.
|
|
86
|
+
* @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the
|
|
87
|
+
* returned array's length will be equal to [[length]].
|
|
88
|
+
*/
|
|
89
|
+
toTypedArray(includeUnusedCapacity = false) {
|
|
90
|
+
if (includeUnusedCapacity)
|
|
91
|
+
return this._data;
|
|
92
|
+
const subarray = this._data.subarray(0, this.length);
|
|
93
|
+
(0, Assert_1.assert)(subarray instanceof this._constructor);
|
|
94
|
+
(0, Assert_1.assert)(subarray.buffer === this._data.buffer);
|
|
95
|
+
return subarray;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.TypedArrayBuilder = TypedArrayBuilder;
|
|
99
|
+
/** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
class Uint8ArrayBuilder extends TypedArrayBuilder {
|
|
103
|
+
/** @see [[TypedArrayBuilder]] constructor. */
|
|
104
|
+
constructor(options) {
|
|
105
|
+
super(Uint8Array, options);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.Uint8ArrayBuilder = Uint8ArrayBuilder;
|
|
109
|
+
/** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
class Uint16ArrayBuilder extends TypedArrayBuilder {
|
|
113
|
+
/** @see [[TypedArrayBuilder]] constructor. */
|
|
114
|
+
constructor(options) {
|
|
115
|
+
super(Uint16Array, options);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Uint16ArrayBuilder = Uint16ArrayBuilder;
|
|
119
|
+
/** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
class Uint32ArrayBuilder extends TypedArrayBuilder {
|
|
123
|
+
/** @see [[TypedArrayBuilder]] constructor. */
|
|
124
|
+
constructor(options) {
|
|
125
|
+
super(Uint32Array, options);
|
|
126
|
+
}
|
|
127
|
+
/** Obtain a view of the finished array as an array of bytes. */
|
|
128
|
+
toUint8Array(includeUnusedCapacity = false) {
|
|
129
|
+
if (includeUnusedCapacity)
|
|
130
|
+
return new Uint8Array(this._data.buffer);
|
|
131
|
+
return new Uint8Array(this._data.buffer, 0, this.length * 4);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.Uint32ArrayBuilder = Uint32ArrayBuilder;
|
|
135
|
+
//# sourceMappingURL=TypedArrayBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedArrayBuilder.js","sourceRoot":"","sources":["../../src/TypedArrayBuilder.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,qCAAkC;AAqBlC;;;;;;;;;;;;GAYG;AACH,MAAa,iBAAiB;IAU5B,sFAAsF;IACtF,YAAsB,WAA2B,EAAE,OAAkC;;QACnF,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,qDAAqD;IACrD,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,6FAA6F;IAC7F,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,EAAE,CAAC,KAAa;QACrB,IAAI,KAAK,GAAG,CAAC;YACX,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAChC,IAAA,eAAM,EAAC,KAAK,K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qB,GAAG,KAAK;QAC/C,IAAI,qBAAqB;YACvB,OAAO,IAAI,CAAC,KAAK,CAAC;QAEpB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACrD,IAAA,eAAM,EAAC,QAAQ,YAAY,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAA,eAAM,EAAC,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9C,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA3FD,8CA2FC;AAED;;GAEG;AACH,MAAa,iBAAkB,SAAQ,iBAA6B;IAClE,8CAA8C;IAC9C,YAAmB,OAAkC;QACnD,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;CACF;AALD,8CAKC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,iBAA8B;IACpE,8CAA8C;IAC9C,YAAmB,OAAkC;QACnD,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;CACF;AALD,gDAKC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,iBAA8B;IACpE,8CAA8C;IAC9C,YAAmB,OAAkC;QACnD,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,gEAAgE;IACzD,YAAY,CAAC,qBAAqB,GAAG,KAAK;QAC/C,IAAI,qBAAqB;YACvB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAE3C,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF;AAbD,gDAaC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { Constructor } from \"./UtilityTypes\";\r\nimport { assert } from \"./Assert\";\r\n\r\n/** Options used to construct a [[TypedArrayBuilder]].\r\n * @public\r\n */\r\nexport interface TypedArrayBuilderOptions {\r\n /** Controls how much additional memory is allocated when the TypedArray needs to be resized to accomodate more elements.\r\n * [[TypedArrayBuilder.ensureCapacity]] multiplies the required capacity by this factor to determine the new capacity.\r\n * Default: 1.5\r\n * Minimum: 1.0, which causes the TypedArray to allocate exactly the space it needs each time it is resized.\r\n */\r\n growthFactor?: number;\r\n /** The number of elements to allocate memory for in the TypedArray when creating the builder.\r\n * If you know the minimum number of elements you intend to add to the builder, you should specify that as the\r\n * initial capacity to avoid reallocations when populating the array.\r\n * Default: 0.\r\n * Minimum: 0.\r\n */\r\n initialCapacity?: number;\r\n}\r\n\r\n/** Incrementally builds a [TypedArray] of unsigned 8-, 16-, or 32-bit integers.\r\n * Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.\r\n * `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.\r\n *\r\n * `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two \"size\" properties\":\r\n * - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and\r\n * - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].\r\n * When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.\r\n *\r\n * Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].\r\n * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.\r\n * @public\r\n */\r\nexport class TypedArrayBuilder<T extends Uint8Array | Uint16Array | Uint32Array> {\r\n /** The constructor for the specific type of array being populated. */\r\n protected readonly _constructor: Constructor<T>;\r\n /** The underlying typed array, to be reallocated and copied when its capacity is exceeded. */\r\n protected _data: T;\r\n /** The number of elements added to the array so far. */\r\n protected _length: number;\r\n /** Multiplier applied to required capacity by [[ensureCapacity]]. */\r\n public readonly growthFactor: number;\r\n\r\n /** Constructs a new builder from the specified options, with a [[length]] of zero. */\r\n protected constructor(constructor: Constructor<T>, options?: TypedArrayBuilderOptions) {\r\n this._constructor = constructor;\r\n this._data = new constructor(options?.initialCapacity ?? 0);\r\n this.growthFactor = Math.max(1.0, options?.growthFactor ?? 1.5);\r\n this._length = 0;\r\n }\r\n\r\n /** The number of elements currently in the array. */\r\n public get length(): number {\r\n return this._length;\r\n }\r\n\r\n /** The number of elements that can fit into the memory currently allocated for the array. */\r\n public get capacity(): number {\r\n return this._data.length;\r\n }\r\n\r\n /** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),\r\n * returns the element at the specified index, with negative integers counting back from the end of the array.\r\n * @note It is your responsibility to ensure the index falls within the bounds of the array.\r\n */\r\n public at(index: number): number {\r\n if (index < 0)\r\n index = this.length - index;\r\n\r\n const value = this._data[index];\r\n assert(value !== undefined, \"index out of bounds\");\r\n return value;\r\n }\r\n\r\n /** Ensure that [[capacity]] is at least equal to `newCapacity`.\r\n * This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.\r\n * It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.\r\n *\r\n * If `newCapacity` is not greater than the current [[capacity]], this function does nothing.\r\n * Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.\r\n * [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.\r\n */\r\n public ensureCapacity(newCapacity: number): number {\r\n if (this.capacity >= newCapacity)\r\n return this.capacity;\r\n\r\n assert(this.growthFactor >= 1.0);\r\n newCapacity = Math.ceil(newCapacity * this.growthFactor);\r\n const prevData = this._data;\r\n this._data = new this._constructor(newCapacity);\r\n this._data.set(prevData, 0);\r\n\r\n assert(this.capacity === newCapacity);\r\n return this.capacity;\r\n }\r\n\r\n /** Append the specified value, resizing if necessary. */\r\n public push(value: number): void {\r\n this.ensureCapacity(this.length + 1);\r\n this._data[this.length] = value;\r\n ++this._length;\r\n }\r\n\r\n /** Append an array of values, resizing (at most once) if necessary. */\r\n public append(values: T): void {\r\n const newLength = this.length + values.length;\r\n this.ensureCapacity(newLength);\r\n this._data.set(values, this.length);\r\n this._length = newLength;\r\n }\r\n\r\n /** Obtain the finished array.\r\n * @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the\r\n * returned array's length will be equal to [[length]].\r\n */\r\n public toTypedArray(includeUnusedCapacity = false): T {\r\n if (includeUnusedCapacity)\r\n return this._data;\r\n\r\n const subarray = this._data.subarray(0, this.length);\r\n assert(subarray instanceof this._constructor);\r\n assert(subarray.buffer === this._data.buffer);\r\n return subarray;\r\n }\r\n}\r\n\r\n/** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).\r\n * @public\r\n */\r\nexport class Uint8ArrayBuilder extends TypedArrayBuilder<Uint8Array> {\r\n /** @see [[TypedArrayBuilder]] constructor. */\r\n public constructor(options?: TypedArrayBuilderOptions) {\r\n super(Uint8Array, options);\r\n }\r\n}\r\n\r\n/** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).\r\n * @public\r\n */\r\nexport class Uint16ArrayBuilder extends TypedArrayBuilder<Uint16Array> {\r\n /** @see [[TypedArrayBuilder]] constructor. */\r\n public constructor(options?: TypedArrayBuilderOptions) {\r\n super(Uint16Array, options);\r\n }\r\n}\r\n\r\n/** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).\r\n * @public\r\n */\r\nexport class Uint32ArrayBuilder extends TypedArrayBuilder<Uint32Array> {\r\n /** @see [[TypedArrayBuilder]] constructor. */\r\n public constructor(options?: TypedArrayBuilderOptions) {\r\n super(Uint32Array, options);\r\n }\r\n\r\n /** Obtain a view of the finished array as an array of bytes. */\r\n public toUint8Array(includeUnusedCapacity = false): Uint8Array {\r\n if (includeUnusedCapacity)\r\n return new Uint8Array(this._data.buffer);\r\n\r\n return new Uint8Array(this._data.buffer, 0, this.length * 4);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnexpectedErrors.d.ts","sourceRoot":"","sources":["../../src/UnexpectedErrors.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAIH;;GAEG;AACH,oBAAY,iBAAiB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAErD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,kDAAkD;IAClD,gBAAuB,gBAAgB,MAAO,GAAG,WAAkB;IACnE,kHAAkH;IAClH,gBAAuB,eAAe,MAAO,GAAG,oBAAuC;IACvF,+CAA+C;IAC/C,gBAAuB,UAAU,MAAO,GAAG,UAAsB;IACjE,oDAAoD;IACpD,gBAAuB,QAAQ,MAAO,GAAG,UAAyC;IAElF,OAAO,CAAC,MAAM,CAAC,UAAU,CAA2B;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO;IAEP;;OAEG;WACW,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAKlE;;;OAGG;WACW,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,eAAe,UAAO,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"UnexpectedErrors.d.ts","sourceRoot":"","sources":["../../src/UnexpectedErrors.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAIH;;GAEG;AACH,oBAAY,iBAAiB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAErD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,kDAAkD;IAClD,gBAAuB,gBAAgB,MAAO,GAAG,WAAkB;IACnE,kHAAkH;IAClH,gBAAuB,eAAe,MAAO,GAAG,oBAAuC;IACvF,+CAA+C;IAC/C,gBAAuB,UAAU,MAAO,GAAG,UAAsB;IACjE,oDAAoD;IACpD,gBAAuB,QAAQ,MAAO,GAAG,UAAyC;IAElF,OAAO,CAAC,MAAM,CAAC,UAAU,CAA2B;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO;IAEP;;OAEG;WACW,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAKlE;;;OAGG;WACW,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,eAAe,UAAO,GAAG,IAAI;IAa9D;;;;OAIG;WACW,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB;CAKxE"}
|
|
@@ -32,13 +32,16 @@ class UnexpectedErrors {
|
|
|
32
32
|
*/
|
|
33
33
|
static handle(error, notifyTelemetry = true) {
|
|
34
34
|
this._handler(error);
|
|
35
|
-
if (notifyTelemetry)
|
|
35
|
+
if (notifyTelemetry) {
|
|
36
36
|
this._telemetry.forEach((telemetry) => {
|
|
37
37
|
try {
|
|
38
38
|
telemetry(error);
|
|
39
39
|
}
|
|
40
|
-
catch (_) {
|
|
40
|
+
catch (_) {
|
|
41
|
+
// ignore errors from telemetry trackers
|
|
42
|
+
}
|
|
41
43
|
});
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
/** establish a new global *unexpected error* handler.
|
|
44
47
|
* @param handler the new global handler. You may provide your own function or use one of the static members of this class.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnexpectedErrors.js","sourceRoot":"","sources":["../../src/UnexpectedErrors.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,qCAAk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,OAAO,CAAC,EAAE;oBACV,wCAAwC;iBACzC;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,OAA0B;QACjD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,OAAO,UAAU,CAAC;IACpB,CAAC;;AAhDH,4CAiDC;;AAhDC,kDAAkD;AAC3B,iCAAgB,GAAG,CAAC,CAAM,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAE,CAAA;AACnE,kHAAkH;AAC3F,gCAAe,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAE,CAAA;AACvF,+CAA+C;AACxB,2BAAU,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,CAAA,CAAC,iCAAiC;AACnG,oDAAoD;AAC7B,yBAAQ,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,eAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAE,CAAA;AAEnE,2BAAU,GAAwB,EAAG,CAAA;AACrC,yBAAQ,GAAG,EAAI,CAAC,QAAS,CAAA,CAAC,2BAA2B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Errors\r\n */\r\n\r\nimport { Logger } from \"./Logger\";\r\n\r\n/** A function to be notified when an unexpected error happens\r\n * @public\r\n */\r\nexport type OnUnexpectedError = (error: any) => void;\r\n\r\n/**\r\n * Utility for handling/reporting unexpected runtime errors. This class establishes a global handler for\r\n * unexpected errors, and programmers should use its `handle` method when they occur. Generally, unexpected\r\n * errors should not cause program termination, and should instead be logged and swallowed. However, for\r\n * development/debugging, it can be helpful to re-throw exceptions so they are not missed.\r\n * @public\r\n */\r\nexport class UnexpectedErrors {\r\n /** handler for re-throwing exceptions directly */\r\n public static readonly reThrowImmediate = (e: any) => { throw e; };\r\n /** handler for re-throwing exceptions from an asynchronous interval (so the current call stack is not aborted) */\r\n public static readonly reThrowDeferred = (e: any) => setTimeout(() => { throw e; }, 0);\r\n /** handler for logging exception to console */\r\n public static readonly consoleLog = (e: any) => console.error(e); // eslint-disable-line no-console\r\n /** handler for logging exception with [[Logger]] */\r\n public static readonly errorLog = (e: any) => Logger.logException(\"unhandled\", e);\r\n\r\n private static _telemetry: OnUnexpectedError[] = [];\r\n private static _handler = this.errorLog; // default to error logging\r\n private constructor() { } // this is a singleton\r\n\r\n /** Add a \"telemetry tracker\" for unexpected errors. Useful for tracking/reporting errors without changing handler.\r\n * @returns a method to remove the tracker\r\n */\r\n public static addTelemetry(tracker: OnUnexpectedError): () => void {\r\n this._telemetry.push(tracker);\r\n return () => this._telemetry.splice(this._telemetry.indexOf(tracker), 1);\r\n }\r\n\r\n /** call this method when an unexpected error happens so the global handler can process it.\r\n * @param error the unexpected error\r\n * @param notifyTelemetry if false, don't notify telemetry trackers. Use this for exceptions from third-party code, for example.\r\n */\r\n public static handle(error: any, notifyTelemetry = true): void {\r\n this._handler(error);\r\n if (notifyTelemetry) {\r\n this._telemetry.forEach((telemetry) => {\r\n try {\r\n telemetry(error);\r\n } catch (_) {\r\n // ignore errors from telemetry trackers\r\n }\r\n });\r\n }\r\n }\r\n\r\n /** establish a new global *unexpected error* handler.\r\n * @param handler the new global handler. You may provide your own function or use one of the static members of this class.\r\n * The default is [[errorLog]].\r\n * @returns the previous handler. Useful to temporarily change the handler.\r\n */\r\n public static setHandler(handler: OnUnexpectedError): OnUnexpectedError {\r\n const oldHandler = this._handler;\r\n this._handler = handler;\r\n return oldHandler;\r\n }\r\n}\r\n"]}
|
|
@@ -29,6 +29,7 @@ export * from "./SortedArray";
|
|
|
29
29
|
export * from "./StringUtils";
|
|
30
30
|
export * from "./Time";
|
|
31
31
|
export * from "./Tracing";
|
|
32
|
+
export * from "./TypedArrayBuilder";
|
|
32
33
|
export * from "./UnexpectedErrors";
|
|
33
34
|
export * from "./UtilityTypes";
|
|
34
35
|
export * from "./YieldManager";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.d.ts","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAIA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B;;GAEG;AACH;;;GAGG;AACH;;;G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-bentley.js
CHANGED
|
@@ -45,6 +45,7 @@ __exportStar(require("./SortedArray"), exports);
|
|
|
45
45
|
__exportStar(require("./StringUtils"), exports);
|
|
46
46
|
__exportStar(require("./Time"), exports);
|
|
47
47
|
__exportStar(require("./Tracing"), exports);
|
|
48
|
+
__exportStar(require("./TypedArrayBuilder"), exports);
|
|
48
49
|
__exportStar(require("./UnexpectedErrors"), exports);
|
|
49
50
|
__exportStar(require("./UtilityTypes"), exports);
|
|
50
51
|
__exportStar(require("./YieldManager"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,2CAAyB;AACzB,+CAA6B;AAC7B,4CAA0B;AAC1B,iDAA+B;AAC/B,0DAAwC;AACxC,mDAAiC;AACjC,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,+CAA6B;AAC7B,uCAAqB;AACrB,6CAA2B;AAC3B,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,kDAAgC;AAChC,qDAAmC;AACnC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAuB;AACvB,4CAA0B;AAC1B,qDAAmC;AACnC,iDAA+B;AAC/B,iDAA+B;AAE/B;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./AccessToken\";\r\nexport * from \"./Assert\";\r\nexport * from \"./AsyncMutex\";\r\nexport * from \"./BeEvent\";\r\nexport * from \"./BentleyError\";\r\nexport * from \"./BentleyLoggerCategory\";\r\nexport * from \"./StatusCategory\";\r\nexport * from \"./BeSQLite\";\r\nexport * from \"./ByteStream\";\r\nexport * from \"./ClassUtils\";\r\nexport * from \"./Compare\";\r\nexport * from \"./CompressedId64Set\";\r\nexport * from \"./Dictionary\";\r\nexport * from \"./Disposable\";\r\nexport * from \"./Id\";\r\nexport * from \"./IndexMap\";\r\nexport * from \"./JsonSchema\";\r\nexport * from \"./JsonUtils\";\r\nexport * from \"./Logger\";\r\nexport * from \"./LRUMap\";\r\nexport * from \"./ObservableSet\";\r\nexport * from \"./OneAtATimeAction\";\r\nexport * from \"./OrderedId64Iterable\";\r\nexport * from \"./OrderedSet\";\r\nexport * from \"./partitionArray\";\r\nexport * from \"./PriorityQueue\";\r\nexport * from \"./ProcessDetector\";\r\nexport * from \"./SortedArray\";\r\nexport * from \"./StringUtils\";\r\nexport * from \"./Time\";\r\nexport * from \"./Tracing\";\r\nexport * from \"./UnexpectedErrors\";\r\nexport * from \"./UtilityTypes\";\r\nexport * from \"./YieldManager\";\r\n\r\n/** @docs-package-description\r\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\r\n */\r\n/**\r\n * @docs-group-description BeSQLite\r\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\r\n */\r\n/**\r\n * @docs-group-description Errors\r\n * Classes for working with errors.\r\n */\r\n/**\r\n * @docs-group-description Events\r\n * Classes for raising and handling events.\r\n */\r\n/**\r\n * @docs-group-description Ids\r\n * Classes for working with unique identifiers.\r\n */\r\n/**\r\n * @docs-group-description Logging\r\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\r\n */\r\n/**\r\n * @docs-group-description Collections\r\n * Specialized, customizable collection classes like priority queues.\r\n */\r\n/**\r\n * @docs-group-description Json\r\n * utilities for dealing with Json strings and files.\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * Miscellaneous utility classes.\r\n */\r\n/**\r\n * @docs-group-description ProcessDetector\r\n * Functions for determining the type of the current JavaScript process.\r\n */\r\n"]}
|
|
1
|
+
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,2CAAyB;AACzB,+CAA6B;AAC7B,4CAA0B;AAC1B,iDAA+B;AAC/B,0DAAwC;AACxC,mDAAiC;AACjC,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,+CAA6B;AAC7B,uCAAqB;AACrB,6CAA2B;AAC3B,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,kDAAgC;AAChC,qDAAmC;AACnC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAuB;AACvB,4CAA0B;AAC1B,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,iDAA+B;AAE/B;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./AccessToken\";\r\nexport * from \"./Assert\";\r\nexport * from \"./AsyncMutex\";\r\nexport * from \"./BeEvent\";\r\nexport * from \"./BentleyError\";\r\nexport * from \"./BentleyLoggerCategory\";\r\nexport * from \"./StatusCategory\";\r\nexport * from \"./BeSQLite\";\r\nexport * from \"./ByteStream\";\r\nexport * from \"./ClassUtils\";\r\nexport * from \"./Compare\";\r\nexport * from \"./CompressedId64Set\";\r\nexport * from \"./Dictionary\";\r\nexport * from \"./Disposable\";\r\nexport * from \"./Id\";\r\nexport * from \"./IndexMap\";\r\nexport * from \"./JsonSchema\";\r\nexport * from \"./JsonUtils\";\r\nexport * from \"./Logger\";\r\nexport * from \"./LRUMap\";\r\nexport * from \"./ObservableSet\";\r\nexport * from \"./OneAtATimeAction\";\r\nexport * from \"./OrderedId64Iterable\";\r\nexport * from \"./OrderedSet\";\r\nexport * from \"./partitionArray\";\r\nexport * from \"./PriorityQueue\";\r\nexport * from \"./ProcessDetector\";\r\nexport * from \"./SortedArray\";\r\nexport * from \"./StringUtils\";\r\nexport * from \"./Time\";\r\nexport * from \"./Tracing\";\r\nexport * from \"./TypedArrayBuilder\";\r\nexport * from \"./UnexpectedErrors\";\r\nexport * from \"./UtilityTypes\";\r\nexport * from \"./YieldManager\";\r\n\r\n/** @docs-package-description\r\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\r\n */\r\n/**\r\n * @docs-group-description BeSQLite\r\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\r\n */\r\n/**\r\n * @docs-group-description Errors\r\n * Classes for working with errors.\r\n */\r\n/**\r\n * @docs-group-description Events\r\n * Classes for raising and handling events.\r\n */\r\n/**\r\n * @docs-group-description Ids\r\n * Classes for working with unique identifiers.\r\n */\r\n/**\r\n * @docs-group-description Logging\r\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\r\n */\r\n/**\r\n * @docs-group-description Collections\r\n * Specialized, customizable collection classes like priority queues.\r\n */\r\n/**\r\n * @docs-group-description Json\r\n * utilities for dealing with Json strings and files.\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * Miscellaneous utility classes.\r\n */\r\n/**\r\n * @docs-group-description ProcessDetector\r\n * Functions for determining the type of the current JavaScript process.\r\n */\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ByteStream.d.ts","sourceRoot":"","sources":["../../src/ByteStream.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,UAAU,EAAE,MAAM,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,OAAO,CAAa;IAE5B;;;;;;;;;;;;;OAaG;gBACgB,MAAM,EAAE,WAAW,GAAG,iBAAiB,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAUhH;;OAEG;WACW,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAK3D;;;OAGG;WACW,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;IAIxI,yCAAyC;IACzC,IAAW,MAAM,IAAI,MAAM,CAAkC;IAC7D;;OAEG;IACH,IAAW,YAAY,IAAI,OAAO,CAAsC;IACxE;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAAwC;IAExE,sEAAsE;IACtE,IAAW,MAAM,IAAI,MAAM,CAAyB;IACpD,IAAW,MAAM,CAAC,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ByteStream.d.ts","sourceRoot":"","sources":["../../src/ByteStream.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,UAAU,EAAE,MAAM,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QA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AAwI;IACxI,IAAW,QAAQ,IAAI,UAAU,CAAkE;IACnG,6FAA6F;IAC7F,IAAW,UAAU,IAAI,MAAM,CAA4E;IAE3G;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAM9C,qGAAqG;IAC9F,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU;IAI/D,0HAA0H;IACnH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW;IAOnD,0CAA0C;IAC1C,IAAW,WAAW,IAAI,WAAW,GAAG,iBAAiB,CAA8B;IAEvF,OAAO,CAAC,IAAI;CAKb"}
|
package/lib/esm/ByteStream.js
CHANGED
|
@@ -66,12 +66,22 @@ export class ByteStream {
|
|
|
66
66
|
get isAtTheEnd() { return this.curPos === this.length; }
|
|
67
67
|
/** The current read position as an index into the stream of bytes. */
|
|
68
68
|
get curPos() { return this._curPos; }
|
|
69
|
-
set curPos(pos) {
|
|
69
|
+
set curPos(pos) {
|
|
70
|
+
this._curPos = pos;
|
|
71
|
+
assert(!this.isPastTheEnd);
|
|
72
|
+
}
|
|
70
73
|
/** Adds the specified number of bytes to the current read position */
|
|
71
|
-
advance(numBytes) {
|
|
74
|
+
advance(numBytes) {
|
|
75
|
+
this.curPos = (this.curPos + numBytes);
|
|
76
|
+
return !this.isPastTheEnd;
|
|
77
|
+
}
|
|
72
78
|
/** Subtracts the specified number of bytes from the current read position */
|
|
73
|
-
rewind(numBytes) {
|
|
74
|
-
|
|
79
|
+
rewind(numBytes) {
|
|
80
|
+
if (this.curPos - numBytes < 0)
|
|
81
|
+
return false;
|
|
82
|
+
this.curPos = this.curPos - numBytes;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
75
85
|
/** Resets the current read position to the beginning of the stream */
|
|
76
86
|
reset() { this.curPos = 0; }
|
|
77
87
|
/** Read a unsigned 8-bit integer from the current read position and advance by 1 byte. */
|
|
@@ -1 +1 @@
|
|
|
1
|
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,CAAC,CAAC;QACzF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qGAAqG;IAC9F,SAAS,CAAC,OAAe,EAAE,QAAgB;QAChD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChF,CAAC;IAED,0HAA0H;IACnH,WAAW,CAAC,UAAkB;QACnC,MAAM,QAAQ,GAAG,UAAU,GAAG,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9F,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,0CAA0C;IAC1C,IAAW,WAAW,KAAsC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/E,IAAI,CAAC,QAAgB,EAAE,IAAgC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { assert } from \"./Assert\";\r\nimport { Id64, Id64String } from \"./Id\";\r\n\r\n/** Allows the contents of an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)\r\n * to be consumed sequentially using methods to extract\r\n * data of a particular type from the bytes beginning at the current read position.\r\n * Methods and properties beginning with 'next' consume data at the current read position and advance it\r\n * by the size of the data read. The read position can also be directly adjusted by the caller.\r\n * @public\r\n */\r\nexport class ByteStream {\r\n private readonly _view: DataView;\r\n private readonly _byteOffset: number;\r\n private _curPos: number = 0;\r\n\r\n /** Construct a new ByteStream with the read position set to the beginning.\r\n * @param buffer The underlying buffer from which data is to be extracted.\r\n * @param subView If defined, specifies the subset of the underlying buffer's data to use.\r\n * This constructor is subject to two common mistakes:\r\n *\r\n * 1. Given `bytes: Uint8Array`, `new ByteStream(bytes)` will compile but at run-time will produce an error asserting that\r\n * the DataView constructor requires an ArrayBuffer. The correct usage is `new ByteStream(bytes.buffer)`.\r\n * 2. Given `bytes: Uint8Array`, `new ByteStream(bytes.buffer)` creates a stream for the entire range of bytes represented by the underlying\r\n * ArrayBuffer. If `bytes` represents only a **sub-range** of the underlying buffer's data, the results will be unexpected unless the optional `subView`\r\n * argument is supplied, with correct offset and length.\r\n *\r\n * For both of the above reasons, prefer to use [[fromUint8Array]].\r\n * @deprecated Use [[fromUint8Array]] or [[fromArrayBuffer]].\r\n */\r\n public constructor(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteOffset: number, byteLength: number }) {\r\n if (undefined !== subView) {\r\n this._view = new DataView(buffer, subView.byteOffset, subView.byteLength);\r\n this._byteOffset = subView.byteOffset;\r\n } else {\r\n this._view = new DataView(buffer);\r\n this._byteOffset = 0;\r\n }\r\n }\r\n\r\n /** Construct a new ByteStream for the range of bytes represented by `bytes`, which may be a subset of the range of bytes\r\n * represented by the underlying ArrayBuffer. The read position will be set to the beginning of the range of bytes.\r\n */\r\n public static fromUint8Array(bytes: Uint8Array): ByteStream {\r\n const { byteOffset, byteLength } = bytes;\r\n return new ByteStream(bytes.buffer, { byteOffset, byteLength }); // eslint-disable-line deprecation/deprecation\r\n }\r\n\r\n /** Construct a new ByteStream with the read position set to the beginning.\r\n * @param buffer The underlying buffer from which data is to be extracted.\r\n * @param subView If defined, specifies the subset of the underlying buffer's data to use.\r\n */\r\n public static fromArrayBuffer(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteOffset: number, byteLength: number }): ByteStream {\r\n return new ByteStream(buffer, subView); // eslint-disable-line deprecation/deprecation\r\n }\r\n\r\n /** The number of bytes in this stream */\r\n public get length(): number { return this._view.byteLength; }\r\n /** Returns true if the current read position has been advanced past the end of the stream. This generally indicates that an attempt was made to read more data than is available.\r\n * @see [[isAtTheEnd]]\r\n */\r\n public get isPastTheEnd(): boolean { return this.curPos > this.length; }\r\n /** Returns true if the current read position has advanced precisely to the end of the stream, indicating all of the data has been consumed.\r\n * @see [[isPastTheEnd]].\r\n */\r\n public get isAtTheEnd(): boolean { return this.curPos === this.length; }\r\n\r\n /** The current read position as an index into the stream of bytes. */\r\n public get curPos(): number { return this._curPos; }\r\n public set curPos(pos: number) { this._curPos = pos; assert(!this.isPastTheEnd); }\r\n\r\n /** Adds the specified number of bytes to the current read position */\r\n public advance(numBytes: number): boolean { this.curPos = (this.curPos + numBytes); return !this.isPastTheEnd; }\r\n /** Subtracts the specified number of bytes from the current read position */\r\n public rewind(numBytes: number): boolean { if (this.curPos - numBytes < 0) return false; this.curPos = this.curPos - numBytes; return true; }\r\n /** Resets the current read position to the beginning of the stream */\r\n public reset(): void { this.curPos = 0; }\r\n\r\n /** Read a unsigned 8-bit integer from the current read position and advance by 1 byte. */\r\n public get nextUint8(): number { return this.read(1, (view) => view.getUint8(this.curPos)); }\r\n /** Read an unsigned 16-bit integer from the current read position and advance by 2 bytes. */\r\n public get nextUint16(): number { return this.read(2, (view) => view.getUint16(this.curPos, true)); }\r\n /** Read an unsigned 32-bit integer from the current read position and advance by 4 bytes. */\r\n public get nextUint32(): number { return this.read(4, (view) => view.getUint32(this.curPos, true)); }\r\n /** Read a signed 32-bit integer from the current read position and advance by 4 bytes. */\r\n public get nextInt32(): number { return this.read(4, (view) => view.getInt32(this.curPos, true)); }\r\n /** Read a 32-bit floating point number from the current read position and advance by 4 bytes. */\r\n public get nextFloat32(): number { return this.read(4, (view) => view.getFloat32(this.curPos, true)); }\r\n /** Read a 64-bit floating point number from the current read position and advance by 8 bytes. */\r\n public get nextFloat64(): number { return this.read(8, (view) => view.getFloat64(this.curPos, true)); }\r\n /** Read an unsigned 64-bit integer from the current read position, advance by 8 bytes, and return the 64-bit value as an Id64String. */\r\n public get nextId64(): Id64String { return Id64.fromUint32Pair(this.nextUint32, this.nextUint32); }\r\n /** Read an unsigned 24-bit integer from the current read position and advance by 3 bytes. */\r\n public get nextUint24(): number { return this.nextUint8 | (this.nextUint8 << 8) | (this.nextUint8 << 16); }\r\n\r\n /** Read the specified number of bytes beginning at the current read position into a Uint8Array and advance by the specified number of byte.\r\n * @param numBytes The number of bytes to read.\r\n */\r\n public nextBytes(numBytes: number): Uint8Array {\r\n const bytes = new Uint8Array(this.arrayBuffer, this.curPos + this._byteOffset, numBytes);\r\n this.advance(numBytes);\r\n return bytes;\r\n }\r\n\r\n /** Read the specified number of bytes at the specified offset without changing the read position. */\r\n public readBytes(readPos: number, numBytes: number): Uint8Array {\r\n return new Uint8Array(this.arrayBuffer, readPos + this._byteOffset, numBytes);\r\n }\r\n\r\n /** Read the specified number of unsigned 32-bit integers from the current read position and advance the read position. */\r\n public nextUint32s(numUint32s: number): Uint32Array {\r\n const numBytes = numUint32s * 4;\r\n const uint32s = new Uint32Array(this.arrayBuffer, this.curPos + this._byteOffset, numUint32s);\r\n this.advance(numBytes);\r\n return uint32s;\r\n }\r\n\r\n /** Returns the underlying array buffer */\r\n public get arrayBuffer(): ArrayBuffer | SharedArrayBuffer { return this._view.buffer; }\r\n\r\n private read(numBytes: number, read: (view: DataView) => number) {\r\n const result = read(this._view);\r\n this.advance(numBytes);\r\n return result;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ByteStream.js","sourceRoot":"","sources":["../../src/ByteStream.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM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S,CAAC,OAAe,EAAE,QAAgB;QAChD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChF,CAAC;IAED,0HAA0H;IACnH,WAAW,CAAC,UAAkB;QACnC,MAAM,QAAQ,GAAG,UAAU,GAAG,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9F,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,0CAA0C;IAC1C,IAAW,WAAW,KAAsC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/E,IAAI,CAAC,QAAgB,EAAE,IAAgC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { assert } from \"./Assert\";\r\nimport { Id64, Id64String } from \"./Id\";\r\n\r\n/** Allows the contents of an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)\r\n * to be consumed sequentially using methods to extract\r\n * data of a particular type from the bytes beginning at the current read position.\r\n * Methods and properties beginning with 'next' consume data at the current read position and advance it\r\n * by the size of the data read. The read position can also be directly adjusted by the caller.\r\n * @public\r\n */\r\nexport class ByteStream {\r\n private readonly _view: DataView;\r\n private readonly _byteOffset: number;\r\n private _curPos: number = 0;\r\n\r\n /** Construct a new ByteStream with the read position set to the beginning.\r\n * @param buffer The underlying buffer from which data is to be extracted.\r\n * @param subView If defined, specifies the subset of the underlying buffer's data to use.\r\n * This constructor is subject to two common mistakes:\r\n *\r\n * 1. Given `bytes: Uint8Array`, `new ByteStream(bytes)` will compile but at run-time will produce an error asserting that\r\n * the DataView constructor requires an ArrayBuffer. The correct usage is `new ByteStream(bytes.buffer)`.\r\n * 2. Given `bytes: Uint8Array`, `new ByteStream(bytes.buffer)` creates a stream for the entire range of bytes represented by the underlying\r\n * ArrayBuffer. If `bytes` represents only a **sub-range** of the underlying buffer's data, the results will be unexpected unless the optional `subView`\r\n * argument is supplied, with correct offset and length.\r\n *\r\n * For both of the above reasons, prefer to use [[fromUint8Array]].\r\n * @deprecated Use [[fromUint8Array]] or [[fromArrayBuffer]].\r\n */\r\n public constructor(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteOffset: number, byteLength: number }) {\r\n if (undefined !== subView) {\r\n this._view = new DataView(buffer, subView.byteOffset, subView.byteLength);\r\n this._byteOffset = subView.byteOffset;\r\n } else {\r\n this._view = new DataView(buffer);\r\n this._byteOffset = 0;\r\n }\r\n }\r\n\r\n /** Construct a new ByteStream for the range of bytes represented by `bytes`, which may be a subset of the range of bytes\r\n * represented by the underlying ArrayBuffer. The read position will be set to the beginning of the range of bytes.\r\n */\r\n public static fromUint8Array(bytes: Uint8Array): ByteStream {\r\n const { byteOffset, byteLength } = bytes;\r\n return new ByteStream(bytes.buffer, { byteOffset, byteLength }); // eslint-disable-line deprecation/deprecation\r\n }\r\n\r\n /** Construct a new ByteStream with the read position set to the beginning.\r\n * @param buffer The underlying buffer from which data is to be extracted.\r\n * @param subView If defined, specifies the subset of the underlying buffer's data to use.\r\n */\r\n public static fromArrayBuffer(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteOffset: number, byteLength: number }): ByteStream {\r\n return new ByteStream(buffer, subView); // eslint-disable-line deprecation/deprecation\r\n }\r\n\r\n /** The number of bytes in this stream */\r\n public get length(): number { return this._view.byteLength; }\r\n /** Returns true if the current read position has been advanced past the end of the stream. This generally indicates that an attempt was made to read more data than is available.\r\n * @see [[isAtTheEnd]]\r\n */\r\n public get isPastTheEnd(): boolean { return this.curPos > this.length; }\r\n /** Returns true if the current read position has advanced precisely to the end of the stream, indicating all of the data has been consumed.\r\n * @see [[isPastTheEnd]].\r\n */\r\n public get isAtTheEnd(): boolean { return this.curPos === this.length; }\r\n\r\n /** The current read position as an index into the stream of bytes. */\r\n public get curPos(): number { return this._curPos; }\r\n public set curPos(pos: number) {\r\n this._curPos = pos;\r\n assert(!this.isPastTheEnd);\r\n }\r\n\r\n /** Adds the specified number of bytes to the current read position */\r\n public advance(numBytes: number): boolean {\r\n this.curPos = (this.curPos + numBytes);\r\n return !this.isPastTheEnd;\r\n }\r\n\r\n /** Subtracts the specified number of bytes from the current read position */\r\n public rewind(numBytes: number): boolean {\r\n if (this.curPos - numBytes < 0)\r\n return false;\r\n\r\n this.curPos = this.curPos - numBytes;\r\n return true;\r\n }\r\n\r\n /** Resets the current read position to the beginning of the stream */\r\n public reset(): void { this.curPos = 0; }\r\n\r\n /** Read a unsigned 8-bit integer from the current read position and advance by 1 byte. */\r\n public get nextUint8(): number { return this.read(1, (view) => view.getUint8(this.curPos)); }\r\n /** Read an unsigned 16-bit integer from the current read position and advance by 2 bytes. */\r\n public get nextUint16(): number { return this.read(2, (view) => view.getUint16(this.curPos, true)); }\r\n /** Read an unsigned 32-bit integer from the current read position and advance by 4 bytes. */\r\n public get nextUint32(): number { return this.read(4, (view) => view.getUint32(this.curPos, true)); }\r\n /** Read a signed 32-bit integer from the current read position and advance by 4 bytes. */\r\n public get nextInt32(): number { return this.read(4, (view) => view.getInt32(this.curPos, true)); }\r\n /** Read a 32-bit floating point number from the current read position and advance by 4 bytes. */\r\n public get nextFloat32(): number { return this.read(4, (view) => view.getFloat32(this.curPos, true)); }\r\n /** Read a 64-bit floating point number from the current read position and advance by 8 bytes. */\r\n public get nextFloat64(): number { return this.read(8, (view) => view.getFloat64(this.curPos, true)); }\r\n /** Read an unsigned 64-bit integer from the current read position, advance by 8 bytes, and return the 64-bit value as an Id64String. */\r\n public get nextId64(): Id64String { return Id64.fromUint32Pair(this.nextUint32, this.nextUint32); }\r\n /** Read an unsigned 24-bit integer from the current read position and advance by 3 bytes. */\r\n public get nextUint24(): number { return this.nextUint8 | (this.nextUint8 << 8) | (this.nextUint8 << 16); }\r\n\r\n /** Read the specified number of bytes beginning at the current read position into a Uint8Array and advance by the specified number of byte.\r\n * @param numBytes The number of bytes to read.\r\n */\r\n public nextBytes(numBytes: number): Uint8Array {\r\n const bytes = new Uint8Array(this.arrayBuffer, this.curPos + this._byteOffset, numBytes);\r\n this.advance(numBytes);\r\n return bytes;\r\n }\r\n\r\n /** Read the specified number of bytes at the specified offset without changing the read position. */\r\n public readBytes(readPos: number, numBytes: number): Uint8Array {\r\n return new Uint8Array(this.arrayBuffer, readPos + this._byteOffset, numBytes);\r\n }\r\n\r\n /** Read the specified number of unsigned 32-bit integers from the current read position and advance the read position. */\r\n public nextUint32s(numUint32s: number): Uint32Array {\r\n const numBytes = numUint32s * 4;\r\n const uint32s = new Uint32Array(this.arrayBuffer, this.curPos + this._byteOffset, numUint32s);\r\n this.advance(numBytes);\r\n return uint32s;\r\n }\r\n\r\n /** Returns the underlying array buffer */\r\n public get arrayBuffer(): ArrayBuffer | SharedArrayBuffer { return this._view.buffer; }\r\n\r\n private read(numBytes: number, read: (view: DataView) => number) {\r\n const result = read(this._view);\r\n this.advance(numBytes);\r\n return result;\r\n }\r\n}\r\n"]}
|
package/lib/esm/Compare.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Compare.d.ts","sourceRoot":"","sources":["../../src/Compare.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oBAAY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B,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,cAAc;AACd,wBAAgB,yBAAyB,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,cAAc;AACd,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAE/E;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAO9H"}
|
package/lib/esm/Compare.js
CHANGED
|
@@ -18,11 +18,17 @@ export function compareWithTolerance(a, b, tolerance = 0.1) {
|
|
|
18
18
|
return 0;
|
|
19
19
|
}
|
|
20
20
|
/** @public */
|
|
21
|
-
export function compareNumbers(a, b) {
|
|
21
|
+
export function compareNumbers(a, b) {
|
|
22
|
+
return a - b;
|
|
23
|
+
}
|
|
22
24
|
/** @public */
|
|
23
|
-
export function compareBooleans(a, b) {
|
|
25
|
+
export function compareBooleans(a, b) {
|
|
26
|
+
return a !== b ? (a < b ? -1 : 1) : 0;
|
|
27
|
+
}
|
|
24
28
|
/** @public */
|
|
25
|
-
export function compareStrings(a, b) {
|
|
29
|
+
export function compareStrings(a, b) {
|
|
30
|
+
return a === b ? 0 : (a < b ? -1 : 1);
|
|
31
|
+
}
|
|
26
32
|
/** @public */
|
|
27
33
|
export function comparePossiblyUndefined(compareDefined, lhs, rhs) {
|
|
28
34
|
if (undefined === lhs)
|
|
@@ -33,11 +39,17 @@ export function comparePossiblyUndefined(compareDefined, lhs, rhs) {
|
|
|
33
39
|
return compareDefined(lhs, rhs);
|
|
34
40
|
}
|
|
35
41
|
/** @public */
|
|
36
|
-
export function compareStringsOrUndefined(lhs, rhs) {
|
|
42
|
+
export function compareStringsOrUndefined(lhs, rhs) {
|
|
43
|
+
return comparePossiblyUndefined(compareStrings, lhs, rhs);
|
|
44
|
+
}
|
|
37
45
|
/** @public */
|
|
38
|
-
export function compareNumbersOrUndefined(lhs, rhs) {
|
|
46
|
+
export function compareNumbersOrUndefined(lhs, rhs) {
|
|
47
|
+
return comparePossiblyUndefined(compareNumbers, lhs, rhs);
|
|
48
|
+
}
|
|
39
49
|
/** @public */
|
|
40
|
-
export function compareBooleansOrUndefined(lhs, rhs) {
|
|
50
|
+
export function compareBooleansOrUndefined(lhs, rhs) {
|
|
51
|
+
return comparePossiblyUndefined(compareBooleans, lhs, rhs);
|
|
52
|
+
}
|
|
41
53
|
/** Compare two possibly-undefined values for equality. If both are undefined, the comparison is performed by the supplied `areEqual` function.
|
|
42
54
|
* @public
|
|
43
55
|
*/
|
package/lib/esm/Compare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Compare.js","sourceRoot":"","sources":["../../src/Compare.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwBH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAS,EAAE,CAAS,EAAE,SAAS,GAAG,GAAG;IACxE,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS;QACnB,OAAO,CAAC,CAAC,CAAC;SACP,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS;QACxB,OAAO,CAAC,CAAC;;QAET,OAAO,CAAC,CAAC;AACb,CAAC;AAED,cAAc;AACd,MAAM,UAAU,cAAc,CAAC,CAAS,EAAE,CAAS,
|
|
1
|
+
{"version":3,"file":"Compare.js","sourceRoot":"","sources":["../../src/Compare.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwBH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAS,EAAE,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,cAAc;AACd,MAAM,UAAU,yBAAyB,CAAC,GAAY,EAAE,GAAY;IAClE,OAAO,wBAAwB,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED,cAAc;AACd,MAAM,UAAU,0BAA0B,CAAC,GAAa,EAAE,GAAa;IACrE,OAAO,wBAAwB,CAAC,eAAe,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAO,CAAgB,EAAE,CAAgB,EAAE,QAAiC;IACnH,IAAI,SAAS,KAAK,CAAC;QACjB,OAAO,SAAS,KAAK,CAAC,CAAC;SACpB,IAAI,SAAS,KAAK,CAAC;QACtB,OAAO,KAAK,CAAC;;QAEb,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n/**\r\n * A function that returns a numerical value indicating how two objects are ordered in relation to one another.\r\n * Such functions are used by various collection classes throughout the library.\r\n * Given values `lhs` and `rhs`, the function returns:\r\n * - Zero if lhs == rhs\r\n * - A negative number if lhs < rhs\r\n * - A positive number if lhs > rhs\r\n *\r\n * An OrderedComparator `must` implement [strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), which can be summarized by the following rules:\r\n * - `compare(x, x)` returns zero.\r\n * - If `compare(x, y)` returns zero, then so does `compare(y, x)` (i.e., `x == y` implies `y == x`).\r\n * - If `compare(x, y)` returns non-zero, then `compare(y, x)` returns a value with an opposite sign (i.e., `x < y` implies `y > x`).\r\n * - If `compare(x, y)` and `compare(y, z)` return non-zero values with the same sign, then `compare(x, z)` returns a value with the same sign (i.e., `x < y < z` implies `x < z`).\r\n *\r\n * @see SortedArray\r\n * @see Dictionary\r\n * @see IndexMap\r\n * @see PriorityQueue\r\n * @public\r\n */\r\nexport type OrderedComparator<T, U = T> = (lhs: T, rhs: U) => number;\r\n\r\n/**\r\n * An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance.\r\n * @public\r\n */\r\nexport function compareWithTolerance(a: number, b: number, tolerance = 0.1): number {\r\n if (a < b - tolerance)\r\n return -1;\r\n else if (a > b + tolerance)\r\n return 1;\r\n else\r\n return 0;\r\n}\r\n\r\n/** @public */\r\nexport function compareNumbers(a: number, b: number): number {\r\n return a - b;\r\n}\r\n\r\n/** @public */\r\nexport function compareBooleans(a: boolean, b: boolean): number {\r\n return a !== b ? (a < b ? -1 : 1) : 0;\r\n}\r\n\r\n/** @public */\r\nexport function compareStrings(a: string, b: string): number {\r\n return a === b ? 0 : (a < b ? -1 : 1);\r\n}\r\n\r\n/** @public */\r\nexport function comparePossiblyUndefined<T>(compareDefined: (lhs: T, rhs: T) => number, lhs?: T, rhs?: T): number {\r\n if (undefined === lhs)\r\n return undefined === rhs ? 0 : -1;\r\n else if (undefined === rhs)\r\n return 1;\r\n else\r\n return compareDefined(lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareStringsOrUndefined(lhs?: string, rhs?: string): number {\r\n return comparePossiblyUndefined(compareStrings, lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareNumbersOrUndefined(lhs?: number, rhs?: number): number {\r\n return comparePossiblyUndefined(compareNumbers, lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareBooleansOrUndefined(lhs?: boolean, rhs?: boolean): number {\r\n return comparePossiblyUndefined(compareBooleans, lhs, rhs);\r\n}\r\n\r\n/** Compare two possibly-undefined values for equality. If both are undefined, the comparison is performed by the supplied `areEqual` function.\r\n * @public\r\n */\r\nexport function areEqualPossiblyUndefined<T, U>(t: T | undefined, u: U | undefined, areEqual: (t: T, u: U) => boolean): boolean {\r\n if (undefined === t)\r\n return undefined === u;\r\n else if (undefined === u)\r\n return false;\r\n else\r\n return areEqual(t, u);\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dictionary.d.ts","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAA4B,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Dictionary.d.ts","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAA4B,MAAM,eAAe,CAAC;AA4BxE;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC,iDAAiD;IACjD,GAAG,EAAE,CAAC,CAAC;IACP,2DAA2D;IAC3D,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,QAAQ,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAM;IAC1B,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACtD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC/C,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAM;IAC5B,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAEjD;;;;;OAKG;gBACgB,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAE,aAAa,CAAC,CAAC,CAAg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AI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAM,IAAuC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\nimport { CloneFunction, lowerBound, shallowClone } from \"./SortedArray\";\r\n\r\nclass DictionaryIterator<K, V> implements Iterator<DictionaryEntry<K, V>> {\r\n private _keys: K[];\r\n private _values: V[];\r\n private _curIndex = -1;\r\n\r\n public constructor(keys: K[], values: V[]) { this._keys = keys; this._values = values; }\r\n\r\n public next(): IteratorResult<DictionaryEntry<K, V>> {\r\n if (++this._curIndex >= this._keys.length) {\r\n // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.\r\n return { done: true } as any as IteratorResult<DictionaryEntry<K, V>>;\r\n } else {\r\n return {\r\n value: {\r\n key: this._keys[this._curIndex],\r\n value: this._values[this._curIndex],\r\n },\r\n done: false,\r\n };\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents an entry in a [[Dictionary]].\r\n * @public\r\n */\r\nexport interface DictionaryEntry<K, V> {\r\n /** The key used for lookup in the Dictionary. */\r\n key: K;\r\n /** The value associated with the key in the Dictionary. */\r\n value: V;\r\n}\r\n\r\n/**\r\n * Maintains a mapping of keys to values.\r\n * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).\r\n * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Modifying a key in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that keys will cease to map to the values with which they were initially inserted.\r\n * @public\r\n */\r\nexport class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {\r\n protected _keys: K[] = [];\r\n protected readonly _compareKeys: OrderedComparator<K>;\r\n protected readonly _cloneKey: CloneFunction<K>;\r\n protected _values: V[] = [];\r\n protected readonly _cloneValue: CloneFunction<V>;\r\n\r\n /**\r\n * Construct a new Dictionary<K, V>.\r\n * @param compareKeys The function used to compare keys within the dictionary.\r\n * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.\r\n * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.\r\n */\r\n public constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone) {\r\n this._compareKeys = compareKeys;\r\n this._cloneKey = cloneKey;\r\n this._cloneValue = cloneValue;\r\n }\r\n\r\n /** The number of entries in the dictionary. */\r\n public get size(): number { return this._keys.length; }\r\n\r\n /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */\r\n public [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> {\r\n return new DictionaryIterator<K, V>(this._keys, this._values);\r\n }\r\n\r\n /** Provides iteration over the keys in this Dictionary, in sorted order. */\r\n public keys(): Iterable<K> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.key;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */\r\n public values(): Iterable<V> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.value;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Removes all entries from this dictionary */\r\n public clear(): void {\r\n this._keys = [];\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Looks up a value by its key.\r\n * @param key The key to search for\r\n * @returns the value associated with the key, or undefined if the key is not present in the dictionary.\r\n */\r\n public get(key: K): V | undefined {\r\n const bound = this.lowerBound(key);\r\n return bound.equal ? this._values[bound.index] : undefined;\r\n }\r\n\r\n /**\r\n * Determines if an entry exists for the specified key\r\n * @param key The key to search for\r\n * @returns true if an entry exists in this dictionary corresponding to the specified key.\r\n */\r\n public has(key: K): boolean {\r\n return this.lowerBound(key).equal;\r\n }\r\n\r\n /**\r\n * Deletes a value using its key.\r\n * @param key The key to delete\r\n * @returns true if the key was found and deleted.\r\n */\r\n public delete(key: K): boolean {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values.splice(bound.index, 1);\r\n this._keys.splice(bound.index, 1);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.\r\n * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.\r\n * @param key The key to associate with the value\r\n * @param value The value to associate with the key\r\n * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.\r\n */\r\n public insert(key: K, value: V): boolean {\r\n const result = this.findOrInsert(key, value);\r\n return result.inserted;\r\n }\r\n\r\n /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.\r\n * @param key The key to search for.\r\n * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.\r\n * @returns The found or inserted value and a flag indicating whether the new value was inserted.\r\n */\r\n public findOrInsert(key: K, value: V): { value: V, inserted: boolean } {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal)\r\n return { value: this._values[bound.index], inserted: false };\r\n\r\n value = this._cloneValue(value);\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, this._cloneValue(value));\r\n return { value, inserted: true };\r\n }\r\n\r\n /**\r\n * Sets the value associated with the specified key in the dictionary.\r\n * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.\r\n * In either case, the value will be cloned using the function supplied to the dictionary's constructor.\r\n */\r\n public set(key: K, value: V): void {\r\n value = this._cloneValue(value);\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values[bound.index] = value;\r\n } else {\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, value);\r\n }\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.\r\n * @returns An array of { key, value } pairs sorted by key.\r\n */\r\n public extractPairs(): Array<{ key: K, value: V }> {\r\n const pairs: Array<{ key: K, value: V }> = [];\r\n for (let i = 0; i < this.size; i++)\r\n pairs.push({ key: this._keys[i], value: this._values[i] });\r\n\r\n this.clear();\r\n return pairs;\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.\r\n * The array of keys is sorted according to the comparison criterion.\r\n * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.\r\n * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.\r\n */\r\n public extractArrays(): { keys: K[], values: V[] } {\r\n const result = { keys: this._keys, values: this._values };\r\n this.clear();\r\n return result;\r\n }\r\n\r\n /** Apply a function to each (key, value) pair in the dictionary, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (key: K, value: V) => void): void {\r\n for (let i = 0; i < this.size; i++)\r\n func(this._keys[i], this._values[i]);\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified key should be inserted to maintain sorted order.\r\n * @param key The key whose position is to be computed.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.\r\n */\r\n protected lowerBound(key: K): { index: number, equal: boolean } { return lowerBound(key, this._keys, this._compareKeys); }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Dictionary.js","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAiB,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,kBAAkB;IAKtB,YAAmB,IAAS,EAAE,MAAW;QAFjC,cAAS,GAAG,CAAC,CAAC,CAAC;QAGrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,IAAI;QACT,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACzC,0JAA0J;YAC1J,OAAO,EAAE,IAAI,EAAE,IAAI,EAAkD,CAAC;SACvE;aAAM;YACL,OAAO;gBACL,KAAK,EAAE;oBACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;iBACpC;gBACD,IAAI,EAAE,KAAK;aACZ,CAAC;SACH;IACH,CAAC;CACF;AAaD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,UAAU;IAOrB;;;;;OAKG;IACH,YAAmB,WAAiC,EAAE,WAA6B,YAAY,EAAE,aAA+B,YAAY;QAZlI,UAAK,GAAQ,EAAE,CAAC;QAGhB,YAAO,GAAQ,EAAE,CAAC;QAU1B,IAAI,CAAC,Y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b,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAgC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAM,IAAuC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\nimport { CloneFunction, lowerBound, shallowClone } from \"./SortedArray\";\r\n\r\nclass DictionaryIterator<K, V> implements Iterator<DictionaryEntry<K, V>> {\r\n private _keys: K[];\r\n private _values: V[];\r\n private _curIndex = -1;\r\n\r\n public constructor(keys: K[], values: V[]) {\r\n this._keys = keys;\r\n this._values = values;\r\n }\r\n\r\n public next(): IteratorResult<DictionaryEntry<K, V>> {\r\n if (++this._curIndex >= this._keys.length) {\r\n // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.\r\n return { done: true } as any as IteratorResult<DictionaryEntry<K, V>>;\r\n } else {\r\n return {\r\n value: {\r\n key: this._keys[this._curIndex],\r\n value: this._values[this._curIndex],\r\n },\r\n done: false,\r\n };\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents an entry in a [[Dictionary]].\r\n * @public\r\n */\r\nexport interface DictionaryEntry<K, V> {\r\n /** The key used for lookup in the Dictionary. */\r\n key: K;\r\n /** The value associated with the key in the Dictionary. */\r\n value: V;\r\n}\r\n\r\n/**\r\n * Maintains a mapping of keys to values.\r\n * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).\r\n * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Modifying a key in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that keys will cease to map to the values with which they were initially inserted.\r\n * @public\r\n */\r\nexport class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {\r\n protected _keys: K[] = [];\r\n protected readonly _compareKeys: OrderedComparator<K>;\r\n protected readonly _cloneKey: CloneFunction<K>;\r\n protected _values: V[] = [];\r\n protected readonly _cloneValue: CloneFunction<V>;\r\n\r\n /**\r\n * Construct a new Dictionary<K, V>.\r\n * @param compareKeys The function used to compare keys within the dictionary.\r\n * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.\r\n * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.\r\n */\r\n public constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone) {\r\n this._compareKeys = compareKeys;\r\n this._cloneKey = cloneKey;\r\n this._cloneValue = cloneValue;\r\n }\r\n\r\n /** The number of entries in the dictionary. */\r\n public get size(): number { return this._keys.length; }\r\n\r\n /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */\r\n public [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> {\r\n return new DictionaryIterator<K, V>(this._keys, this._values);\r\n }\r\n\r\n /** Provides iteration over the keys in this Dictionary, in sorted order. */\r\n public keys(): Iterable<K> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.key;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */\r\n public values(): Iterable<V> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.value;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Removes all entries from this dictionary */\r\n public clear(): void {\r\n this._keys = [];\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Looks up a value by its key.\r\n * @param key The key to search for\r\n * @returns the value associated with the key, or undefined if the key is not present in the dictionary.\r\n */\r\n public get(key: K): V | undefined {\r\n const bound = this.lowerBound(key);\r\n return bound.equal ? this._values[bound.index] : undefined;\r\n }\r\n\r\n /**\r\n * Determines if an entry exists for the specified key\r\n * @param key The key to search for\r\n * @returns true if an entry exists in this dictionary corresponding to the specified key.\r\n */\r\n public has(key: K): boolean {\r\n return this.lowerBound(key).equal;\r\n }\r\n\r\n /**\r\n * Deletes a value using its key.\r\n * @param key The key to delete\r\n * @returns true if the key was found and deleted.\r\n */\r\n public delete(key: K): boolean {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values.splice(bound.index, 1);\r\n this._keys.splice(bound.index, 1);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.\r\n * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.\r\n * @param key The key to associate with the value\r\n * @param value The value to associate with the key\r\n * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.\r\n */\r\n public insert(key: K, value: V): boolean {\r\n const result = this.findOrInsert(key, value);\r\n return result.inserted;\r\n }\r\n\r\n /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.\r\n * @param key The key to search for.\r\n * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.\r\n * @returns The found or inserted value and a flag indicating whether the new value was inserted.\r\n */\r\n public findOrInsert(key: K, value: V): { value: V, inserted: boolean } {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal)\r\n return { value: this._values[bound.index], inserted: false };\r\n\r\n value = this._cloneValue(value);\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, this._cloneValue(value));\r\n return { value, inserted: true };\r\n }\r\n\r\n /**\r\n * Sets the value associated with the specified key in the dictionary.\r\n * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.\r\n * In either case, the value will be cloned using the function supplied to the dictionary's constructor.\r\n */\r\n public set(key: K, value: V): void {\r\n value = this._cloneValue(value);\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values[bound.index] = value;\r\n } else {\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, value);\r\n }\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.\r\n * @returns An array of { key, value } pairs sorted by key.\r\n */\r\n public extractPairs(): Array<{ key: K, value: V }> {\r\n const pairs: Array<{ key: K, value: V }> = [];\r\n for (let i = 0; i < this.size; i++)\r\n pairs.push({ key: this._keys[i], value: this._values[i] });\r\n\r\n this.clear();\r\n return pairs;\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.\r\n * The array of keys is sorted according to the comparison criterion.\r\n * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.\r\n * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.\r\n */\r\n public extractArrays(): { keys: K[], values: V[] } {\r\n const result = { keys: this._keys, values: this._values };\r\n this.clear();\r\n return result;\r\n }\r\n\r\n /** Apply a function to each (key, value) pair in the dictionary, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (key: K, value: V) => void): void {\r\n for (let i = 0; i < this.size; i++)\r\n func(this._keys[i], this._values[i]);\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified key should be inserted to maintain sorted order.\r\n * @param key The key whose position is to be computed.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.\r\n */\r\n protected lowerBound(key: K): { index: number, equal: boolean } { return lowerBound(key, this._keys, this._compareKeys); }\r\n}\r\n"]}
|
package/lib/esm/Id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Id.d.ts","sourceRoot":"","sources":["../../src/Id.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;GAGG;AACH,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,oBAAY,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;AAEtC;;GAEG;AACH,oBAAY,SAAS,GAAG,UAAU,EAAE,CAAC;AAErC;;GAEG;AACH,oBAAY,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;AAiCvD;;;;;;;;GAQG;AACH,yBAAiB,IAAI,CAAC;IACpB,2GAA2G;IAC3G,SAAgB,UAAU,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAOjD;IAED,6GAA6G;IAC7G,SAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAMrD;IAED;;;;;OAKG;IACH,SAAgB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAElD;IAED;;;;;;OAMG;IACH,SAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAyBlD;IAiBD;;;;;OAKG;IACH,SAAgB,wBAAwB,CAAC,OAAO,EAAE,MAA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,CAAa;IAE7B,yEAAyE;IACzE,IAAW,IAAI,IAAI,UAAU,CAAqE;CACnG;AAED;;;;;;GAMG;AACH,yBAAiB,IAAI,CAAC;IAGpB,qEAAqE;IAC9D,MAAM,KAAK,EAAE,UAAmD,CAAC;IAExE;;OAEG;IACH,SAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7C;IAED,mEAAmE;IACnE,SAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE/C;IAED,iCAAiC;IACjC,SAAgB,WAAW,IAAI,UAAU,CAOxC;IAED;;;;;;;OAOG;IACH,SAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAkBvD;CACF"}
|
package/lib/esm/Id.js
CHANGED
|
@@ -387,18 +387,24 @@ export var Id64;
|
|
|
387
387
|
* @see [[Id64.isInvalid]]
|
|
388
388
|
* @see [[Id64.isValidId64]]
|
|
389
389
|
*/
|
|
390
|
-
function isValid(id) {
|
|
390
|
+
function isValid(id) {
|
|
391
|
+
return Id64.invalid !== id;
|
|
392
|
+
}
|
|
391
393
|
Id64.isValid = isValid;
|
|
392
394
|
/** Returns true if the input is a well-formed [[Id64String]] representing a valid Id.
|
|
393
395
|
* @see [[Id64.isValid]]
|
|
394
396
|
* @see [[Id64.isId64]]
|
|
395
397
|
*/
|
|
396
|
-
function isValidId64(id) {
|
|
398
|
+
function isValidId64(id) {
|
|
399
|
+
return Id64.invalid !== id && Id64.isId64(id);
|
|
400
|
+
}
|
|
397
401
|
Id64.isValidId64 = isValidId64;
|
|
398
402
|
/** Returns true if the input is a well-formed [[Id64String]] representing an invalid Id.
|
|
399
403
|
* @see [[Id64.isValid]]
|
|
400
404
|
*/
|
|
401
|
-
function isInvalid(id) {
|
|
405
|
+
function isInvalid(id) {
|
|
406
|
+
return Id64.invalid === id;
|
|
407
|
+
}
|
|
402
408
|
Id64.isInvalid = isInvalid;
|
|
403
409
|
/** A specialized replacement for Set<Id64String> optimized for performance-critical code which represents large sets of [[Id64]]s as pairs of
|
|
404
410
|
* 32-bit integers.
|
|
@@ -574,10 +580,14 @@ export var Guid;
|
|
|
574
580
|
/** Determine whether the input string is "guid-like". That is, it follows the 8-4-4-4-12 pattern. This does not enforce
|
|
575
581
|
* that the string is actually in valid UUID format.
|
|
576
582
|
*/
|
|
577
|
-
function isGuid(value) {
|
|
583
|
+
function isGuid(value) {
|
|
584
|
+
return uuidPattern.test(value);
|
|
585
|
+
}
|
|
578
586
|
Guid.isGuid = isGuid;
|
|
579
587
|
/** Determine whether the input string is a valid V4 Guid string */
|
|
580
|
-
function isV4Guid(value) {
|
|
588
|
+
function isV4Guid(value) {
|
|
589
|
+
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(value);
|
|
590
|
+
}
|
|
581
591
|
Guid.isV4Guid = isV4Guid;
|
|
582
592
|
/** Create a new V4 Guid value */
|
|
583
593
|
function createValue() {
|