@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.72

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 (211) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/lib/cjs/AccessToken.d.ts +10 -10
  3. package/lib/cjs/AccessToken.d.ts.map +1 -1
  4. package/lib/cjs/AccessToken.js +9 -9
  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/BeSQLite.d.ts +172 -170
  12. package/lib/cjs/BeSQLite.d.ts.map +1 -1
  13. package/lib/cjs/BeSQLite.js +185 -183
  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 -702
  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/ByteStream.d.ts +110 -110
  22. package/lib/cjs/ByteStream.js +159 -159
  23. package/lib/cjs/ClassUtils.d.ts +14 -14
  24. package/lib/cjs/ClassUtils.js +27 -27
  25. package/lib/cjs/Compare.d.ts +47 -47
  26. package/lib/cjs/Compare.d.ts.map +1 -1
  27. package/lib/cjs/Compare.js +75 -75
  28. package/lib/cjs/CompressedId64Set.d.ts +134 -134
  29. package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
  30. package/lib/cjs/CompressedId64Set.js +428 -428
  31. package/lib/cjs/CompressedId64Set.js.map +1 -1
  32. package/lib/cjs/Dictionary.d.ts +125 -125
  33. package/lib/cjs/Dictionary.js +203 -203
  34. package/lib/cjs/Disposable.d.ts +80 -80
  35. package/lib/cjs/Disposable.d.ts.map +1 -1
  36. package/lib/cjs/Disposable.js +120 -120
  37. package/lib/cjs/Id.d.ts +285 -285
  38. package/lib/cjs/Id.d.ts.map +1 -1
  39. package/lib/cjs/Id.js +643 -643
  40. package/lib/cjs/IndexMap.d.ts +65 -65
  41. package/lib/cjs/IndexMap.js +91 -91
  42. package/lib/cjs/JsonSchema.d.ts +77 -77
  43. package/lib/cjs/JsonSchema.d.ts.map +1 -1
  44. package/lib/cjs/JsonSchema.js +9 -9
  45. package/lib/cjs/JsonUtils.d.ts +78 -78
  46. package/lib/cjs/JsonUtils.js +151 -151
  47. package/lib/cjs/LRUMap.d.ts +129 -129
  48. package/lib/cjs/LRUMap.js +333 -333
  49. package/lib/cjs/LRUMap.js.map +1 -1
  50. package/lib/cjs/Logger.d.ts +143 -143
  51. package/lib/cjs/Logger.d.ts.map +1 -1
  52. package/lib/cjs/Logger.js +256 -258
  53. package/lib/cjs/Logger.js.map +1 -1
  54. package/lib/cjs/ObservableSet.d.ts +23 -23
  55. package/lib/cjs/ObservableSet.js +51 -51
  56. package/lib/cjs/OneAtATimeAction.d.ts +31 -31
  57. package/lib/cjs/OneAtATimeAction.js +94 -94
  58. package/lib/cjs/OneAtATimeAction.js.map +1 -1
  59. package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
  60. package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
  61. package/lib/cjs/OrderedId64Iterable.js +235 -235
  62. package/lib/cjs/OrderedSet.d.ts +40 -40
  63. package/lib/cjs/OrderedSet.js +64 -64
  64. package/lib/cjs/PriorityQueue.d.ts +70 -70
  65. package/lib/cjs/PriorityQueue.d.ts.map +1 -1
  66. package/lib/cjs/PriorityQueue.js +140 -140
  67. package/lib/cjs/ProcessDetector.d.ts +59 -59
  68. package/lib/cjs/ProcessDetector.js +71 -71
  69. package/lib/cjs/SortedArray.d.ts +236 -232
  70. package/lib/cjs/SortedArray.d.ts.map +1 -1
  71. package/lib/cjs/SortedArray.js +315 -303
  72. package/lib/cjs/SortedArray.js.map +1 -1
  73. package/lib/cjs/StatusCategory.d.ts +30 -30
  74. package/lib/cjs/StatusCategory.d.ts.map +1 -1
  75. package/lib/cjs/StatusCategory.js +460 -460
  76. package/lib/cjs/StatusCategory.js.map +1 -1
  77. package/lib/cjs/StringUtils.d.ts +22 -22
  78. package/lib/cjs/StringUtils.js +148 -148
  79. package/lib/cjs/Time.d.ts +122 -122
  80. package/lib/cjs/Time.js +152 -152
  81. package/lib/cjs/Time.js.map +1 -1
  82. package/lib/cjs/Tracing.d.ts +43 -40
  83. package/lib/cjs/Tracing.d.ts.map +1 -1
  84. package/lib/cjs/Tracing.js +134 -130
  85. package/lib/cjs/Tracing.js.map +1 -1
  86. package/lib/cjs/TupleKeyedMap.d.ts +36 -36
  87. package/lib/cjs/TupleKeyedMap.js +102 -102
  88. package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
  89. package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
  90. package/lib/cjs/TypedArrayBuilder.js +206 -208
  91. package/lib/cjs/TypedArrayBuilder.js.map +1 -1
  92. package/lib/cjs/UnexpectedErrors.d.ts +43 -43
  93. package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
  94. package/lib/cjs/UnexpectedErrors.js +68 -68
  95. package/lib/cjs/UnexpectedErrors.js.map +1 -1
  96. package/lib/cjs/UtilityTypes.d.ts +112 -96
  97. package/lib/cjs/UtilityTypes.d.ts.map +1 -1
  98. package/lib/cjs/UtilityTypes.js +40 -40
  99. package/lib/cjs/UtilityTypes.js.map +1 -1
  100. package/lib/cjs/YieldManager.d.ts +18 -18
  101. package/lib/cjs/YieldManager.js +34 -34
  102. package/lib/cjs/core-bentley.d.ts +74 -74
  103. package/lib/cjs/core-bentley.js +94 -90
  104. package/lib/cjs/core-bentley.js.map +1 -1
  105. package/lib/cjs/partitionArray.d.ts +21 -21
  106. package/lib/cjs/partitionArray.js +43 -43
  107. package/lib/esm/AccessToken.d.ts +10 -10
  108. package/lib/esm/AccessToken.d.ts.map +1 -1
  109. package/lib/esm/AccessToken.js +8 -8
  110. package/lib/esm/Assert.d.ts +25 -25
  111. package/lib/esm/Assert.js +41 -41
  112. package/lib/esm/Assert.js.map +1 -1
  113. package/lib/esm/BeEvent.d.ts +81 -81
  114. package/lib/esm/BeEvent.d.ts.map +1 -1
  115. package/lib/esm/BeEvent.js +150 -150
  116. package/lib/esm/BeSQLite.d.ts +172 -170
  117. package/lib/esm/BeSQLite.d.ts.map +1 -1
  118. package/lib/esm/BeSQLite.js +182 -180
  119. package/lib/esm/BeSQLite.js.map +1 -1
  120. package/lib/esm/BentleyError.d.ts +378 -378
  121. package/lib/esm/BentleyError.d.ts.map +1 -1
  122. package/lib/esm/BentleyError.js +699 -698
  123. package/lib/esm/BentleyError.js.map +1 -1
  124. package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
  125. package/lib/esm/BentleyLoggerCategory.js +16 -16
  126. package/lib/esm/ByteStream.d.ts +110 -110
  127. package/lib/esm/ByteStream.js +155 -155
  128. package/lib/esm/ClassUtils.d.ts +14 -14
  129. package/lib/esm/ClassUtils.js +22 -22
  130. package/lib/esm/Compare.d.ts +47 -47
  131. package/lib/esm/Compare.d.ts.map +1 -1
  132. package/lib/esm/Compare.js +63 -63
  133. package/lib/esm/CompressedId64Set.d.ts +134 -134
  134. package/lib/esm/CompressedId64Set.d.ts.map +1 -1
  135. package/lib/esm/CompressedId64Set.js +423 -423
  136. package/lib/esm/CompressedId64Set.js.map +1 -1
  137. package/lib/esm/Dictionary.d.ts +125 -125
  138. package/lib/esm/Dictionary.js +199 -199
  139. package/lib/esm/Disposable.d.ts +80 -80
  140. package/lib/esm/Disposable.d.ts.map +1 -1
  141. package/lib/esm/Disposable.js +112 -112
  142. package/lib/esm/Id.d.ts +285 -285
  143. package/lib/esm/Id.d.ts.map +1 -1
  144. package/lib/esm/Id.js +639 -639
  145. package/lib/esm/IndexMap.d.ts +65 -65
  146. package/lib/esm/IndexMap.js +86 -86
  147. package/lib/esm/JsonSchema.d.ts +77 -77
  148. package/lib/esm/JsonSchema.d.ts.map +1 -1
  149. package/lib/esm/JsonSchema.js +8 -8
  150. package/lib/esm/JsonUtils.d.ts +78 -78
  151. package/lib/esm/JsonUtils.js +148 -148
  152. package/lib/esm/LRUMap.d.ts +129 -129
  153. package/lib/esm/LRUMap.js +326 -326
  154. package/lib/esm/LRUMap.js.map +1 -1
  155. package/lib/esm/Logger.d.ts +143 -143
  156. package/lib/esm/Logger.d.ts.map +1 -1
  157. package/lib/esm/Logger.js +253 -253
  158. package/lib/esm/Logger.js.map +1 -1
  159. package/lib/esm/ObservableSet.d.ts +23 -23
  160. package/lib/esm/ObservableSet.js +47 -47
  161. package/lib/esm/OneAtATimeAction.d.ts +31 -31
  162. package/lib/esm/OneAtATimeAction.js +89 -89
  163. package/lib/esm/OneAtATimeAction.js.map +1 -1
  164. package/lib/esm/OrderedId64Iterable.d.ts +74 -74
  165. package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
  166. package/lib/esm/OrderedId64Iterable.js +232 -232
  167. package/lib/esm/OrderedSet.d.ts +40 -40
  168. package/lib/esm/OrderedSet.js +59 -59
  169. package/lib/esm/PriorityQueue.d.ts +70 -70
  170. package/lib/esm/PriorityQueue.d.ts.map +1 -1
  171. package/lib/esm/PriorityQueue.js +136 -136
  172. package/lib/esm/ProcessDetector.d.ts +59 -59
  173. package/lib/esm/ProcessDetector.js +67 -67
  174. package/lib/esm/SortedArray.d.ts +236 -232
  175. package/lib/esm/SortedArray.d.ts.map +1 -1
  176. package/lib/esm/SortedArray.js +308 -296
  177. package/lib/esm/SortedArray.js.map +1 -1
  178. package/lib/esm/StatusCategory.d.ts +30 -30
  179. package/lib/esm/StatusCategory.d.ts.map +1 -1
  180. package/lib/esm/StatusCategory.js +455 -454
  181. package/lib/esm/StatusCategory.js.map +1 -1
  182. package/lib/esm/StringUtils.d.ts +22 -22
  183. package/lib/esm/StringUtils.js +142 -142
  184. package/lib/esm/Time.d.ts +122 -122
  185. package/lib/esm/Time.js +146 -146
  186. package/lib/esm/Time.js.map +1 -1
  187. package/lib/esm/Tracing.d.ts +43 -40
  188. package/lib/esm/Tracing.d.ts.map +1 -1
  189. package/lib/esm/Tracing.js +130 -126
  190. package/lib/esm/Tracing.js.map +1 -1
  191. package/lib/esm/TupleKeyedMap.d.ts +36 -36
  192. package/lib/esm/TupleKeyedMap.js +98 -98
  193. package/lib/esm/TypedArrayBuilder.d.ts +155 -155
  194. package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
  195. package/lib/esm/TypedArrayBuilder.js +198 -200
  196. package/lib/esm/TypedArrayBuilder.js.map +1 -1
  197. package/lib/esm/UnexpectedErrors.d.ts +43 -43
  198. package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
  199. package/lib/esm/UnexpectedErrors.js +65 -64
  200. package/lib/esm/UnexpectedErrors.js.map +1 -1
  201. package/lib/esm/UtilityTypes.d.ts +112 -96
  202. package/lib/esm/UtilityTypes.d.ts.map +1 -1
  203. package/lib/esm/UtilityTypes.js +34 -34
  204. package/lib/esm/UtilityTypes.js.map +1 -1
  205. package/lib/esm/YieldManager.d.ts +18 -18
  206. package/lib/esm/YieldManager.js +30 -30
  207. package/lib/esm/core-bentley.d.ts +74 -74
  208. package/lib/esm/core-bentley.js +78 -78
  209. package/lib/esm/partitionArray.d.ts +21 -21
  210. package/lib/esm/partitionArray.js +39 -39
  211. package/package.json +9 -9
@@ -1,200 +1,200 @@
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 { lowerBound, shallowClone } from "./SortedArray";
9
- class DictionaryIterator {
10
- constructor(keys, values) {
11
- this._curIndex = -1;
12
- this._keys = keys;
13
- this._values = values;
14
- }
15
- next() {
16
- if (++this._curIndex >= this._keys.length) {
17
- // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.
18
- return { done: true };
19
- }
20
- else {
21
- return {
22
- value: {
23
- key: this._keys[this._curIndex],
24
- value: this._values[this._curIndex],
25
- },
26
- done: false,
27
- };
28
- }
29
- }
30
- }
31
- /**
32
- * Maintains a mapping of keys to values.
33
- * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).
34
- * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:
35
- * - If lhs is equal to rhs, returns 0
36
- * - If lhs is less than rhs, returns a negative value
37
- * - If lhs is greater than rhs, returns a positive value
38
- * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0
39
- * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.
40
- *
41
- * Modifying a key in a way that affects the comparison function will produce unpredictable results, the
42
- * most likely of which is that keys will cease to map to the values with which they were initially inserted.
43
- * @public
44
- */
45
- export class Dictionary {
46
- /**
47
- * Construct a new Dictionary<K, V>.
48
- * @param compareKeys The function used to compare keys within the dictionary.
49
- * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.
50
- * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.
51
- */
52
- constructor(compareKeys, cloneKey = shallowClone, cloneValue = shallowClone) {
53
- this._keys = [];
54
- this._values = [];
55
- this._compareKeys = compareKeys;
56
- this._cloneKey = cloneKey;
57
- this._cloneValue = cloneValue;
58
- }
59
- /** The number of entries in the dictionary. */
60
- get size() { return this._keys.length; }
61
- /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */
62
- [Symbol.iterator]() {
63
- return new DictionaryIterator(this._keys, this._values);
64
- }
65
- /** Provides iteration over the keys in this Dictionary, in sorted order. */
66
- keys() {
67
- function* iterator(dict) {
68
- for (const entry of dict)
69
- yield entry.key;
70
- }
71
- return {
72
- [Symbol.iterator]: () => iterator(this),
73
- };
74
- }
75
- /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */
76
- values() {
77
- function* iterator(dict) {
78
- for (const entry of dict)
79
- yield entry.value;
80
- }
81
- return {
82
- [Symbol.iterator]: () => iterator(this),
83
- };
84
- }
85
- /** Removes all entries from this dictionary */
86
- clear() {
87
- this._keys = [];
88
- this._values = [];
89
- }
90
- /**
91
- * Looks up a value by its key.
92
- * @param key The key to search for
93
- * @returns the value associated with the key, or undefined if the key is not present in the dictionary.
94
- */
95
- get(key) {
96
- const bound = this.lowerBound(key);
97
- return bound.equal ? this._values[bound.index] : undefined;
98
- }
99
- /**
100
- * Determines if an entry exists for the specified key
101
- * @param key The key to search for
102
- * @returns true if an entry exists in this dictionary corresponding to the specified key.
103
- */
104
- has(key) {
105
- return this.lowerBound(key).equal;
106
- }
107
- /**
108
- * Deletes a value using its key.
109
- * @param key The key to delete
110
- * @returns true if the key was found and deleted.
111
- */
112
- delete(key) {
113
- const bound = this.lowerBound(key);
114
- if (bound.equal) {
115
- this._values.splice(bound.index, 1);
116
- this._keys.splice(bound.index, 1);
117
- return true;
118
- }
119
- else {
120
- return false;
121
- }
122
- }
123
- /**
124
- * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.
125
- * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.
126
- * @param key The key to associate with the value
127
- * @param value The value to associate with the key
128
- * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.
129
- */
130
- insert(key, value) {
131
- const result = this.findOrInsert(key, value);
132
- return result.inserted;
133
- }
134
- /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.
135
- * @param key The key to search for.
136
- * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.
137
- * @returns The found or inserted value and a flag indicating whether the new value was inserted.
138
- */
139
- findOrInsert(key, value) {
140
- const bound = this.lowerBound(key);
141
- if (bound.equal)
142
- return { value: this._values[bound.index], inserted: false };
143
- value = this._cloneValue(value);
144
- this._keys.splice(bound.index, 0, this._cloneKey(key));
145
- this._values.splice(bound.index, 0, this._cloneValue(value));
146
- return { value, inserted: true };
147
- }
148
- /**
149
- * Sets the value associated with the specified key in the dictionary.
150
- * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.
151
- * In either case, the value will be cloned using the function supplied to the dictionary's constructor.
152
- */
153
- set(key, value) {
154
- value = this._cloneValue(value);
155
- const bound = this.lowerBound(key);
156
- if (bound.equal) {
157
- this._values[bound.index] = value;
158
- }
159
- else {
160
- this._keys.splice(bound.index, 0, this._cloneKey(key));
161
- this._values.splice(bound.index, 0, value);
162
- }
163
- }
164
- /**
165
- * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.
166
- * @returns An array of { key, value } pairs sorted by key.
167
- */
168
- extractPairs() {
169
- const pairs = [];
170
- for (let i = 0; i < this.size; i++)
171
- pairs.push({ key: this._keys[i], value: this._values[i] });
172
- this.clear();
173
- return pairs;
174
- }
175
- /**
176
- * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.
177
- * The array of keys is sorted according to the comparison criterion.
178
- * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.
179
- * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.
180
- */
181
- extractArrays() {
182
- const result = { keys: this._keys, values: this._values };
183
- this.clear();
184
- return result;
185
- }
186
- /** Apply a function to each (key, value) pair in the dictionary, in sorted order.
187
- * @param func The function to be applied.
188
- */
189
- forEach(func) {
190
- for (let i = 0; i < this.size; i++)
191
- func(this._keys[i], this._values[i]);
192
- }
193
- /**
194
- * Computes the position at which the specified key should be inserted to maintain sorted order.
195
- * @param key The key whose position is to be computed.
196
- * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.
197
- */
198
- lowerBound(key) { return lowerBound(key, this._keys, this._compareKeys); }
199
- }
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 { lowerBound, shallowClone } from "./SortedArray";
9
+ class DictionaryIterator {
10
+ constructor(keys, values) {
11
+ this._curIndex = -1;
12
+ this._keys = keys;
13
+ this._values = values;
14
+ }
15
+ next() {
16
+ if (++this._curIndex >= this._keys.length) {
17
+ // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.
18
+ return { done: true };
19
+ }
20
+ else {
21
+ return {
22
+ value: {
23
+ key: this._keys[this._curIndex],
24
+ value: this._values[this._curIndex],
25
+ },
26
+ done: false,
27
+ };
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * Maintains a mapping of keys to values.
33
+ * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).
34
+ * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:
35
+ * - If lhs is equal to rhs, returns 0
36
+ * - If lhs is less than rhs, returns a negative value
37
+ * - If lhs is greater than rhs, returns a positive value
38
+ * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0
39
+ * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.
40
+ *
41
+ * Modifying a key in a way that affects the comparison function will produce unpredictable results, the
42
+ * most likely of which is that keys will cease to map to the values with which they were initially inserted.
43
+ * @public
44
+ */
45
+ export class Dictionary {
46
+ /**
47
+ * Construct a new Dictionary<K, V>.
48
+ * @param compareKeys The function used to compare keys within the dictionary.
49
+ * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.
50
+ * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.
51
+ */
52
+ constructor(compareKeys, cloneKey = shallowClone, cloneValue = shallowClone) {
53
+ this._keys = [];
54
+ this._values = [];
55
+ this._compareKeys = compareKeys;
56
+ this._cloneKey = cloneKey;
57
+ this._cloneValue = cloneValue;
58
+ }
59
+ /** The number of entries in the dictionary. */
60
+ get size() { return this._keys.length; }
61
+ /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */
62
+ [Symbol.iterator]() {
63
+ return new DictionaryIterator(this._keys, this._values);
64
+ }
65
+ /** Provides iteration over the keys in this Dictionary, in sorted order. */
66
+ keys() {
67
+ function* iterator(dict) {
68
+ for (const entry of dict)
69
+ yield entry.key;
70
+ }
71
+ return {
72
+ [Symbol.iterator]: () => iterator(this),
73
+ };
74
+ }
75
+ /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */
76
+ values() {
77
+ function* iterator(dict) {
78
+ for (const entry of dict)
79
+ yield entry.value;
80
+ }
81
+ return {
82
+ [Symbol.iterator]: () => iterator(this),
83
+ };
84
+ }
85
+ /** Removes all entries from this dictionary */
86
+ clear() {
87
+ this._keys = [];
88
+ this._values = [];
89
+ }
90
+ /**
91
+ * Looks up a value by its key.
92
+ * @param key The key to search for
93
+ * @returns the value associated with the key, or undefined if the key is not present in the dictionary.
94
+ */
95
+ get(key) {
96
+ const bound = this.lowerBound(key);
97
+ return bound.equal ? this._values[bound.index] : undefined;
98
+ }
99
+ /**
100
+ * Determines if an entry exists for the specified key
101
+ * @param key The key to search for
102
+ * @returns true if an entry exists in this dictionary corresponding to the specified key.
103
+ */
104
+ has(key) {
105
+ return this.lowerBound(key).equal;
106
+ }
107
+ /**
108
+ * Deletes a value using its key.
109
+ * @param key The key to delete
110
+ * @returns true if the key was found and deleted.
111
+ */
112
+ delete(key) {
113
+ const bound = this.lowerBound(key);
114
+ if (bound.equal) {
115
+ this._values.splice(bound.index, 1);
116
+ this._keys.splice(bound.index, 1);
117
+ return true;
118
+ }
119
+ else {
120
+ return false;
121
+ }
122
+ }
123
+ /**
124
+ * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.
125
+ * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.
126
+ * @param key The key to associate with the value
127
+ * @param value The value to associate with the key
128
+ * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.
129
+ */
130
+ insert(key, value) {
131
+ const result = this.findOrInsert(key, value);
132
+ return result.inserted;
133
+ }
134
+ /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.
135
+ * @param key The key to search for.
136
+ * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.
137
+ * @returns The found or inserted value and a flag indicating whether the new value was inserted.
138
+ */
139
+ findOrInsert(key, value) {
140
+ const bound = this.lowerBound(key);
141
+ if (bound.equal)
142
+ return { value: this._values[bound.index], inserted: false };
143
+ value = this._cloneValue(value);
144
+ this._keys.splice(bound.index, 0, this._cloneKey(key));
145
+ this._values.splice(bound.index, 0, this._cloneValue(value));
146
+ return { value, inserted: true };
147
+ }
148
+ /**
149
+ * Sets the value associated with the specified key in the dictionary.
150
+ * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.
151
+ * In either case, the value will be cloned using the function supplied to the dictionary's constructor.
152
+ */
153
+ set(key, value) {
154
+ value = this._cloneValue(value);
155
+ const bound = this.lowerBound(key);
156
+ if (bound.equal) {
157
+ this._values[bound.index] = value;
158
+ }
159
+ else {
160
+ this._keys.splice(bound.index, 0, this._cloneKey(key));
161
+ this._values.splice(bound.index, 0, value);
162
+ }
163
+ }
164
+ /**
165
+ * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.
166
+ * @returns An array of { key, value } pairs sorted by key.
167
+ */
168
+ extractPairs() {
169
+ const pairs = [];
170
+ for (let i = 0; i < this.size; i++)
171
+ pairs.push({ key: this._keys[i], value: this._values[i] });
172
+ this.clear();
173
+ return pairs;
174
+ }
175
+ /**
176
+ * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.
177
+ * The array of keys is sorted according to the comparison criterion.
178
+ * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.
179
+ * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.
180
+ */
181
+ extractArrays() {
182
+ const result = { keys: this._keys, values: this._values };
183
+ this.clear();
184
+ return result;
185
+ }
186
+ /** Apply a function to each (key, value) pair in the dictionary, in sorted order.
187
+ * @param func The function to be applied.
188
+ */
189
+ forEach(func) {
190
+ for (let i = 0; i < this.size; i++)
191
+ func(this._keys[i], this._values[i]);
192
+ }
193
+ /**
194
+ * Computes the position at which the specified key should be inserted to maintain sorted order.
195
+ * @param key The key whose position is to be computed.
196
+ * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.
197
+ */
198
+ lowerBound(key) { return lowerBound(key, this._keys, this._compareKeys); }
199
+ }
200
200
  //# sourceMappingURL=Dictionary.js.map
@@ -1,81 +1,81 @@
1
- /** @packageDocumentation
2
- * @module Utils
3
- */
4
- /** Interface adopted by a type which has deterministic cleanup logic.
5
- * For example:
6
- * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.
7
- * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.
8
- *
9
- * A similar concept exists in languages like C++ (implemented as "destructors") and C# ("IDisposable").
10
- * However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately.
11
- * Failure to do so may result in memory leaks or leaking of other resources.
12
- *
13
- * IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.
14
- *
15
- * Implementations of IDisposable tend to be more "low-level" types. The disposal of such types is often handled on your behalf.
16
- * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.
17
- * @public
18
- */
19
- export interface IDisposable {
20
- /** Disposes of any resources owned by this object.
21
- * @note The object is generally considered unusable after it has been disposed of.
22
- */
23
- dispose(): void;
24
- }
25
- /**
26
- * A type guard that checks whether the given argument implements `IDisposable` interface
27
- * @public
28
- */
29
- export declare function isIDisposable(obj: unknown): obj is IDisposable;
30
- /** Convenience function for disposing of a disposable object that may be undefined.
31
- * This is primarily used to simplify implementations of [[IDisposable.dispose]].
32
- * As a simple example:
33
- * ```ts
34
- * class Disposable implements IDisposable {
35
- * public member1?: DisposableType1;
36
- * public member2?: DisposableType2;
37
- *
38
- * public dispose() {
39
- * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
40
- * this.member2 = dispose(this.member2); // Likewise for member2.
41
- * }
42
- * }
43
- * ```
44
- * @param disposable The object to be disposed of.
45
- * @returns undefined
46
- * @public
47
- */
48
- export declare function dispose(disposable?: IDisposable): undefined;
49
- /** Disposes of and empties a list of disposable objects.
50
- * @param list The list of disposable objects.
51
- * @returns undefined
52
- * @public
53
- */
54
- export declare function disposeArray(list?: IDisposable[]): undefined;
55
- /** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'
56
- * is called on the resource no matter if the func returns or throws. If func returns, the return value
57
- * of this function is equal to return value of func. If func throws, this function also throws (after
58
- * disposing the resource).
59
- * @public
60
- */
61
- export declare function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult;
62
- /** A definition of function which may be called to dispose an object
63
- * @public
64
- */
65
- export declare type DisposeFunc = () => void;
66
- /** A disposable container of disposable objects.
67
- * @public
68
- */
69
- export declare class DisposableList implements IDisposable {
70
- private _disposables;
71
- /** Creates a disposable list. */
72
- constructor(disposables?: Array<IDisposable | DisposeFunc>);
73
- private isDisposable;
74
- /** Register an object for disposal. */
75
- add(disposable: IDisposable | DisposeFunc): void;
76
- /** Unregister disposable object. */
77
- remove(disposable: IDisposable): void;
78
- /** Disposes all registered objects. */
79
- dispose(): void;
80
- }
1
+ /** @packageDocumentation
2
+ * @module Utils
3
+ */
4
+ /** Interface adopted by a type which has deterministic cleanup logic.
5
+ * For example:
6
+ * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.
7
+ * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.
8
+ *
9
+ * A similar concept exists in languages like C++ (implemented as "destructors") and C# ("IDisposable").
10
+ * However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately.
11
+ * Failure to do so may result in memory leaks or leaking of other resources.
12
+ *
13
+ * IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.
14
+ *
15
+ * Implementations of IDisposable tend to be more "low-level" types. The disposal of such types is often handled on your behalf.
16
+ * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.
17
+ * @public
18
+ */
19
+ export interface IDisposable {
20
+ /** Disposes of any resources owned by this object.
21
+ * @note The object is generally considered unusable after it has been disposed of.
22
+ */
23
+ dispose(): void;
24
+ }
25
+ /**
26
+ * A type guard that checks whether the given argument implements `IDisposable` interface
27
+ * @public
28
+ */
29
+ export declare function isIDisposable(obj: unknown): obj is IDisposable;
30
+ /** Convenience function for disposing of a disposable object that may be undefined.
31
+ * This is primarily used to simplify implementations of [[IDisposable.dispose]].
32
+ * As a simple example:
33
+ * ```ts
34
+ * class Disposable implements IDisposable {
35
+ * public member1?: DisposableType1;
36
+ * public member2?: DisposableType2;
37
+ *
38
+ * public dispose() {
39
+ * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
40
+ * this.member2 = dispose(this.member2); // Likewise for member2.
41
+ * }
42
+ * }
43
+ * ```
44
+ * @param disposable The object to be disposed of.
45
+ * @returns undefined
46
+ * @public
47
+ */
48
+ export declare function dispose(disposable?: IDisposable): undefined;
49
+ /** Disposes of and empties a list of disposable objects.
50
+ * @param list The list of disposable objects.
51
+ * @returns undefined
52
+ * @public
53
+ */
54
+ export declare function disposeArray(list?: IDisposable[]): undefined;
55
+ /** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'
56
+ * is called on the resource no matter if the func returns or throws. If func returns, the return value
57
+ * of this function is equal to return value of func. If func throws, this function also throws (after
58
+ * disposing the resource).
59
+ * @public
60
+ */
61
+ export declare function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult;
62
+ /** A definition of function which may be called to dispose an object
63
+ * @public
64
+ */
65
+ export type DisposeFunc = () => void;
66
+ /** A disposable container of disposable objects.
67
+ * @public
68
+ */
69
+ export declare class DisposableList implements IDisposable {
70
+ private _disposables;
71
+ /** Creates a disposable list. */
72
+ constructor(disposables?: Array<IDisposable | DisposeFunc>);
73
+ private isDisposable;
74
+ /** Register an object for disposal. */
75
+ add(disposable: IDisposable | DisposeFunc): void;
76
+ /** Unregister disposable object. */
77
+ remove(disposable: IDisposable): void;
78
+ /** Disposes all registered objects. */
79
+ dispose(): void;
80
+ }
81
81
  //# sourceMappingURL=Disposable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Disposable.d.ts","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAG9D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,UAAU,CAAC,EAAE,WAAW,GAAG,SAAS,CAI3D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,GAAG,SAAS,CAS5D;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,GAAG,OAAO,CAkB/G;AAED;;GAEG;AACH,oBAAY,WAAW,GAAG,MAAM,IAAI,CAAC;AAQrC;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,YAAY,CAAgB;IAEpC,iCAAiC;gBACrB,WAAW,GAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAM;IAO9D,OAAO,CAAC,YAAY;IAIpB,uCAAuC;IAChC,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW;IAOhD,oCAAoC;IAC7B,MAAM,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI;IAM5C,uCAAuC;IAChC,OAAO,IAAI,IAAI;CAIvB"}
1
+ {"version":3,"file":"Disposable.d.ts","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAG9D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,UAAU,CAAC,EAAE,WAAW,GAAG,SAAS,CAI3D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,GAAG,SAAS,CAS5D;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,GAAG,OAAO,CAkB/G;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAQrC;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,YAAY,CAAgB;IAEpC,iCAAiC;gBACrB,WAAW,GAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAM;IAO9D,OAAO,CAAC,YAAY;IAIpB,uCAAuC;IAChC,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW;IAOhD,oCAAoC;IAC7B,MAAM,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI;IAM5C,uCAAuC;IAChC,OAAO,IAAI,IAAI;CAIvB"}