@itwin/core-bentley 3.5.0-dev.8 → 3.5.1

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.
Files changed (238) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/lib/cjs/AccessToken.d.ts +8 -8
  3. package/lib/cjs/AccessToken.js +9 -9
  4. package/lib/cjs/AccessToken.js.map +1 -1
  5. package/lib/cjs/Assert.d.ts +25 -25
  6. package/lib/cjs/Assert.js +45 -45
  7. package/lib/cjs/Assert.js.map +1 -1
  8. package/lib/cjs/AsyncMutex.d.ts +26 -26
  9. package/lib/cjs/AsyncMutex.js +43 -43
  10. package/lib/cjs/AsyncMutex.js.map +1 -1
  11. package/lib/cjs/BeEvent.d.ts +81 -81
  12. package/lib/cjs/BeEvent.js +156 -156
  13. package/lib/cjs/BeEvent.js.map +1 -1
  14. package/lib/cjs/BeSQLite.d.ts +170 -170
  15. package/lib/cjs/BeSQLite.js +183 -183
  16. package/lib/cjs/BeSQLite.js.map +1 -1
  17. package/lib/cjs/BentleyError.d.ts +378 -376
  18. package/lib/cjs/BentleyError.d.ts.map +1 -1
  19. package/lib/cjs/BentleyError.js +702 -699
  20. package/lib/cjs/BentleyError.js.map +1 -1
  21. package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
  22. package/lib/cjs/BentleyLoggerCategory.js +19 -19
  23. package/lib/cjs/BentleyLoggerCategory.js.map +1 -1
  24. package/lib/cjs/ByteStream.d.ts +110 -92
  25. package/lib/cjs/ByteStream.d.ts.map +1 -1
  26. package/lib/cjs/ByteStream.js +159 -133
  27. package/lib/cjs/ByteStream.js.map +1 -1
  28. package/lib/cjs/ClassUtils.d.ts +14 -14
  29. package/lib/cjs/ClassUtils.js +27 -27
  30. package/lib/cjs/ClassUtils.js.map +1 -1
  31. package/lib/cjs/Compare.d.ts +47 -47
  32. package/lib/cjs/Compare.js +75 -75
  33. package/lib/cjs/Compare.js.map +1 -1
  34. package/lib/cjs/CompressedId64Set.d.ts +134 -134
  35. package/lib/cjs/CompressedId64Set.js +428 -428
  36. package/lib/cjs/CompressedId64Set.js.map +1 -1
  37. package/lib/cjs/Dictionary.d.ts +125 -125
  38. package/lib/cjs/Dictionary.js +203 -203
  39. package/lib/cjs/Dictionary.js.map +1 -1
  40. package/lib/cjs/Disposable.d.ts +80 -80
  41. package/lib/cjs/Disposable.js +120 -120
  42. package/lib/cjs/Disposable.js.map +1 -1
  43. package/lib/cjs/Id.d.ts +277 -277
  44. package/lib/cjs/Id.js +629 -629
  45. package/lib/cjs/Id.js.map +1 -1
  46. package/lib/cjs/IndexMap.d.ts +65 -65
  47. package/lib/cjs/IndexMap.js +91 -91
  48. package/lib/cjs/IndexMap.js.map +1 -1
  49. package/lib/cjs/JsonSchema.d.ts +77 -77
  50. package/lib/cjs/JsonSchema.js +9 -9
  51. package/lib/cjs/JsonSchema.js.map +1 -1
  52. package/lib/cjs/JsonUtils.d.ts +78 -78
  53. package/lib/cjs/JsonUtils.js +151 -151
  54. package/lib/cjs/JsonUtils.js.map +1 -1
  55. package/lib/cjs/LRUMap.d.ts +129 -129
  56. package/lib/cjs/LRUMap.js +333 -333
  57. package/lib/cjs/LRUMap.js.map +1 -1
  58. package/lib/cjs/Logger.d.ts +143 -141
  59. package/lib/cjs/Logger.d.ts.map +1 -1
  60. package/lib/cjs/Logger.js +258 -254
  61. package/lib/cjs/Logger.js.map +1 -1
  62. package/lib/cjs/ObservableSet.d.ts +23 -23
  63. package/lib/cjs/ObservableSet.js +51 -51
  64. package/lib/cjs/ObservableSet.js.map +1 -1
  65. package/lib/cjs/OneAtATimeAction.d.ts +31 -31
  66. package/lib/cjs/OneAtATimeAction.js +94 -94
  67. package/lib/cjs/OneAtATimeAction.js.map +1 -1
  68. package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
  69. package/lib/cjs/OrderedId64Iterable.js +235 -235
  70. package/lib/cjs/OrderedId64Iterable.js.map +1 -1
  71. package/lib/cjs/OrderedSet.d.ts +40 -40
  72. package/lib/cjs/OrderedSet.js +64 -64
  73. package/lib/cjs/OrderedSet.js.map +1 -1
  74. package/lib/cjs/PriorityQueue.d.ts +70 -70
  75. package/lib/cjs/PriorityQueue.js +140 -140
  76. package/lib/cjs/PriorityQueue.js.map +1 -1
  77. package/lib/cjs/ProcessDetector.d.ts +59 -59
  78. package/lib/cjs/ProcessDetector.js +71 -71
  79. package/lib/cjs/ProcessDetector.js.map +1 -1
  80. package/lib/cjs/SortedArray.d.ts +232 -232
  81. package/lib/cjs/SortedArray.js +303 -303
  82. package/lib/cjs/SortedArray.js.map +1 -1
  83. package/lib/cjs/StatusCategory.d.ts +30 -30
  84. package/lib/cjs/StatusCategory.js +460 -460
  85. package/lib/cjs/StatusCategory.js.map +1 -1
  86. package/lib/cjs/StringUtils.d.ts +22 -22
  87. package/lib/cjs/StringUtils.js +148 -148
  88. package/lib/cjs/StringUtils.js.map +1 -1
  89. package/lib/cjs/Time.d.ts +122 -122
  90. package/lib/cjs/Time.js +152 -152
  91. package/lib/cjs/Time.js.map +1 -1
  92. package/lib/cjs/Tracing.d.ts +40 -40
  93. package/lib/cjs/Tracing.js +130 -130
  94. package/lib/cjs/Tracing.js.map +1 -1
  95. package/lib/cjs/TupleKeyedMap.d.ts +37 -0
  96. package/lib/cjs/TupleKeyedMap.d.ts.map +1 -0
  97. package/lib/cjs/TupleKeyedMap.js +103 -0
  98. package/lib/cjs/TupleKeyedMap.js.map +1 -0
  99. package/lib/cjs/TypedArrayBuilder.d.ts +155 -97
  100. package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
  101. package/lib/cjs/TypedArrayBuilder.js +208 -134
  102. package/lib/cjs/TypedArrayBuilder.js.map +1 -1
  103. package/lib/cjs/UnexpectedErrors.d.ts +43 -43
  104. package/lib/cjs/UnexpectedErrors.js +68 -68
  105. package/lib/cjs/UnexpectedErrors.js.map +1 -1
  106. package/lib/cjs/UtilityTypes.d.ts +100 -86
  107. package/lib/cjs/UtilityTypes.d.ts.map +1 -1
  108. package/lib/cjs/UtilityTypes.js +40 -26
  109. package/lib/cjs/UtilityTypes.js.map +1 -1
  110. package/lib/cjs/YieldManager.d.ts +18 -18
  111. package/lib/cjs/YieldManager.js +34 -34
  112. package/lib/cjs/YieldManager.js.map +1 -1
  113. package/lib/cjs/core-bentley.d.ts +75 -74
  114. package/lib/cjs/core-bentley.d.ts.map +1 -1
  115. package/lib/cjs/core-bentley.js +91 -90
  116. package/lib/cjs/core-bentley.js.map +1 -1
  117. package/lib/cjs/partitionArray.d.ts +21 -21
  118. package/lib/cjs/partitionArray.js +43 -43
  119. package/lib/cjs/partitionArray.js.map +1 -1
  120. package/lib/esm/AccessToken.d.ts +8 -8
  121. package/lib/esm/AccessToken.js +8 -8
  122. package/lib/esm/AccessToken.js.map +1 -1
  123. package/lib/esm/Assert.d.ts +25 -25
  124. package/lib/esm/Assert.js +41 -41
  125. package/lib/esm/Assert.js.map +1 -1
  126. package/lib/esm/AsyncMutex.d.ts +26 -26
  127. package/lib/esm/AsyncMutex.js +39 -39
  128. package/lib/esm/AsyncMutex.js.map +1 -1
  129. package/lib/esm/BeEvent.d.ts +81 -81
  130. package/lib/esm/BeEvent.js +150 -150
  131. package/lib/esm/BeEvent.js.map +1 -1
  132. package/lib/esm/BeSQLite.d.ts +170 -170
  133. package/lib/esm/BeSQLite.js +180 -180
  134. package/lib/esm/BeSQLite.js.map +1 -1
  135. package/lib/esm/BentleyError.d.ts +378 -376
  136. package/lib/esm/BentleyError.d.ts.map +1 -1
  137. package/lib/esm/BentleyError.js +698 -695
  138. package/lib/esm/BentleyError.js.map +1 -1
  139. package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
  140. package/lib/esm/BentleyLoggerCategory.js +16 -16
  141. package/lib/esm/BentleyLoggerCategory.js.map +1 -1
  142. package/lib/esm/ByteStream.d.ts +110 -92
  143. package/lib/esm/ByteStream.d.ts.map +1 -1
  144. package/lib/esm/ByteStream.js +155 -129
  145. package/lib/esm/ByteStream.js.map +1 -1
  146. package/lib/esm/ClassUtils.d.ts +14 -14
  147. package/lib/esm/ClassUtils.js +22 -22
  148. package/lib/esm/ClassUtils.js.map +1 -1
  149. package/lib/esm/Compare.d.ts +47 -47
  150. package/lib/esm/Compare.js +63 -63
  151. package/lib/esm/Compare.js.map +1 -1
  152. package/lib/esm/CompressedId64Set.d.ts +134 -134
  153. package/lib/esm/CompressedId64Set.js +423 -423
  154. package/lib/esm/CompressedId64Set.js.map +1 -1
  155. package/lib/esm/Dictionary.d.ts +125 -125
  156. package/lib/esm/Dictionary.js +199 -199
  157. package/lib/esm/Dictionary.js.map +1 -1
  158. package/lib/esm/Disposable.d.ts +80 -80
  159. package/lib/esm/Disposable.js +112 -112
  160. package/lib/esm/Disposable.js.map +1 -1
  161. package/lib/esm/Id.d.ts +277 -277
  162. package/lib/esm/Id.js +625 -625
  163. package/lib/esm/Id.js.map +1 -1
  164. package/lib/esm/IndexMap.d.ts +65 -65
  165. package/lib/esm/IndexMap.js +86 -86
  166. package/lib/esm/IndexMap.js.map +1 -1
  167. package/lib/esm/JsonSchema.d.ts +77 -77
  168. package/lib/esm/JsonSchema.js +8 -8
  169. package/lib/esm/JsonSchema.js.map +1 -1
  170. package/lib/esm/JsonUtils.d.ts +78 -78
  171. package/lib/esm/JsonUtils.js +148 -148
  172. package/lib/esm/JsonUtils.js.map +1 -1
  173. package/lib/esm/LRUMap.d.ts +129 -129
  174. package/lib/esm/LRUMap.js +326 -326
  175. package/lib/esm/LRUMap.js.map +1 -1
  176. package/lib/esm/Logger.d.ts +143 -141
  177. package/lib/esm/Logger.d.ts.map +1 -1
  178. package/lib/esm/Logger.js +253 -249
  179. package/lib/esm/Logger.js.map +1 -1
  180. package/lib/esm/ObservableSet.d.ts +23 -23
  181. package/lib/esm/ObservableSet.js +47 -47
  182. package/lib/esm/ObservableSet.js.map +1 -1
  183. package/lib/esm/OneAtATimeAction.d.ts +31 -31
  184. package/lib/esm/OneAtATimeAction.js +89 -89
  185. package/lib/esm/OneAtATimeAction.js.map +1 -1
  186. package/lib/esm/OrderedId64Iterable.d.ts +74 -74
  187. package/lib/esm/OrderedId64Iterable.js +232 -232
  188. package/lib/esm/OrderedId64Iterable.js.map +1 -1
  189. package/lib/esm/OrderedSet.d.ts +40 -40
  190. package/lib/esm/OrderedSet.js +59 -59
  191. package/lib/esm/OrderedSet.js.map +1 -1
  192. package/lib/esm/PriorityQueue.d.ts +70 -70
  193. package/lib/esm/PriorityQueue.js +136 -136
  194. package/lib/esm/PriorityQueue.js.map +1 -1
  195. package/lib/esm/ProcessDetector.d.ts +59 -59
  196. package/lib/esm/ProcessDetector.js +67 -67
  197. package/lib/esm/ProcessDetector.js.map +1 -1
  198. package/lib/esm/SortedArray.d.ts +232 -232
  199. package/lib/esm/SortedArray.js +296 -296
  200. package/lib/esm/SortedArray.js.map +1 -1
  201. package/lib/esm/StatusCategory.d.ts +30 -30
  202. package/lib/esm/StatusCategory.js +454 -454
  203. package/lib/esm/StatusCategory.js.map +1 -1
  204. package/lib/esm/StringUtils.d.ts +22 -22
  205. package/lib/esm/StringUtils.js +142 -142
  206. package/lib/esm/StringUtils.js.map +1 -1
  207. package/lib/esm/Time.d.ts +122 -122
  208. package/lib/esm/Time.js +146 -146
  209. package/lib/esm/Time.js.map +1 -1
  210. package/lib/esm/Tracing.d.ts +40 -40
  211. package/lib/esm/Tracing.js +126 -126
  212. package/lib/esm/Tracing.js.map +1 -1
  213. package/lib/esm/TupleKeyedMap.d.ts +37 -0
  214. package/lib/esm/TupleKeyedMap.d.ts.map +1 -0
  215. package/lib/esm/TupleKeyedMap.js +99 -0
  216. package/lib/esm/TupleKeyedMap.js.map +1 -0
  217. package/lib/esm/TypedArrayBuilder.d.ts +155 -97
  218. package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
  219. package/lib/esm/TypedArrayBuilder.js +200 -127
  220. package/lib/esm/TypedArrayBuilder.js.map +1 -1
  221. package/lib/esm/UnexpectedErrors.d.ts +43 -43
  222. package/lib/esm/UnexpectedErrors.js +64 -64
  223. package/lib/esm/UnexpectedErrors.js.map +1 -1
  224. package/lib/esm/UtilityTypes.d.ts +100 -86
  225. package/lib/esm/UtilityTypes.d.ts.map +1 -1
  226. package/lib/esm/UtilityTypes.js +34 -21
  227. package/lib/esm/UtilityTypes.js.map +1 -1
  228. package/lib/esm/YieldManager.d.ts +18 -18
  229. package/lib/esm/YieldManager.js +30 -30
  230. package/lib/esm/YieldManager.js.map +1 -1
  231. package/lib/esm/core-bentley.d.ts +75 -74
  232. package/lib/esm/core-bentley.d.ts.map +1 -1
  233. package/lib/esm/core-bentley.js +79 -78
  234. package/lib/esm/core-bentley.js.map +1 -1
  235. package/lib/esm/partitionArray.d.ts +21 -21
  236. package/lib/esm/partitionArray.js +39 -39
  237. package/lib/esm/partitionArray.js.map +1 -1
  238. package/package.json +4 -4
@@ -1,98 +1,156 @@
1
- /** @packageDocumentation
2
- * @module Collections
3
- */
4
- import { Constructor } from "./UtilityTypes";
5
- /** Options used to construct a [[TypedArrayBuilder]].
6
- * @public
7
- */
8
- export interface TypedArrayBuilderOptions {
9
- /** Controls how much additional memory is allocated when the TypedArray needs to be resized to accomodate more elements.
10
- * [[TypedArrayBuilder.ensureCapacity]] multiplies the required capacity by this factor to determine the new capacity.
11
- * Default: 1.5
12
- * Minimum: 1.0, which causes the TypedArray to allocate exactly the space it needs each time it is resized.
13
- */
14
- growthFactor?: number;
15
- /** The number of elements to allocate memory for in the TypedArray when creating the builder.
16
- * If you know the minimum number of elements you intend to add to the builder, you should specify that as the
17
- * initial capacity to avoid reallocations when populating the array.
18
- * Default: 0.
19
- * Minimum: 0.
20
- */
21
- initialCapacity?: number;
22
- }
23
- /** Incrementally builds a [TypedArray] of unsigned 8-, 16-, or 32-bit integers.
24
- * Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.
25
- * `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.
26
- *
27
- * `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two "size" properties":
28
- * - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and
29
- * - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].
30
- * When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.
31
- *
32
- * Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].
33
- * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.
34
- * @public
35
- */
36
- export declare class TypedArrayBuilder<T extends Uint8Array | Uint16Array | Uint32Array> {
37
- /** The constructor for the specific type of array being populated. */
38
- protected readonly _constructor: Constructor<T>;
39
- /** The underlying typed array, to be reallocated and copied when its capacity is exceeded. */
40
- protected _data: T;
41
- /** The number of elements added to the array so far. */
42
- protected _length: number;
43
- /** Multiplier applied to required capacity by [[ensureCapacity]]. */
44
- readonly growthFactor: number;
45
- /** Constructs a new builder from the specified options, with a [[length]] of zero. */
46
- protected constructor(constructor: Constructor<T>, options?: TypedArrayBuilderOptions);
47
- /** The number of elements currently in the array. */
48
- get length(): number;
49
- /** The number of elements that can fit into the memory currently allocated for the array. */
50
- get capacity(): number;
51
- /** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),
52
- * returns the element at the specified index, with negative integers counting back from the end of the array.
53
- * @note It is your responsibility to ensure the index falls within the bounds of the array.
54
- */
55
- at(index: number): number;
56
- /** Ensure that [[capacity]] is at least equal to `newCapacity`.
57
- * This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.
58
- * It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
59
- *
60
- * If `newCapacity` is not greater than the current [[capacity]], this function does nothing.
61
- * Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.
62
- * [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.
63
- */
64
- ensureCapacity(newCapacity: number): number;
65
- /** Append the specified value, resizing if necessary. */
66
- push(value: number): void;
67
- /** Append an array of values, resizing (at most once) if necessary. */
68
- append(values: T): void;
69
- /** Obtain the finished array.
70
- * @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the
71
- * returned array's length will be equal to [[length]].
72
- */
73
- toTypedArray(includeUnusedCapacity?: boolean): T;
74
- }
75
- /** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
76
- * @public
77
- */
78
- export declare class Uint8ArrayBuilder extends TypedArrayBuilder<Uint8Array> {
79
- /** @see [[TypedArrayBuilder]] constructor. */
80
- constructor(options?: TypedArrayBuilderOptions);
81
- }
82
- /** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).
83
- * @public
84
- */
85
- export declare class Uint16ArrayBuilder extends TypedArrayBuilder<Uint16Array> {
86
- /** @see [[TypedArrayBuilder]] constructor. */
87
- constructor(options?: TypedArrayBuilderOptions);
88
- }
89
- /** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).
90
- * @public
91
- */
92
- export declare class Uint32ArrayBuilder extends TypedArrayBuilder<Uint32Array> {
93
- /** @see [[TypedArrayBuilder]] constructor. */
94
- constructor(options?: TypedArrayBuilderOptions);
95
- /** Obtain a view of the finished array as an array of bytes. */
96
- toUint8Array(includeUnusedCapacity?: boolean): Uint8Array;
97
- }
1
+ /** @packageDocumentation
2
+ * @module Collections
3
+ */
4
+ import { Constructor } from "./UtilityTypes";
5
+ /** Options used to construct a [[TypedArrayBuilder]].
6
+ * @public
7
+ */
8
+ export interface TypedArrayBuilderOptions {
9
+ /** Controls how much additional memory is allocated when the TypedArray needs to be resized to accomodate more elements.
10
+ * [[TypedArrayBuilder.ensureCapacity]] multiplies the required capacity by this factor to determine the new capacity.
11
+ * Default: 1.5
12
+ * Minimum: 1.0, which causes the TypedArray to allocate exactly the space it needs each time it is resized.
13
+ */
14
+ growthFactor?: number;
15
+ /** The number of elements to allocate memory for in the TypedArray when creating the builder.
16
+ * If you know the minimum number of elements you intend to add to the builder, you should specify that as the
17
+ * initial capacity to avoid reallocations when populating the array.
18
+ * Default: 0.
19
+ * Minimum: 0.
20
+ */
21
+ initialCapacity?: number;
22
+ }
23
+ /** A [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) containing unsigned 8-, 16-, or 32-bit integers.
24
+ * @see [[UintArrayBuilder]] to construct such an array.
25
+ * @public
26
+ */
27
+ export declare type UintArray = Uint8Array | Uint16Array | Uint32Array;
28
+ /** Incrementally builds a [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) of unsigned 8-, 16-, or 32-bit integers.
29
+ * Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.
30
+ * `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.
31
+ *
32
+ * `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two "size" properties":
33
+ * - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and
34
+ * - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].
35
+ * When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.
36
+ *
37
+ * Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].
38
+ * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.
39
+ * @see [[UintArrayBuilder]] when you don't know the maximum number of bytes required for each element in the array.
40
+ * @public
41
+ */
42
+ export declare class TypedArrayBuilder<T extends UintArray> {
43
+ /** The constructor for the specific type of array being populated. */
44
+ protected _constructor: Constructor<T>;
45
+ /** The underlying typed array, to be reallocated and copied when its capacity is exceeded. */
46
+ protected _data: T;
47
+ /** The number of elements added to the array so far. */
48
+ protected _length: number;
49
+ /** Multiplier applied to required capacity by [[ensureCapacity]]. */
50
+ readonly growthFactor: number;
51
+ /** Constructs a new builder from the specified options, with a [[length]] of zero. */
52
+ protected constructor(constructor: Constructor<T>, options?: TypedArrayBuilderOptions);
53
+ /** The number of elements currently in the array. */
54
+ get length(): number;
55
+ /** The number of elements that can fit into the memory currently allocated for the array. */
56
+ get capacity(): number;
57
+ /** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),
58
+ * returns the element at the specified index, with negative integers counting back from the end of the array.
59
+ * @note It is your responsibility to ensure the index falls within the bounds of the array.
60
+ */
61
+ at(index: number): number;
62
+ /** Ensure that [[capacity]] is at least equal to `newCapacity`.
63
+ * This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.
64
+ * It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
65
+ *
66
+ * If `newCapacity` is not greater than the current [[capacity]], this function does nothing.
67
+ * Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.
68
+ * [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.
69
+ */
70
+ ensureCapacity(newCapacity: number): number;
71
+ /** Append the specified value, resizing if necessary. */
72
+ push(value: number): void;
73
+ /** Append an array of values, resizing (at most once) if necessary. */
74
+ append(values: T): void;
75
+ /** Obtain the finished array.
76
+ * @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the
77
+ * returned array's length will be equal to [[length]].
78
+ */
79
+ toTypedArray(includeUnusedCapacity?: boolean): T;
80
+ }
81
+ /** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
82
+ * @public
83
+ */
84
+ export declare class Uint8ArrayBuilder extends TypedArrayBuilder<Uint8Array> {
85
+ /** See [[TypedArrayBuilder]] constructor. */
86
+ constructor(options?: TypedArrayBuilderOptions);
87
+ }
88
+ /** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).
89
+ * @public
90
+ */
91
+ export declare class Uint16ArrayBuilder extends TypedArrayBuilder<Uint16Array> {
92
+ /** See [[TypedArrayBuilder]] constructor. */
93
+ constructor(options?: TypedArrayBuilderOptions);
94
+ }
95
+ /** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).
96
+ * @public
97
+ */
98
+ export declare class Uint32ArrayBuilder extends TypedArrayBuilder<Uint32Array> {
99
+ /** See [[TypedArrayBuilder]] constructor. */
100
+ constructor(options?: TypedArrayBuilderOptions);
101
+ /** Obtain a view of the finished array as an array of bytes. */
102
+ toUint8Array(includeUnusedCapacity?: boolean): Uint8Array;
103
+ }
104
+ /** Options used to construct a [[UintArrayBuilder]].
105
+ * @public
106
+ */
107
+ export interface UintArrayBuilderOptions extends TypedArrayBuilderOptions {
108
+ /** The type of the initial empty `TypedArray` created by the builder. For example, if you know that you will be adding values larger than
109
+ * 255 to the array, specify `{ initialType: Uint16Array }` to avoid replacing the otherwise default `Uint8Array` when the first such value is added.
110
+ * Default: `Uint8Array`.
111
+ */
112
+ initialType?: typeof Uint8Array | typeof Uint16Array | typeof Uint32Array;
113
+ }
114
+ /** A [[TypedArrayBuilder]] that can populate a [[UintArray]] with the minimum
115
+ * [bytes per element](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT) required.
116
+ *
117
+ * By default, the underlying array is a `Uint8Array`, though this can be configured via [[UintArrayBuilderOptions.initialType]].
118
+ * As values are added to the array, if the bytes per element supported by the underlying array is too small to hold one of the new values, the array is
119
+ * reallocated to a type large enough to hold all of the new values. For example, the following produces a `Uint8Array` because all values are less than 256:
120
+ *
121
+ * ```ts
122
+ * const builder = new UintArrayBuilder();
123
+ * builder.append([1, 2, 254, 255]);
124
+ * const array = builder.toTypedArray();
125
+ * assert(array instanceof Uint8Array);
126
+ * ```
127
+ *
128
+ * However, the following produces a `Uint16Array` because one of the values is larger than 255 but none are larger than 65,535:
129
+ *
130
+ * ```ts
131
+ * const builder = new UintArrayBuilder();
132
+ * builder.append([1, 255, 257, 65535]);
133
+ * const array = builder.toTypedArray();
134
+ * assert(array instanceof Uint16Array);
135
+ * ```
136
+ *
137
+ * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], or [[Uint32ArrayBuilder]] if you know the number of bytes you want to allocate for each element in the array.
138
+ * @public
139
+ */
140
+ export declare class UintArrayBuilder extends TypedArrayBuilder<UintArray> {
141
+ constructor(options?: UintArrayBuilderOptions);
142
+ /** The number of bytes (1, 2, or 4) currently allocated per element by the underlying array.
143
+ * This may change as larger values are added to the array.
144
+ */
145
+ get bytesPerElement(): number;
146
+ /** Ensures that the underlying array is of a type that can contain the largest value in `newValues`.
147
+ * For example, if `_data` is a `Uint16Array` and `newValues` contains any value(s) larger than 65,535, it will be replaced with a `Uint32Array`.
148
+ * This method is invoked by [[push]] and [[append]].
149
+ */
150
+ protected ensureBytesPerElement(newValues: Iterable<number>): void;
151
+ /** See [[TypedArrayBuilder.push]]. */
152
+ push(value: number): void;
153
+ /** See [[TypedArrayBuilder.append]]. */
154
+ append(values: UintArray): void;
155
+ }
98
156
  //# sourceMappingURL=TypedArrayBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypedArrayBuilder.d.ts","sourceRoot":"","sources":["../../src/TypedArrayBuilder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,WAAW,GAAG,WAAW;IAC7E,sEAAsE;IACtE,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAChD,8FAA8F;IAC9F,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IACnB,wDAAwD;IACxD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,qEAAqE;IACrE,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,sFAAsF;IACtF,SAAS,aAAa,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAOrF,qDAAqD;IACrD,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,6FAA6F;IAC7F,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED;;;OAGG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAShC;;;;;;;OAOG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAclD,yDAAyD;IAClD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMhC,uEAAuE;IAChE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAO9B;;;OAGG;IACI,YAAY,CAAC,qBAAqB,UAAQ,GAAG,CAAC;CAStD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IAClE,8CAA8C;gBAC3B,OAAO,CAAC,EAAE,wBAAwB;CAGtD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IACpE,8CAA8C;gBAC3B,OAAO,CAAC,EAAE,wBAAwB;CAGtD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IACpE,8CAA8C;gBAC3B,OAAO,CAAC,EAAE,wBAAwB;IAIrD,gEAAgE;IACzD,YAAY,CAAC,qBAAqB,UAAQ,GAAG,UAAU;CAM/D"}
1
+ {"version":3,"file":"TypedArrayBuilder.d.ts","sourceRoot":"","sources":["../../src/TypedArrayBuilder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,oBAAY,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,SAAS;IAChD,sEAAsE;IACtE,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvC,8FAA8F;IAC9F,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IACnB,wDAAwD;IACxD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,qEAAqE;IACrE,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,sFAAsF;IACtF,SAAS,aAAa,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAOrF,qDAAqD;IACrD,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,6FAA6F;IAC7F,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED;;;OAGG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAShC;;;;;;;OAOG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAclD,yDAAyD;IAClD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMhC,uEAAuE;IAChE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAO9B;;;OAGG;IACI,YAAY,CAAC,qBAAqB,UAAQ,GAAG,CAAC;CAStD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IAClE,6CAA6C;gBAC1B,OAAO,CAAC,EAAE,wBAAwB;CAGtD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IACpE,6CAA6C;gBAC1B,OAAO,CAAC,EAAE,wBAAwB;CAGtD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IACpE,6CAA6C;gBAC1B,OAAO,CAAC,EAAE,wBAAwB;IAIrD,gEAAgE;IACzD,YAAY,CAAC,qBAAqB,UAAQ,GAAG,UAAU;CAM/D;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,UAAU,GAAG,OAAO,WAAW,GAAG,OAAO,WAAW,CAAC;CAC3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,SAAS,CAAC;gBAC7C,OAAO,CAAC,EAAE,uBAAuB;IAIpD;;OAEG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;;OAGG;IACH,SAAS,CAAC,qBAAqB,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;IAuBlE,sCAAsC;IACtB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKzC,wCAAwC;IACxB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;CAIhD"}
@@ -1,128 +1,201 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module Collections
7
- */
8
- import { assert } from "./Assert";
9
- /** Incrementally builds a [TypedArray] of unsigned 8-, 16-, or 32-bit integers.
10
- * Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.
11
- * `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.
12
- *
13
- * `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two "size" properties":
14
- * - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and
15
- * - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].
16
- * When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.
17
- *
18
- * Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].
19
- * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.
20
- * @public
21
- */
22
- export class TypedArrayBuilder {
23
- /** Constructs a new builder from the specified options, with a [[length]] of zero. */
24
- constructor(constructor, options) {
25
- var _a, _b;
26
- this._constructor = constructor;
27
- this._data = new constructor((_a = options === null || options === void 0 ? void 0 : options.initialCapacity) !== null && _a !== void 0 ? _a : 0);
28
- this.growthFactor = Math.max(1.0, (_b = options === null || options === void 0 ? void 0 : options.growthFactor) !== null && _b !== void 0 ? _b : 1.5);
29
- this._length = 0;
30
- }
31
- /** The number of elements currently in the array. */
32
- get length() {
33
- return this._length;
34
- }
35
- /** The number of elements that can fit into the memory currently allocated for the array. */
36
- get capacity() {
37
- return this._data.length;
38
- }
39
- /** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),
40
- * returns the element at the specified index, with negative integers counting back from the end of the array.
41
- * @note It is your responsibility to ensure the index falls within the bounds of the array.
42
- */
43
- at(index) {
44
- if (index < 0)
45
- index = this.length - index;
46
- const value = this._data[index];
47
- assert(value !== undefined, "index out of bounds");
48
- return value;
49
- }
50
- /** Ensure that [[capacity]] is at least equal to `newCapacity`.
51
- * This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.
52
- * It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
53
- *
54
- * If `newCapacity` is not greater than the current [[capacity]], this function does nothing.
55
- * Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.
56
- * [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.
57
- */
58
- ensureCapacity(newCapacity) {
59
- if (this.capacity >= newCapacity)
60
- return this.capacity;
61
- assert(this.growthFactor >= 1.0);
62
- newCapacity = Math.ceil(newCapacity * this.growthFactor);
63
- const prevData = this._data;
64
- this._data = new this._constructor(newCapacity);
65
- this._data.set(prevData, 0);
66
- assert(this.capacity === newCapacity);
67
- return this.capacity;
68
- }
69
- /** Append the specified value, resizing if necessary. */
70
- push(value) {
71
- this.ensureCapacity(this.length + 1);
72
- this._data[this.length] = value;
73
- ++this._length;
74
- }
75
- /** Append an array of values, resizing (at most once) if necessary. */
76
- append(values) {
77
- const newLength = this.length + values.length;
78
- this.ensureCapacity(newLength);
79
- this._data.set(values, this.length);
80
- this._length = newLength;
81
- }
82
- /** Obtain the finished array.
83
- * @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the
84
- * returned array's length will be equal to [[length]].
85
- */
86
- toTypedArray(includeUnusedCapacity = false) {
87
- if (includeUnusedCapacity)
88
- return this._data;
89
- const subarray = this._data.subarray(0, this.length);
90
- assert(subarray instanceof this._constructor);
91
- assert(subarray.buffer === this._data.buffer);
92
- return subarray;
93
- }
94
- }
95
- /** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
96
- * @public
97
- */
98
- export class Uint8ArrayBuilder extends TypedArrayBuilder {
99
- /** @see [[TypedArrayBuilder]] constructor. */
100
- constructor(options) {
101
- super(Uint8Array, options);
102
- }
103
- }
104
- /** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).
105
- * @public
106
- */
107
- export class Uint16ArrayBuilder extends TypedArrayBuilder {
108
- /** @see [[TypedArrayBuilder]] constructor. */
109
- constructor(options) {
110
- super(Uint16Array, options);
111
- }
112
- }
113
- /** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).
114
- * @public
115
- */
116
- export class Uint32ArrayBuilder extends TypedArrayBuilder {
117
- /** @see [[TypedArrayBuilder]] constructor. */
118
- constructor(options) {
119
- super(Uint32Array, options);
120
- }
121
- /** Obtain a view of the finished array as an array of bytes. */
122
- toUint8Array(includeUnusedCapacity = false) {
123
- if (includeUnusedCapacity)
124
- return new Uint8Array(this._data.buffer);
125
- return new Uint8Array(this._data.buffer, 0, this.length * 4);
126
- }
127
- }
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Collections
7
+ */
8
+ import { assert } from "./Assert";
9
+ /** Incrementally builds a [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) of unsigned 8-, 16-, or 32-bit integers.
10
+ * Sometimes you wish to populate a `TypedArray`, but you don't know how many elements you will need.
11
+ * `TypedArray` requires you to specify the size upon construction, and does not permit you to change the size later.
12
+ *
13
+ * `TypedArrayBuilder` manages a `TypedArray`, permitting you to [[push]] and [[append]] elements to it. It exposes two "size" properties":
14
+ * - [[capacity]], the number of elements it has currently allocated space for - i.e., the length of the underlying TypedArray; and
15
+ * - [[length]], the number of elements that have so far been added to it, which is never bigger than [[capacity]].
16
+ * When [[capacity]] is exceeded, a new, bigger TypedArray is allocated and the contents of the previous array are copied over to it.
17
+ *
18
+ * Once you've finished adding elements, you can obtain the finished `TypedArray` via [[toTypedArray]].
19
+ * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], and [[Uint32ArrayBuilder]] to build specific types of arrays.
20
+ * @see [[UintArrayBuilder]] when you don't know the maximum number of bytes required for each element in the array.
21
+ * @public
22
+ */
23
+ export class TypedArrayBuilder {
24
+ /** Constructs a new builder from the specified options, with a [[length]] of zero. */
25
+ constructor(constructor, options) {
26
+ var _a, _b;
27
+ this._constructor = constructor;
28
+ this._data = new constructor((_a = options === null || options === void 0 ? void 0 : options.initialCapacity) !== null && _a !== void 0 ? _a : 0);
29
+ this.growthFactor = Math.max(1.0, (_b = options === null || options === void 0 ? void 0 : options.growthFactor) !== null && _b !== void 0 ? _b : 1.5);
30
+ this._length = 0;
31
+ }
32
+ /** The number of elements currently in the array. */
33
+ get length() {
34
+ return this._length;
35
+ }
36
+ /** The number of elements that can fit into the memory currently allocated for the array. */
37
+ get capacity() {
38
+ return this._data.length;
39
+ }
40
+ /** Like [TypedArray.at](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at),
41
+ * returns the element at the specified index, with negative integers counting back from the end of the array.
42
+ * @note It is your responsibility to ensure the index falls within the bounds of the array.
43
+ */
44
+ at(index) {
45
+ if (index < 0)
46
+ index = this.length - index;
47
+ const value = this._data[index];
48
+ assert(value !== undefined, "index out of bounds");
49
+ return value;
50
+ }
51
+ /** Ensure that [[capacity]] is at least equal to `newCapacity`.
52
+ * This is used internally by methods like [[push]] and [[append]] to ensure the array has room for the element(s) to be added.
53
+ * It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
54
+ *
55
+ * If `newCapacity` is not greater than the current [[capacity]], this function does nothing.
56
+ * Otherwise, it allocates a new `TypedArray` with room for `newCapacity * growthFactor` elements, and copies the contents of the previous `TypedArray` into it.
57
+ * [[length]] remains unchanged; [[capacity]] reflects the size of the new TypeArray.
58
+ */
59
+ ensureCapacity(newCapacity) {
60
+ if (this.capacity >= newCapacity)
61
+ return this.capacity;
62
+ assert(this.growthFactor >= 1.0);
63
+ newCapacity = Math.ceil(newCapacity * this.growthFactor);
64
+ const prevData = this._data;
65
+ this._data = new this._constructor(newCapacity);
66
+ this._data.set(prevData, 0);
67
+ assert(this.capacity === newCapacity);
68
+ return this.capacity;
69
+ }
70
+ /** Append the specified value, resizing if necessary. */
71
+ push(value) {
72
+ this.ensureCapacity(this.length + 1);
73
+ this._data[this.length] = value;
74
+ ++this._length;
75
+ }
76
+ /** Append an array of values, resizing (at most once) if necessary. */
77
+ append(values) {
78
+ const newLength = this.length + values.length;
79
+ this.ensureCapacity(newLength);
80
+ this._data.set(values, this.length);
81
+ this._length = newLength;
82
+ }
83
+ /** Obtain the finished array.
84
+ * @param includeUnusedCapacity If true, the length of the returned array will be equal to [[capacity]], with extra bytes initialized to zero; otherwise, the
85
+ * returned array's length will be equal to [[length]].
86
+ */
87
+ toTypedArray(includeUnusedCapacity = false) {
88
+ if (includeUnusedCapacity)
89
+ return this._data;
90
+ const subarray = this._data.subarray(0, this.length);
91
+ assert(subarray instanceof this._constructor);
92
+ assert(subarray.buffer === this._data.buffer);
93
+ return subarray;
94
+ }
95
+ }
96
+ /** A [[TypedArrayBuilder]] for producing a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
97
+ * @public
98
+ */
99
+ export class Uint8ArrayBuilder extends TypedArrayBuilder {
100
+ /** See [[TypedArrayBuilder]] constructor. */
101
+ constructor(options) {
102
+ super(Uint8Array, options);
103
+ }
104
+ }
105
+ /** A [[TypedArrayBuilder]] for producing a [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array).
106
+ * @public
107
+ */
108
+ export class Uint16ArrayBuilder extends TypedArrayBuilder {
109
+ /** See [[TypedArrayBuilder]] constructor. */
110
+ constructor(options) {
111
+ super(Uint16Array, options);
112
+ }
113
+ }
114
+ /** A [[TypedArrayBuilder]] for producing a [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array).
115
+ * @public
116
+ */
117
+ export class Uint32ArrayBuilder extends TypedArrayBuilder {
118
+ /** See [[TypedArrayBuilder]] constructor. */
119
+ constructor(options) {
120
+ super(Uint32Array, options);
121
+ }
122
+ /** Obtain a view of the finished array as an array of bytes. */
123
+ toUint8Array(includeUnusedCapacity = false) {
124
+ if (includeUnusedCapacity)
125
+ return new Uint8Array(this._data.buffer);
126
+ return new Uint8Array(this._data.buffer, 0, this.length * 4);
127
+ }
128
+ }
129
+ /** A [[TypedArrayBuilder]] that can populate a [[UintArray]] with the minimum
130
+ * [bytes per element](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT) required.
131
+ *
132
+ * By default, the underlying array is a `Uint8Array`, though this can be configured via [[UintArrayBuilderOptions.initialType]].
133
+ * As values are added to the array, if the bytes per element supported by the underlying array is too small to hold one of the new values, the array is
134
+ * reallocated to a type large enough to hold all of the new values. For example, the following produces a `Uint8Array` because all values are less than 256:
135
+ *
136
+ * ```ts
137
+ * const builder = new UintArrayBuilder();
138
+ * builder.append([1, 2, 254, 255]);
139
+ * const array = builder.toTypedArray();
140
+ * assert(array instanceof Uint8Array);
141
+ * ```
142
+ *
143
+ * However, the following produces a `Uint16Array` because one of the values is larger than 255 but none are larger than 65,535:
144
+ *
145
+ * ```ts
146
+ * const builder = new UintArrayBuilder();
147
+ * builder.append([1, 255, 257, 65535]);
148
+ * const array = builder.toTypedArray();
149
+ * assert(array instanceof Uint16Array);
150
+ * ```
151
+ *
152
+ * @see [[Uint8ArrayBuilder]], [[Uint16ArrayBuilder]], or [[Uint32ArrayBuilder]] if you know the number of bytes you want to allocate for each element in the array.
153
+ * @public
154
+ */
155
+ export class UintArrayBuilder extends TypedArrayBuilder {
156
+ constructor(options) {
157
+ var _a;
158
+ super((_a = options === null || options === void 0 ? void 0 : options.initialType) !== null && _a !== void 0 ? _a : Uint8Array, options);
159
+ }
160
+ /** The number of bytes (1, 2, or 4) currently allocated per element by the underlying array.
161
+ * This may change as larger values are added to the array.
162
+ */
163
+ get bytesPerElement() {
164
+ return this._data.BYTES_PER_ELEMENT;
165
+ }
166
+ /** Ensures that the underlying array is of a type that can contain the largest value in `newValues`.
167
+ * For example, if `_data` is a `Uint16Array` and `newValues` contains any value(s) larger than 65,535, it will be replaced with a `Uint32Array`.
168
+ * This method is invoked by [[push]] and [[append]].
169
+ */
170
+ ensureBytesPerElement(newValues) {
171
+ const curBytesPerElem = this.bytesPerElement;
172
+ assert(curBytesPerElem === 1 || curBytesPerElem === 2 || curBytesPerElem === 4);
173
+ if (curBytesPerElem >= 4)
174
+ return;
175
+ let neededBytesPerElem = curBytesPerElem;
176
+ for (const value of newValues) {
177
+ if (value > 0xffff) {
178
+ neededBytesPerElem = 4;
179
+ break;
180
+ }
181
+ else if (value > 0xff) {
182
+ neededBytesPerElem = 2;
183
+ }
184
+ }
185
+ if (neededBytesPerElem <= curBytesPerElem)
186
+ return;
187
+ this._constructor = neededBytesPerElem === 1 ? Uint8Array : (neededBytesPerElem === 2 ? Uint16Array : Uint32Array);
188
+ this._data = new this._constructor(this._data);
189
+ }
190
+ /** See [[TypedArrayBuilder.push]]. */
191
+ push(value) {
192
+ this.ensureBytesPerElement([value]);
193
+ super.push(value);
194
+ }
195
+ /** See [[TypedArrayBuilder.append]]. */
196
+ append(values) {
197
+ this.ensureBytesPerElement(values);
198
+ super.append(values);
199
+ }
200
+ }
128
201
  //# sourceMappingURL=TypedArrayBuilder.js.map