@itwin/core-bentley 4.0.0-dev.52 → 4.0.0-dev.54

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 (249) hide show
  1. package/lib/cjs/AccessToken.d.ts +10 -10
  2. package/lib/cjs/AccessToken.d.ts.map +1 -1
  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/BeEvent.d.ts +81 -81
  9. package/lib/cjs/BeEvent.d.ts.map +1 -1
  10. package/lib/cjs/BeEvent.js +156 -156
  11. package/lib/cjs/BeEvent.js.map +1 -1
  12. package/lib/cjs/BeSQLite.d.ts +172 -172
  13. package/lib/cjs/BeSQLite.js +185 -185
  14. package/lib/cjs/BeSQLite.js.map +1 -1
  15. package/lib/cjs/BentleyError.d.ts +378 -378
  16. package/lib/cjs/BentleyError.d.ts.map +1 -1
  17. package/lib/cjs/BentleyError.js +703 -703
  18. package/lib/cjs/BentleyError.js.map +1 -1
  19. package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
  20. package/lib/cjs/BentleyLoggerCategory.js +19 -19
  21. package/lib/cjs/BentleyLoggerCategory.js.map +1 -1
  22. package/lib/cjs/ByteStream.d.ts +110 -110
  23. package/lib/cjs/ByteStream.js +159 -159
  24. package/lib/cjs/ByteStream.js.map +1 -1
  25. package/lib/cjs/ClassUtils.d.ts +14 -14
  26. package/lib/cjs/ClassUtils.js +27 -27
  27. package/lib/cjs/ClassUtils.js.map +1 -1
  28. package/lib/cjs/Compare.d.ts +47 -47
  29. package/lib/cjs/Compare.d.ts.map +1 -1
  30. package/lib/cjs/Compare.js +75 -75
  31. package/lib/cjs/Compare.js.map +1 -1
  32. package/lib/cjs/CompressedId64Set.d.ts +134 -134
  33. package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
  34. package/lib/cjs/CompressedId64Set.js +428 -428
  35. package/lib/cjs/CompressedId64Set.js.map +1 -1
  36. package/lib/cjs/Dictionary.d.ts +125 -125
  37. package/lib/cjs/Dictionary.js +203 -203
  38. package/lib/cjs/Dictionary.js.map +1 -1
  39. package/lib/cjs/Disposable.d.ts +80 -80
  40. package/lib/cjs/Disposable.d.ts.map +1 -1
  41. package/lib/cjs/Disposable.js +120 -120
  42. package/lib/cjs/Disposable.js.map +1 -1
  43. package/lib/cjs/Id.d.ts +285 -285
  44. package/lib/cjs/Id.d.ts.map +1 -1
  45. package/lib/cjs/Id.js +643 -643
  46. package/lib/cjs/Id.js.map +1 -1
  47. package/lib/cjs/IndexMap.d.ts +65 -65
  48. package/lib/cjs/IndexMap.js +91 -91
  49. package/lib/cjs/IndexMap.js.map +1 -1
  50. package/lib/cjs/JsonSchema.d.ts +77 -77
  51. package/lib/cjs/JsonSchema.d.ts.map +1 -1
  52. package/lib/cjs/JsonSchema.js +9 -9
  53. package/lib/cjs/JsonSchema.js.map +1 -1
  54. package/lib/cjs/JsonUtils.d.ts +78 -78
  55. package/lib/cjs/JsonUtils.js +151 -151
  56. package/lib/cjs/JsonUtils.js.map +1 -1
  57. package/lib/cjs/LRUMap.d.ts +129 -129
  58. package/lib/cjs/LRUMap.js +333 -333
  59. package/lib/cjs/LRUMap.js.map +1 -1
  60. package/lib/cjs/Logger.d.ts +143 -143
  61. package/lib/cjs/Logger.d.ts.map +1 -1
  62. package/lib/cjs/Logger.js +256 -256
  63. package/lib/cjs/Logger.js.map +1 -1
  64. package/lib/cjs/ObservableSet.d.ts +23 -23
  65. package/lib/cjs/ObservableSet.js +51 -51
  66. package/lib/cjs/ObservableSet.js.map +1 -1
  67. package/lib/cjs/OneAtATimeAction.d.ts +31 -31
  68. package/lib/cjs/OneAtATimeAction.js +94 -94
  69. package/lib/cjs/OneAtATimeAction.js.map +1 -1
  70. package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
  71. package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
  72. package/lib/cjs/OrderedId64Iterable.js +235 -235
  73. package/lib/cjs/OrderedId64Iterable.js.map +1 -1
  74. package/lib/cjs/OrderedSet.d.ts +40 -40
  75. package/lib/cjs/OrderedSet.js +64 -64
  76. package/lib/cjs/OrderedSet.js.map +1 -1
  77. package/lib/cjs/PriorityQueue.d.ts +70 -70
  78. package/lib/cjs/PriorityQueue.d.ts.map +1 -1
  79. package/lib/cjs/PriorityQueue.js +140 -140
  80. package/lib/cjs/PriorityQueue.js.map +1 -1
  81. package/lib/cjs/ProcessDetector.d.ts +59 -59
  82. package/lib/cjs/ProcessDetector.js +71 -71
  83. package/lib/cjs/ProcessDetector.js.map +1 -1
  84. package/lib/cjs/SortedArray.d.ts +236 -236
  85. package/lib/cjs/SortedArray.d.ts.map +1 -1
  86. package/lib/cjs/SortedArray.js +315 -315
  87. package/lib/cjs/SortedArray.js.map +1 -1
  88. package/lib/cjs/StatusCategory.d.ts +30 -30
  89. package/lib/cjs/StatusCategory.d.ts.map +1 -1
  90. package/lib/cjs/StatusCategory.js +460 -460
  91. package/lib/cjs/StatusCategory.js.map +1 -1
  92. package/lib/cjs/StringUtils.d.ts +22 -22
  93. package/lib/cjs/StringUtils.js +148 -148
  94. package/lib/cjs/StringUtils.js.map +1 -1
  95. package/lib/cjs/Time.d.ts +122 -122
  96. package/lib/cjs/Time.js +152 -152
  97. package/lib/cjs/Time.js.map +1 -1
  98. package/lib/cjs/Tracing.d.ts +40 -40
  99. package/lib/cjs/Tracing.js +127 -127
  100. package/lib/cjs/Tracing.js.map +1 -1
  101. package/lib/cjs/TupleKeyedMap.d.ts +36 -36
  102. package/lib/cjs/TupleKeyedMap.js +102 -102
  103. package/lib/cjs/TupleKeyedMap.js.map +1 -1
  104. package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
  105. package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
  106. package/lib/cjs/TypedArrayBuilder.js +206 -206
  107. package/lib/cjs/TypedArrayBuilder.js.map +1 -1
  108. package/lib/cjs/UnexpectedErrors.d.ts +43 -43
  109. package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
  110. package/lib/cjs/UnexpectedErrors.js +68 -68
  111. package/lib/cjs/UnexpectedErrors.js.map +1 -1
  112. package/lib/cjs/UtilityTypes.d.ts +112 -112
  113. package/lib/cjs/UtilityTypes.d.ts.map +1 -1
  114. package/lib/cjs/UtilityTypes.js +40 -40
  115. package/lib/cjs/UtilityTypes.js.map +1 -1
  116. package/lib/cjs/YieldManager.d.ts +18 -18
  117. package/lib/cjs/YieldManager.js +34 -34
  118. package/lib/cjs/YieldManager.js.map +1 -1
  119. package/lib/cjs/core-bentley.d.ts +74 -74
  120. package/lib/cjs/core-bentley.js +94 -90
  121. package/lib/cjs/core-bentley.js.map +1 -1
  122. package/lib/cjs/partitionArray.d.ts +21 -21
  123. package/lib/cjs/partitionArray.js +43 -43
  124. package/lib/cjs/partitionArray.js.map +1 -1
  125. package/lib/esm/AccessToken.d.ts +10 -10
  126. package/lib/esm/AccessToken.d.ts.map +1 -1
  127. package/lib/esm/AccessToken.js +8 -8
  128. package/lib/esm/AccessToken.js.map +1 -1
  129. package/lib/esm/Assert.d.ts +25 -25
  130. package/lib/esm/Assert.js +41 -41
  131. package/lib/esm/Assert.js.map +1 -1
  132. package/lib/esm/BeEvent.d.ts +81 -81
  133. package/lib/esm/BeEvent.d.ts.map +1 -1
  134. package/lib/esm/BeEvent.js +150 -150
  135. package/lib/esm/BeEvent.js.map +1 -1
  136. package/lib/esm/BeSQLite.d.ts +172 -172
  137. package/lib/esm/BeSQLite.js +182 -182
  138. package/lib/esm/BeSQLite.js.map +1 -1
  139. package/lib/esm/BentleyError.d.ts +378 -378
  140. package/lib/esm/BentleyError.d.ts.map +1 -1
  141. package/lib/esm/BentleyError.js +699 -699
  142. package/lib/esm/BentleyError.js.map +1 -1
  143. package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
  144. package/lib/esm/BentleyLoggerCategory.js +16 -16
  145. package/lib/esm/BentleyLoggerCategory.js.map +1 -1
  146. package/lib/esm/ByteStream.d.ts +110 -110
  147. package/lib/esm/ByteStream.js +155 -155
  148. package/lib/esm/ByteStream.js.map +1 -1
  149. package/lib/esm/ClassUtils.d.ts +14 -14
  150. package/lib/esm/ClassUtils.js +22 -22
  151. package/lib/esm/ClassUtils.js.map +1 -1
  152. package/lib/esm/Compare.d.ts +47 -47
  153. package/lib/esm/Compare.d.ts.map +1 -1
  154. package/lib/esm/Compare.js +63 -63
  155. package/lib/esm/Compare.js.map +1 -1
  156. package/lib/esm/CompressedId64Set.d.ts +134 -134
  157. package/lib/esm/CompressedId64Set.d.ts.map +1 -1
  158. package/lib/esm/CompressedId64Set.js +423 -423
  159. package/lib/esm/CompressedId64Set.js.map +1 -1
  160. package/lib/esm/Dictionary.d.ts +125 -125
  161. package/lib/esm/Dictionary.js +199 -199
  162. package/lib/esm/Dictionary.js.map +1 -1
  163. package/lib/esm/Disposable.d.ts +80 -80
  164. package/lib/esm/Disposable.d.ts.map +1 -1
  165. package/lib/esm/Disposable.js +112 -112
  166. package/lib/esm/Disposable.js.map +1 -1
  167. package/lib/esm/Id.d.ts +285 -285
  168. package/lib/esm/Id.d.ts.map +1 -1
  169. package/lib/esm/Id.js +639 -639
  170. package/lib/esm/Id.js.map +1 -1
  171. package/lib/esm/IndexMap.d.ts +65 -65
  172. package/lib/esm/IndexMap.js +86 -86
  173. package/lib/esm/IndexMap.js.map +1 -1
  174. package/lib/esm/JsonSchema.d.ts +77 -77
  175. package/lib/esm/JsonSchema.d.ts.map +1 -1
  176. package/lib/esm/JsonSchema.js +8 -8
  177. package/lib/esm/JsonSchema.js.map +1 -1
  178. package/lib/esm/JsonUtils.d.ts +78 -78
  179. package/lib/esm/JsonUtils.js +148 -148
  180. package/lib/esm/JsonUtils.js.map +1 -1
  181. package/lib/esm/LRUMap.d.ts +129 -129
  182. package/lib/esm/LRUMap.js +326 -326
  183. package/lib/esm/LRUMap.js.map +1 -1
  184. package/lib/esm/Logger.d.ts +143 -143
  185. package/lib/esm/Logger.d.ts.map +1 -1
  186. package/lib/esm/Logger.js +253 -251
  187. package/lib/esm/Logger.js.map +1 -1
  188. package/lib/esm/ObservableSet.d.ts +23 -23
  189. package/lib/esm/ObservableSet.js +47 -47
  190. package/lib/esm/ObservableSet.js.map +1 -1
  191. package/lib/esm/OneAtATimeAction.d.ts +31 -31
  192. package/lib/esm/OneAtATimeAction.js +89 -89
  193. package/lib/esm/OneAtATimeAction.js.map +1 -1
  194. package/lib/esm/OrderedId64Iterable.d.ts +74 -74
  195. package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
  196. package/lib/esm/OrderedId64Iterable.js +232 -232
  197. package/lib/esm/OrderedId64Iterable.js.map +1 -1
  198. package/lib/esm/OrderedSet.d.ts +40 -40
  199. package/lib/esm/OrderedSet.js +59 -59
  200. package/lib/esm/OrderedSet.js.map +1 -1
  201. package/lib/esm/PriorityQueue.d.ts +70 -70
  202. package/lib/esm/PriorityQueue.d.ts.map +1 -1
  203. package/lib/esm/PriorityQueue.js +136 -136
  204. package/lib/esm/PriorityQueue.js.map +1 -1
  205. package/lib/esm/ProcessDetector.d.ts +59 -59
  206. package/lib/esm/ProcessDetector.js +67 -67
  207. package/lib/esm/ProcessDetector.js.map +1 -1
  208. package/lib/esm/SortedArray.d.ts +236 -236
  209. package/lib/esm/SortedArray.d.ts.map +1 -1
  210. package/lib/esm/SortedArray.js +308 -308
  211. package/lib/esm/SortedArray.js.map +1 -1
  212. package/lib/esm/StatusCategory.d.ts +30 -30
  213. package/lib/esm/StatusCategory.d.ts.map +1 -1
  214. package/lib/esm/StatusCategory.js +455 -454
  215. package/lib/esm/StatusCategory.js.map +1 -1
  216. package/lib/esm/StringUtils.d.ts +22 -22
  217. package/lib/esm/StringUtils.js +142 -142
  218. package/lib/esm/StringUtils.js.map +1 -1
  219. package/lib/esm/Time.d.ts +122 -122
  220. package/lib/esm/Time.js +146 -146
  221. package/lib/esm/Time.js.map +1 -1
  222. package/lib/esm/Tracing.d.ts +40 -40
  223. package/lib/esm/Tracing.js +123 -123
  224. package/lib/esm/Tracing.js.map +1 -1
  225. package/lib/esm/TupleKeyedMap.d.ts +36 -36
  226. package/lib/esm/TupleKeyedMap.js +98 -98
  227. package/lib/esm/TupleKeyedMap.js.map +1 -1
  228. package/lib/esm/TypedArrayBuilder.d.ts +155 -155
  229. package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
  230. package/lib/esm/TypedArrayBuilder.js +198 -198
  231. package/lib/esm/TypedArrayBuilder.js.map +1 -1
  232. package/lib/esm/UnexpectedErrors.d.ts +43 -43
  233. package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
  234. package/lib/esm/UnexpectedErrors.js +65 -64
  235. package/lib/esm/UnexpectedErrors.js.map +1 -1
  236. package/lib/esm/UtilityTypes.d.ts +112 -112
  237. package/lib/esm/UtilityTypes.d.ts.map +1 -1
  238. package/lib/esm/UtilityTypes.js +34 -34
  239. package/lib/esm/UtilityTypes.js.map +1 -1
  240. package/lib/esm/YieldManager.d.ts +18 -18
  241. package/lib/esm/YieldManager.js +30 -30
  242. package/lib/esm/YieldManager.js.map +1 -1
  243. package/lib/esm/core-bentley.d.ts +74 -74
  244. package/lib/esm/core-bentley.js +78 -78
  245. package/lib/esm/core-bentley.js.map +1 -1
  246. package/lib/esm/partitionArray.d.ts +21 -21
  247. package/lib/esm/partitionArray.js +39 -39
  248. package/lib/esm/partitionArray.js.map +1 -1
  249. package/package.json +4 -4
@@ -1,424 +1,424 @@
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 Ids
7
- */
8
- import { assert } from "./Assert";
9
- import { Id64 } from "./Id";
10
- import { OrderedId64Iterable } from "./OrderedId64Iterable";
11
- import { SortedArray } from "./SortedArray";
12
- /** A compact string representation of an [[Id64Set]]. Such a representation is useful when serializing potentially very large
13
- * sets of Ids.
14
- * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids represented by a compact string.
15
- * @see [[CompressedId64Set.compressSet]] and [[CompressedId64Set.compressArray]] to produce a compact string from a collection of Ids.
16
- * @see [[CompressedId64Set.decompressSet]] and [[CompressedId64Set.decompressArray]] to produce a collection of Ids from a compact string.
17
- * @see [[OrderedId64Iterable]] for a generic representation of an ordered set of Ids (compressed or otherwise).
18
- * @see [[MutableCompressedId64Set]] for a mutable version.
19
- * @public
20
- */
21
- export var CompressedId64Set;
22
- (function (CompressedId64Set) {
23
- function isHexDigit(ch) {
24
- // ascii values:
25
- // '0' = 48
26
- // '9' = 57
27
- // 'a' = 65
28
- // 'f' = 70
29
- return (ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 70);
30
- }
31
- function compactRange(increment, length) {
32
- assert(length > 0);
33
- const inc = `+${increment.toString()}`;
34
- if (length <= 1)
35
- return inc;
36
- const len = length.toString(16).toUpperCase();
37
- return `${inc}*${len}`;
38
- }
39
- /** Given a set of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
40
- * @note Invalid Ids are ignored.
41
- * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
42
- * @see [[CompressedId64Set.compressArray]] to perform the same operation on an [[Id64Array]].
43
- * @see [[CompressedId64Set.decompressSet]] to perform the inverse operation.
44
- */
45
- function compressSet(ids) {
46
- return sortAndCompress(ids);
47
- }
48
- CompressedId64Set.compressSet = compressSet;
49
- /** Create a sorted array from `ids`, then return a compact string representation of those Ids.
50
- * @see [[compressIds]] if `ids` is known to already be sorted.
51
- */
52
- function sortAndCompress(ids) {
53
- // `string` is an Iterable<string>. In that case assume caller passed a single Id64String.
54
- const arr = typeof ids === "string" ? [ids] : Array.from(ids);
55
- OrderedId64Iterable.sortArray(arr);
56
- return compressArray(arr);
57
- }
58
- CompressedId64Set.sortAndCompress = sortAndCompress;
59
- /** Give a **numerically-ordered** array of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
60
- * Duplicate Ids are included only once in the string representation.
61
- * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the array is not properly sorted.
62
- * @note The array must be sorted according to the 64-bit numerical value of each Id.
63
- * @note Invalid Ids are ignored.
64
- * @see [[CompressedId64Set.decompressArray]] to perform the inverse operation.
65
- * @see [[OrderedId64Iterable.sortArray]] to ensure the Ids are properly sorted.
66
- * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
67
- */
68
- function compressArray(ids) {
69
- return compressIds(ids);
70
- }
71
- CompressedId64Set.compressArray = compressArray;
72
- /** Give a **numerically-ordered** collection of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
73
- * Duplicate Ids are included only once in the string representation.
74
- * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the collection is not properly sorted.
75
- * @note The collection must be sorted according to the 64-bit numerical value of each Id.
76
- * @note Invalid Ids are ignored.
77
- * @see [[CompressedId64Set.iterable]] to perform the inverse operation.
78
- * @see [[OrderedId64Iterable.sortArray]] or [[OrderedId64Iterable.compare]] to ensure the Ids are properly sorted.
79
- * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
80
- */
81
- function compressIds(ids) {
82
- if ("string" === typeof ids)
83
- return ids;
84
- let str = "";
85
- const prevId = new Uint64();
86
- const rangeIncrement = new Uint64();
87
- let rangeLen = 0;
88
- const curId = new Uint64();
89
- const curIncrement = new Uint64();
90
- for (const id of ids) {
91
- if (!Id64.isValidId64(id))
92
- continue; // ignore garbage and invalid Ids ("0")
93
- curId.setFromId(id);
94
- curIncrement.setFromDifference(curId, prevId);
95
- const cmp = prevId.compare(curId);
96
- if (0 === cmp)
97
- continue; // ignore duplicates
98
- else if (cmp > 0)
99
- throw new Error("CompressedId64Set.compressArray requires a sorted array as input");
100
- prevId.copyFrom(curId);
101
- if (0 === rangeLen) {
102
- rangeIncrement.copyFrom(curIncrement);
103
- rangeLen = 1;
104
- }
105
- else if (curIncrement.equals(rangeIncrement)) {
106
- ++rangeLen;
107
- }
108
- else {
109
- str += compactRange(rangeIncrement, rangeLen);
110
- rangeIncrement.copyFrom(curIncrement);
111
- rangeLen = 1;
112
- }
113
- }
114
- if (0 < rangeLen)
115
- str += compactRange(rangeIncrement, rangeLen);
116
- return str;
117
- }
118
- CompressedId64Set.compressIds = compressIds;
119
- /** This exists strictly for the purposes of compressed sets of 64-bit Ids, to avoid the overhead of BigInt for handling 64-bit integers. */
120
- class Uint64 {
121
- constructor(lower = 0, upper = 0) {
122
- this.lower = lower;
123
- this.upper = upper;
124
- this.assertConstraints();
125
- }
126
- static assertUint32(num) {
127
- assert(num >= 0);
128
- assert(num < Uint64._base);
129
- assert(Math.floor(num) === num);
130
- }
131
- assertConstraints() {
132
- Uint64.assertUint32(this.lower);
133
- Uint64.assertUint32(this.upper);
134
- }
135
- compare(rhs) {
136
- const diff = this.upper - rhs.upper;
137
- return 0 === diff ? this.lower - rhs.lower : diff;
138
- }
139
- equals(rhs) { return 0 === this.compare(rhs); }
140
- isLessThan(rhs) { return this.compare(rhs) < 0; }
141
- isGreaterThan(rhs) { return this.compare(rhs) > 0; }
142
- get isZero() { return 0 === this.lower && 0 === this.upper; }
143
- setFromDifference(lhs, rhs) {
144
- assert(!rhs.isGreaterThan(lhs));
145
- this.lower = lhs.lower - rhs.lower;
146
- this.upper = lhs.upper - rhs.upper;
147
- if (this.lower < 0) {
148
- this.lower += Uint64._base;
149
- this.upper -= 1;
150
- }
151
- }
152
- add(rhs) {
153
- let lower = rhs.lower;
154
- let upper = rhs.upper;
155
- if (lower + this.lower >= Uint64._base) {
156
- lower -= Uint64._base;
157
- upper += 1;
158
- }
159
- this.lower += lower;
160
- this.upper += upper;
161
- this.assertConstraints();
162
- }
163
- setFromId(id) {
164
- Id64.getUint32Pair(id, this);
165
- }
166
- copyFrom(other) {
167
- this.lower = other.lower;
168
- this.upper = other.upper;
169
- }
170
- toString() {
171
- if (0 === this.upper)
172
- return this.lower.toString(16).toUpperCase();
173
- const upper = this.upper.toString(16);
174
- const lower = this.lower.toString(16).padStart(8, "0");
175
- assert(lower.length === 8);
176
- return `${upper}${lower}`.toUpperCase();
177
- }
178
- toId64String() {
179
- return Id64.fromUint32Pair(this.lower, this.upper);
180
- }
181
- }
182
- Uint64._base = 0x100000000;
183
- /** Supplies an iterator over the [[Id64String]]s in a [[CompressedId64Set]].
184
- * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.
185
- */
186
- function* iterator(ids) {
187
- if (0 === ids.length)
188
- return; // empty set.
189
- if ("+" !== ids[0])
190
- throw new Error("Invalid CompressedId64Set");
191
- let curIndex = 1; // skip the leading '+'
192
- const curId = new Uint64();
193
- function parseUint32() {
194
- let value = 0;
195
- let nChars = 0;
196
- while (curIndex < ids.length && nChars < 8) {
197
- ++nChars;
198
- const ch = ids.charCodeAt(curIndex);
199
- if (!isHexDigit(ch))
200
- break; // not a hex digit in [0..9] or [A..F]
201
- value <<= 4;
202
- value |= (ch >= 65 ? ch - 65 + 10 : ch - 48); // ch - 'A' + 10 or ch - '0'
203
- value = value >>> 0; // restore unsignedness because silly javascript.
204
- ++curIndex;
205
- }
206
- return value;
207
- }
208
- function parseUint64(uint64) {
209
- let lower = 0;
210
- let upper = 0;
211
- // Read up to the first 8 digits.
212
- const startIndex = curIndex;
213
- const first = parseUint32();
214
- const nFirstDigits = curIndex - startIndex;
215
- assert(nFirstDigits <= 8);
216
- if (8 === nFirstDigits && curIndex + 1 < ids.length && isHexDigit(ids.charCodeAt(curIndex + 1))) {
217
- // We've got up to 8 more digits remaining
218
- const secondIndex = curIndex;
219
- const second = parseUint32();
220
- // Transfer excess digits from upper to lower.
221
- const nSecondDigits = curIndex - secondIndex;
222
- assert(nSecondDigits > 0 && nSecondDigits <= 8);
223
- const nDigitsToTransfer = 8 - nSecondDigits;
224
- upper = first >>> (4 * nDigitsToTransfer);
225
- const transfer = first - ((upper << (4 * nDigitsToTransfer)) >>> 0);
226
- lower = (second | ((transfer << (4 * nSecondDigits)) >>> 0)) >>> 0;
227
- }
228
- else {
229
- lower = first;
230
- }
231
- uint64.lower = lower;
232
- uint64.upper = upper;
233
- }
234
- const increment = new Uint64();
235
- while (curIndex < ids.length) {
236
- let multiplier = 1;
237
- parseUint64(increment);
238
- if (increment.isZero)
239
- throw new Error("Invalid CompressedId64Set");
240
- if (curIndex < ids.length) {
241
- switch (ids[curIndex++]) {
242
- case "*":
243
- multiplier = parseUint32();
244
- if (0 === multiplier)
245
- throw new Error("Invalid CompressedId64Set");
246
- if (curIndex !== ids.length && ids[curIndex++] !== "+")
247
- return;
248
- break;
249
- case "+":
250
- break;
251
- default:
252
- throw new Error("Invalid CompressedId64Set");
253
- }
254
- }
255
- for (let i = 0; i < multiplier; i++) {
256
- curId.add(increment);
257
- yield curId.toId64String();
258
- }
259
- }
260
- }
261
- CompressedId64Set.iterator = iterator;
262
- /** Supplies an iterable over the [[Id64String]]s in a [[CompressedId64Set]].
263
- * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.
264
- */
265
- function iterable(ids) {
266
- return {
267
- [Symbol.iterator]: () => iterator(ids),
268
- };
269
- }
270
- CompressedId64Set.iterable = iterable;
271
- /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Set]].
272
- * @param compressedIds The compact string representation.
273
- * @param out If supplied, the Ids will be inserted into this set rather than allocating and returning a new set.
274
- * @returns The set containing the decompressed Ids.
275
- * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].
276
- * @see [[CompressedId64Set.compressSet]] to perform the inverse operation.
277
- * @see [[CompressedId64Set.decompressArray]] to decompress as an [[Id64Array]] instead.
278
- * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.
279
- */
280
- function decompressSet(compressedIds, out) {
281
- const set = out ?? new Set();
282
- for (const id of iterable(compressedIds))
283
- set.add(id);
284
- return set;
285
- }
286
- CompressedId64Set.decompressSet = decompressSet;
287
- /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Array]].
288
- * @param compressedIds The compact string representation.
289
- * @param out If supplied, the Ids will be appended to this array rather than allocating and returning a new array.
290
- * @returns The array containing the decompressed Ids.
291
- * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].
292
- * @note The Ids are decompressed and appended to the array in ascending order based on their 64-bit numerical values.
293
- * @see [[CompressedId64Set.compressArray]] to perform the inverse operation.
294
- * @see [[CompressedId64Set.decompressSet]] to decompress as an [[Id64Set]] instead.
295
- * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.
296
- */
297
- function decompressArray(compressedIds, out) {
298
- const arr = out ?? [];
299
- for (const id of iterable(compressedIds))
300
- arr.push(id);
301
- return arr;
302
- }
303
- CompressedId64Set.decompressArray = decompressArray;
304
- })(CompressedId64Set || (CompressedId64Set = {}));
305
- /** A [[SortedArray]] of unique [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer values of the Ids.
306
- * @see [[CompressedId64Set]] for an immutable compact string representation.
307
- * @public
308
- */
309
- export class OrderedId64Array extends SortedArray {
310
- /** Construct a new, empty array. */
311
- constructor() {
312
- super((lhs, rhs) => OrderedId64Iterable.compare(lhs, rhs));
313
- }
314
- /** An iterable that iterates over the Ids in sorted order. */
315
- get ids() { return this._array; }
316
- /** The underlying array of Ids. */
317
- get array() { return this._array; }
318
- }
319
- /** A mutable set of valid [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer value of the Ids.
320
- * Internally the set of Ids is maintained as a [[CompressedId64Set]] string representation.
321
- * Insertions and removals are buffered until the string representation needs to be recomputed. The string representation is recomputed by every public method except [[add]] and [[delete]] -
322
- * therefore, if multiple removals and/or insertions are required, it is most efficient to perform them all before invoking other methods.
323
- * @public
324
- */
325
- export class MutableCompressedId64Set {
326
- /** Construct a new set, optionally initialized to contain the Ids represented by `ids`. */
327
- constructor(ids) {
328
- this._inserted = new OrderedId64Array();
329
- this._deleted = new OrderedId64Array();
330
- this._ids = ids ?? "";
331
- }
332
- /** Obtain the compact string representation of the contents of this set. If any insertions or removals are pending, they will be applied and the string recomputed. */
333
- get ids() {
334
- this.updateIds();
335
- return this._ids;
336
- }
337
- /** Add the specified Id to the set.
338
- * @throws Error if `id` is not a valid [[Id64String]].
339
- */
340
- add(id) {
341
- if (!Id64.isValidId64(id))
342
- throw new Error("MutableCompressedId64Set.add: invalid Id");
343
- this._deleted.remove(id);
344
- this._inserted.insert(id);
345
- }
346
- /** Remove the specified Id from the set.
347
- * @throws Error if `id` is not a valid [[Id64String]].
348
- */
349
- delete(id) {
350
- if (!Id64.isValidId64(id))
351
- throw new Error("MutableCompressedId64Set.delete: invalid Id");
352
- this._inserted.remove(id);
353
- this._deleted.insert(id);
354
- }
355
- /** Remove all Ids from the set. */
356
- clear() {
357
- this._ids = "";
358
- this._inserted.clear();
359
- this._deleted.clear();
360
- }
361
- /** Remove all Ids from the set, then add the specified Ids. */
362
- reset(ids) {
363
- this.clear();
364
- this._ids = ids ?? "";
365
- }
366
- /** Obtain an iterator over the Ids in this set. The Ids are returned in ascending order based on their unsigned 64-bit integer values. */
367
- [Symbol.iterator]() {
368
- return CompressedId64Set.iterator(this.ids);
369
- }
370
- /** Compute a compact string representation of the union of this and another set of Ids - i.e., those Ids present in either this and/or the other set. */
371
- computeUnion(ids) {
372
- if (this.isEmpty)
373
- return CompressedId64Set.compressIds(ids);
374
- else if (OrderedId64Iterable.isEmptySet(ids) || this.equals(ids))
375
- return this.ids;
376
- return CompressedId64Set.compressIds(OrderedId64Iterable.union(this, ids));
377
- }
378
- /** Compute a compact string representation of the intersection of this and another set of Ids - i.e., those Ids present in both this and the other set. */
379
- computeIntersection(ids) {
380
- if (this.equals(ids))
381
- return this.ids;
382
- else if (this.isEmpty || OrderedId64Iterable.isEmptySet(ids))
383
- return "";
384
- return CompressedId64Set.compressIds(OrderedId64Iterable.intersection(this, ids));
385
- }
386
- /** Compute a compact string representation of the difference between this and another set - i.e., those Ids present in this but not in the other set. */
387
- computeDifference(ids) {
388
- if (this.isEmpty || this.equals(ids))
389
- return "";
390
- return CompressedId64Set.compressIds(OrderedId64Iterable.difference(this, ids));
391
- }
392
- /** Return true if this set contains no Ids. */
393
- get isEmpty() {
394
- return OrderedId64Iterable.isEmptySet(this.ids);
395
- }
396
- /** Return true if the set of Ids represented by `other` is identical to those in this set.
397
- * @note This considers only the **distinct** Ids in `other` - duplicates are ignored.
398
- */
399
- equals(other) {
400
- if (other instanceof MutableCompressedId64Set) {
401
- if (other === this)
402
- return true;
403
- if (typeof other !== "string")
404
- other = other.ids;
405
- }
406
- if (typeof other === "string")
407
- return other === this.ids;
408
- this.updateIds();
409
- return OrderedId64Iterable.areEqualSets(this, other);
410
- }
411
- get _isDirty() {
412
- return !this._inserted.isEmpty || !this._deleted.isEmpty;
413
- }
414
- updateIds() {
415
- if (!this._isDirty)
416
- return;
417
- const difference = OrderedId64Iterable.difference(CompressedId64Set.iterable(this._ids), this._deleted.ids);
418
- const union = { [Symbol.iterator]: () => OrderedId64Iterable.unionIterator(difference, this._inserted.ids) };
419
- this._ids = CompressedId64Set.compressIds(union);
420
- this._inserted.clear();
421
- this._deleted.clear();
422
- }
423
- }
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 Ids
7
+ */
8
+ import { assert } from "./Assert";
9
+ import { Id64 } from "./Id";
10
+ import { OrderedId64Iterable } from "./OrderedId64Iterable";
11
+ import { SortedArray } from "./SortedArray";
12
+ /** A compact string representation of an [[Id64Set]]. Such a representation is useful when serializing potentially very large
13
+ * sets of Ids.
14
+ * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids represented by a compact string.
15
+ * @see [[CompressedId64Set.compressSet]] and [[CompressedId64Set.compressArray]] to produce a compact string from a collection of Ids.
16
+ * @see [[CompressedId64Set.decompressSet]] and [[CompressedId64Set.decompressArray]] to produce a collection of Ids from a compact string.
17
+ * @see [[OrderedId64Iterable]] for a generic representation of an ordered set of Ids (compressed or otherwise).
18
+ * @see [[MutableCompressedId64Set]] for a mutable version.
19
+ * @public
20
+ */
21
+ export var CompressedId64Set;
22
+ (function (CompressedId64Set) {
23
+ function isHexDigit(ch) {
24
+ // ascii values:
25
+ // '0' = 48
26
+ // '9' = 57
27
+ // 'a' = 65
28
+ // 'f' = 70
29
+ return (ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 70);
30
+ }
31
+ function compactRange(increment, length) {
32
+ assert(length > 0);
33
+ const inc = `+${increment.toString()}`;
34
+ if (length <= 1)
35
+ return inc;
36
+ const len = length.toString(16).toUpperCase();
37
+ return `${inc}*${len}`;
38
+ }
39
+ /** Given a set of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
40
+ * @note Invalid Ids are ignored.
41
+ * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
42
+ * @see [[CompressedId64Set.compressArray]] to perform the same operation on an [[Id64Array]].
43
+ * @see [[CompressedId64Set.decompressSet]] to perform the inverse operation.
44
+ */
45
+ function compressSet(ids) {
46
+ return sortAndCompress(ids);
47
+ }
48
+ CompressedId64Set.compressSet = compressSet;
49
+ /** Create a sorted array from `ids`, then return a compact string representation of those Ids.
50
+ * @see [[compressIds]] if `ids` is known to already be sorted.
51
+ */
52
+ function sortAndCompress(ids) {
53
+ // `string` is an Iterable<string>. In that case assume caller passed a single Id64String.
54
+ const arr = typeof ids === "string" ? [ids] : Array.from(ids);
55
+ OrderedId64Iterable.sortArray(arr);
56
+ return compressArray(arr);
57
+ }
58
+ CompressedId64Set.sortAndCompress = sortAndCompress;
59
+ /** Give a **numerically-ordered** array of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
60
+ * Duplicate Ids are included only once in the string representation.
61
+ * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the array is not properly sorted.
62
+ * @note The array must be sorted according to the 64-bit numerical value of each Id.
63
+ * @note Invalid Ids are ignored.
64
+ * @see [[CompressedId64Set.decompressArray]] to perform the inverse operation.
65
+ * @see [[OrderedId64Iterable.sortArray]] to ensure the Ids are properly sorted.
66
+ * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
67
+ */
68
+ function compressArray(ids) {
69
+ return compressIds(ids);
70
+ }
71
+ CompressedId64Set.compressArray = compressArray;
72
+ /** Give a **numerically-ordered** collection of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.
73
+ * Duplicate Ids are included only once in the string representation.
74
+ * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the collection is not properly sorted.
75
+ * @note The collection must be sorted according to the 64-bit numerical value of each Id.
76
+ * @note Invalid Ids are ignored.
77
+ * @see [[CompressedId64Set.iterable]] to perform the inverse operation.
78
+ * @see [[OrderedId64Iterable.sortArray]] or [[OrderedId64Iterable.compare]] to ensure the Ids are properly sorted.
79
+ * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.
80
+ */
81
+ function compressIds(ids) {
82
+ if ("string" === typeof ids)
83
+ return ids;
84
+ let str = "";
85
+ const prevId = new Uint64();
86
+ const rangeIncrement = new Uint64();
87
+ let rangeLen = 0;
88
+ const curId = new Uint64();
89
+ const curIncrement = new Uint64();
90
+ for (const id of ids) {
91
+ if (!Id64.isValidId64(id))
92
+ continue; // ignore garbage and invalid Ids ("0")
93
+ curId.setFromId(id);
94
+ curIncrement.setFromDifference(curId, prevId);
95
+ const cmp = prevId.compare(curId);
96
+ if (0 === cmp)
97
+ continue; // ignore duplicates
98
+ else if (cmp > 0)
99
+ throw new Error("CompressedId64Set.compressArray requires a sorted array as input");
100
+ prevId.copyFrom(curId);
101
+ if (0 === rangeLen) {
102
+ rangeIncrement.copyFrom(curIncrement);
103
+ rangeLen = 1;
104
+ }
105
+ else if (curIncrement.equals(rangeIncrement)) {
106
+ ++rangeLen;
107
+ }
108
+ else {
109
+ str += compactRange(rangeIncrement, rangeLen);
110
+ rangeIncrement.copyFrom(curIncrement);
111
+ rangeLen = 1;
112
+ }
113
+ }
114
+ if (0 < rangeLen)
115
+ str += compactRange(rangeIncrement, rangeLen);
116
+ return str;
117
+ }
118
+ CompressedId64Set.compressIds = compressIds;
119
+ /** This exists strictly for the purposes of compressed sets of 64-bit Ids, to avoid the overhead of BigInt for handling 64-bit integers. */
120
+ class Uint64 {
121
+ static assertUint32(num) {
122
+ assert(num >= 0);
123
+ assert(num < Uint64._base);
124
+ assert(Math.floor(num) === num);
125
+ }
126
+ assertConstraints() {
127
+ Uint64.assertUint32(this.lower);
128
+ Uint64.assertUint32(this.upper);
129
+ }
130
+ constructor(lower = 0, upper = 0) {
131
+ this.lower = lower;
132
+ this.upper = upper;
133
+ this.assertConstraints();
134
+ }
135
+ compare(rhs) {
136
+ const diff = this.upper - rhs.upper;
137
+ return 0 === diff ? this.lower - rhs.lower : diff;
138
+ }
139
+ equals(rhs) { return 0 === this.compare(rhs); }
140
+ isLessThan(rhs) { return this.compare(rhs) < 0; }
141
+ isGreaterThan(rhs) { return this.compare(rhs) > 0; }
142
+ get isZero() { return 0 === this.lower && 0 === this.upper; }
143
+ setFromDifference(lhs, rhs) {
144
+ assert(!rhs.isGreaterThan(lhs));
145
+ this.lower = lhs.lower - rhs.lower;
146
+ this.upper = lhs.upper - rhs.upper;
147
+ if (this.lower < 0) {
148
+ this.lower += Uint64._base;
149
+ this.upper -= 1;
150
+ }
151
+ }
152
+ add(rhs) {
153
+ let lower = rhs.lower;
154
+ let upper = rhs.upper;
155
+ if (lower + this.lower >= Uint64._base) {
156
+ lower -= Uint64._base;
157
+ upper += 1;
158
+ }
159
+ this.lower += lower;
160
+ this.upper += upper;
161
+ this.assertConstraints();
162
+ }
163
+ setFromId(id) {
164
+ Id64.getUint32Pair(id, this);
165
+ }
166
+ copyFrom(other) {
167
+ this.lower = other.lower;
168
+ this.upper = other.upper;
169
+ }
170
+ toString() {
171
+ if (0 === this.upper)
172
+ return this.lower.toString(16).toUpperCase();
173
+ const upper = this.upper.toString(16);
174
+ const lower = this.lower.toString(16).padStart(8, "0");
175
+ assert(lower.length === 8);
176
+ return `${upper}${lower}`.toUpperCase();
177
+ }
178
+ toId64String() {
179
+ return Id64.fromUint32Pair(this.lower, this.upper);
180
+ }
181
+ }
182
+ Uint64._base = 0x100000000;
183
+ /** Supplies an iterator over the [[Id64String]]s in a [[CompressedId64Set]].
184
+ * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.
185
+ */
186
+ function* iterator(ids) {
187
+ if (0 === ids.length)
188
+ return; // empty set.
189
+ if ("+" !== ids[0])
190
+ throw new Error("Invalid CompressedId64Set");
191
+ let curIndex = 1; // skip the leading '+'
192
+ const curId = new Uint64();
193
+ function parseUint32() {
194
+ let value = 0;
195
+ let nChars = 0;
196
+ while (curIndex < ids.length && nChars < 8) {
197
+ ++nChars;
198
+ const ch = ids.charCodeAt(curIndex);
199
+ if (!isHexDigit(ch))
200
+ break; // not a hex digit in [0..9] or [A..F]
201
+ value <<= 4;
202
+ value |= (ch >= 65 ? ch - 65 + 10 : ch - 48); // ch - 'A' + 10 or ch - '0'
203
+ value = value >>> 0; // restore unsignedness because silly javascript.
204
+ ++curIndex;
205
+ }
206
+ return value;
207
+ }
208
+ function parseUint64(uint64) {
209
+ let lower = 0;
210
+ let upper = 0;
211
+ // Read up to the first 8 digits.
212
+ const startIndex = curIndex;
213
+ const first = parseUint32();
214
+ const nFirstDigits = curIndex - startIndex;
215
+ assert(nFirstDigits <= 8);
216
+ if (8 === nFirstDigits && curIndex + 1 < ids.length && isHexDigit(ids.charCodeAt(curIndex + 1))) {
217
+ // We've got up to 8 more digits remaining
218
+ const secondIndex = curIndex;
219
+ const second = parseUint32();
220
+ // Transfer excess digits from upper to lower.
221
+ const nSecondDigits = curIndex - secondIndex;
222
+ assert(nSecondDigits > 0 && nSecondDigits <= 8);
223
+ const nDigitsToTransfer = 8 - nSecondDigits;
224
+ upper = first >>> (4 * nDigitsToTransfer);
225
+ const transfer = first - ((upper << (4 * nDigitsToTransfer)) >>> 0);
226
+ lower = (second | ((transfer << (4 * nSecondDigits)) >>> 0)) >>> 0;
227
+ }
228
+ else {
229
+ lower = first;
230
+ }
231
+ uint64.lower = lower;
232
+ uint64.upper = upper;
233
+ }
234
+ const increment = new Uint64();
235
+ while (curIndex < ids.length) {
236
+ let multiplier = 1;
237
+ parseUint64(increment);
238
+ if (increment.isZero)
239
+ throw new Error("Invalid CompressedId64Set");
240
+ if (curIndex < ids.length) {
241
+ switch (ids[curIndex++]) {
242
+ case "*":
243
+ multiplier = parseUint32();
244
+ if (0 === multiplier)
245
+ throw new Error("Invalid CompressedId64Set");
246
+ if (curIndex !== ids.length && ids[curIndex++] !== "+")
247
+ return;
248
+ break;
249
+ case "+":
250
+ break;
251
+ default:
252
+ throw new Error("Invalid CompressedId64Set");
253
+ }
254
+ }
255
+ for (let i = 0; i < multiplier; i++) {
256
+ curId.add(increment);
257
+ yield curId.toId64String();
258
+ }
259
+ }
260
+ }
261
+ CompressedId64Set.iterator = iterator;
262
+ /** Supplies an iterable over the [[Id64String]]s in a [[CompressedId64Set]].
263
+ * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.
264
+ */
265
+ function iterable(ids) {
266
+ return {
267
+ [Symbol.iterator]: () => iterator(ids),
268
+ };
269
+ }
270
+ CompressedId64Set.iterable = iterable;
271
+ /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Set]].
272
+ * @param compressedIds The compact string representation.
273
+ * @param out If supplied, the Ids will be inserted into this set rather than allocating and returning a new set.
274
+ * @returns The set containing the decompressed Ids.
275
+ * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].
276
+ * @see [[CompressedId64Set.compressSet]] to perform the inverse operation.
277
+ * @see [[CompressedId64Set.decompressArray]] to decompress as an [[Id64Array]] instead.
278
+ * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.
279
+ */
280
+ function decompressSet(compressedIds, out) {
281
+ const set = out ?? new Set();
282
+ for (const id of iterable(compressedIds))
283
+ set.add(id);
284
+ return set;
285
+ }
286
+ CompressedId64Set.decompressSet = decompressSet;
287
+ /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Array]].
288
+ * @param compressedIds The compact string representation.
289
+ * @param out If supplied, the Ids will be appended to this array rather than allocating and returning a new array.
290
+ * @returns The array containing the decompressed Ids.
291
+ * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].
292
+ * @note The Ids are decompressed and appended to the array in ascending order based on their 64-bit numerical values.
293
+ * @see [[CompressedId64Set.compressArray]] to perform the inverse operation.
294
+ * @see [[CompressedId64Set.decompressSet]] to decompress as an [[Id64Set]] instead.
295
+ * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.
296
+ */
297
+ function decompressArray(compressedIds, out) {
298
+ const arr = out ?? [];
299
+ for (const id of iterable(compressedIds))
300
+ arr.push(id);
301
+ return arr;
302
+ }
303
+ CompressedId64Set.decompressArray = decompressArray;
304
+ })(CompressedId64Set || (CompressedId64Set = {}));
305
+ /** A [[SortedArray]] of unique [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer values of the Ids.
306
+ * @see [[CompressedId64Set]] for an immutable compact string representation.
307
+ * @public
308
+ */
309
+ export class OrderedId64Array extends SortedArray {
310
+ /** Construct a new, empty array. */
311
+ constructor() {
312
+ super((lhs, rhs) => OrderedId64Iterable.compare(lhs, rhs));
313
+ }
314
+ /** An iterable that iterates over the Ids in sorted order. */
315
+ get ids() { return this._array; }
316
+ /** The underlying array of Ids. */
317
+ get array() { return this._array; }
318
+ }
319
+ /** A mutable set of valid [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer value of the Ids.
320
+ * Internally the set of Ids is maintained as a [[CompressedId64Set]] string representation.
321
+ * Insertions and removals are buffered until the string representation needs to be recomputed. The string representation is recomputed by every public method except [[add]] and [[delete]] -
322
+ * therefore, if multiple removals and/or insertions are required, it is most efficient to perform them all before invoking other methods.
323
+ * @public
324
+ */
325
+ export class MutableCompressedId64Set {
326
+ /** Construct a new set, optionally initialized to contain the Ids represented by `ids`. */
327
+ constructor(ids) {
328
+ this._inserted = new OrderedId64Array();
329
+ this._deleted = new OrderedId64Array();
330
+ this._ids = ids ?? "";
331
+ }
332
+ /** Obtain the compact string representation of the contents of this set. If any insertions or removals are pending, they will be applied and the string recomputed. */
333
+ get ids() {
334
+ this.updateIds();
335
+ return this._ids;
336
+ }
337
+ /** Add the specified Id to the set.
338
+ * @throws Error if `id` is not a valid [[Id64String]].
339
+ */
340
+ add(id) {
341
+ if (!Id64.isValidId64(id))
342
+ throw new Error("MutableCompressedId64Set.add: invalid Id");
343
+ this._deleted.remove(id);
344
+ this._inserted.insert(id);
345
+ }
346
+ /** Remove the specified Id from the set.
347
+ * @throws Error if `id` is not a valid [[Id64String]].
348
+ */
349
+ delete(id) {
350
+ if (!Id64.isValidId64(id))
351
+ throw new Error("MutableCompressedId64Set.delete: invalid Id");
352
+ this._inserted.remove(id);
353
+ this._deleted.insert(id);
354
+ }
355
+ /** Remove all Ids from the set. */
356
+ clear() {
357
+ this._ids = "";
358
+ this._inserted.clear();
359
+ this._deleted.clear();
360
+ }
361
+ /** Remove all Ids from the set, then add the specified Ids. */
362
+ reset(ids) {
363
+ this.clear();
364
+ this._ids = ids ?? "";
365
+ }
366
+ /** Obtain an iterator over the Ids in this set. The Ids are returned in ascending order based on their unsigned 64-bit integer values. */
367
+ [Symbol.iterator]() {
368
+ return CompressedId64Set.iterator(this.ids);
369
+ }
370
+ /** Compute a compact string representation of the union of this and another set of Ids - i.e., those Ids present in either this and/or the other set. */
371
+ computeUnion(ids) {
372
+ if (this.isEmpty)
373
+ return CompressedId64Set.compressIds(ids);
374
+ else if (OrderedId64Iterable.isEmptySet(ids) || this.equals(ids))
375
+ return this.ids;
376
+ return CompressedId64Set.compressIds(OrderedId64Iterable.union(this, ids));
377
+ }
378
+ /** Compute a compact string representation of the intersection of this and another set of Ids - i.e., those Ids present in both this and the other set. */
379
+ computeIntersection(ids) {
380
+ if (this.equals(ids))
381
+ return this.ids;
382
+ else if (this.isEmpty || OrderedId64Iterable.isEmptySet(ids))
383
+ return "";
384
+ return CompressedId64Set.compressIds(OrderedId64Iterable.intersection(this, ids));
385
+ }
386
+ /** Compute a compact string representation of the difference between this and another set - i.e., those Ids present in this but not in the other set. */
387
+ computeDifference(ids) {
388
+ if (this.isEmpty || this.equals(ids))
389
+ return "";
390
+ return CompressedId64Set.compressIds(OrderedId64Iterable.difference(this, ids));
391
+ }
392
+ /** Return true if this set contains no Ids. */
393
+ get isEmpty() {
394
+ return OrderedId64Iterable.isEmptySet(this.ids);
395
+ }
396
+ /** Return true if the set of Ids represented by `other` is identical to those in this set.
397
+ * @note This considers only the **distinct** Ids in `other` - duplicates are ignored.
398
+ */
399
+ equals(other) {
400
+ if (other instanceof MutableCompressedId64Set) {
401
+ if (other === this)
402
+ return true;
403
+ if (typeof other !== "string")
404
+ other = other.ids;
405
+ }
406
+ if (typeof other === "string")
407
+ return other === this.ids;
408
+ this.updateIds();
409
+ return OrderedId64Iterable.areEqualSets(this, other);
410
+ }
411
+ get _isDirty() {
412
+ return !this._inserted.isEmpty || !this._deleted.isEmpty;
413
+ }
414
+ updateIds() {
415
+ if (!this._isDirty)
416
+ return;
417
+ const difference = OrderedId64Iterable.difference(CompressedId64Set.iterable(this._ids), this._deleted.ids);
418
+ const union = { [Symbol.iterator]: () => OrderedId64Iterable.unionIterator(difference, this._inserted.ids) };
419
+ this._ids = CompressedId64Set.compressIds(union);
420
+ this._inserted.clear();
421
+ this._deleted.clear();
422
+ }
423
+ }
424
424
  //# sourceMappingURL=CompressedId64Set.js.map