@itwin/core-bentley 3.0.0-dev.78 → 3.0.0-dev.79

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 (291) hide show
  1. package/lib/{AccessToken.d.ts → cjs/AccessToken.d.ts} +0 -0
  2. package/lib/cjs/AccessToken.d.ts.map +1 -0
  3. package/lib/{AccessToken.js → cjs/AccessToken.js} +0 -0
  4. package/lib/cjs/AccessToken.js.map +1 -0
  5. package/lib/{Assert.d.ts → cjs/Assert.d.ts} +0 -0
  6. package/lib/cjs/Assert.d.ts.map +1 -0
  7. package/lib/{Assert.js → cjs/Assert.js} +0 -0
  8. package/lib/cjs/Assert.js.map +1 -0
  9. package/lib/{AsyncMutex.d.ts → cjs/AsyncMutex.d.ts} +0 -0
  10. package/lib/cjs/AsyncMutex.d.ts.map +1 -0
  11. package/lib/{AsyncMutex.js → cjs/AsyncMutex.js} +0 -0
  12. package/lib/cjs/AsyncMutex.js.map +1 -0
  13. package/lib/{BeEvent.d.ts → cjs/BeEvent.d.ts} +0 -0
  14. package/lib/cjs/BeEvent.d.ts.map +1 -0
  15. package/lib/{BeEvent.js → cjs/BeEvent.js} +0 -0
  16. package/lib/cjs/BeEvent.js.map +1 -0
  17. package/lib/{BeSQLite.d.ts → cjs/BeSQLite.d.ts} +0 -0
  18. package/lib/cjs/BeSQLite.d.ts.map +1 -0
  19. package/lib/{BeSQLite.js → cjs/BeSQLite.js} +0 -0
  20. package/lib/cjs/BeSQLite.js.map +1 -0
  21. package/lib/{BentleyError.d.ts → cjs/BentleyError.d.ts} +0 -0
  22. package/lib/cjs/BentleyError.d.ts.map +1 -0
  23. package/lib/{BentleyError.js → cjs/BentleyError.js} +0 -0
  24. package/lib/cjs/BentleyError.js.map +1 -0
  25. package/lib/{BentleyLoggerCategory.d.ts → cjs/BentleyLoggerCategory.d.ts} +0 -0
  26. package/lib/cjs/BentleyLoggerCategory.d.ts.map +1 -0
  27. package/lib/{BentleyLoggerCategory.js → cjs/BentleyLoggerCategory.js} +0 -0
  28. package/lib/cjs/BentleyLoggerCategory.js.map +1 -0
  29. package/lib/{ByteStream.d.ts → cjs/ByteStream.d.ts} +0 -0
  30. package/lib/cjs/ByteStream.d.ts.map +1 -0
  31. package/lib/{ByteStream.js → cjs/ByteStream.js} +0 -0
  32. package/lib/cjs/ByteStream.js.map +1 -0
  33. package/lib/{Compare.d.ts → cjs/Compare.d.ts} +0 -0
  34. package/lib/cjs/Compare.d.ts.map +1 -0
  35. package/lib/{Compare.js → cjs/Compare.js} +0 -0
  36. package/lib/cjs/Compare.js.map +1 -0
  37. package/lib/{CompressedId64Set.d.ts → cjs/CompressedId64Set.d.ts} +0 -0
  38. package/lib/cjs/CompressedId64Set.d.ts.map +1 -0
  39. package/lib/{CompressedId64Set.js → cjs/CompressedId64Set.js} +0 -0
  40. package/lib/cjs/CompressedId64Set.js.map +1 -0
  41. package/lib/{Dictionary.d.ts → cjs/Dictionary.d.ts} +0 -0
  42. package/lib/cjs/Dictionary.d.ts.map +1 -0
  43. package/lib/{Dictionary.js → cjs/Dictionary.js} +0 -0
  44. package/lib/cjs/Dictionary.js.map +1 -0
  45. package/lib/{Disposable.d.ts → cjs/Disposable.d.ts} +0 -0
  46. package/lib/cjs/Disposable.d.ts.map +1 -0
  47. package/lib/{Disposable.js → cjs/Disposable.js} +0 -0
  48. package/lib/cjs/Disposable.js.map +1 -0
  49. package/lib/{Id.d.ts → cjs/Id.d.ts} +0 -0
  50. package/lib/cjs/Id.d.ts.map +1 -0
  51. package/lib/{Id.js → cjs/Id.js} +0 -0
  52. package/lib/cjs/Id.js.map +1 -0
  53. package/lib/{IndexMap.d.ts → cjs/IndexMap.d.ts} +0 -0
  54. package/lib/cjs/IndexMap.d.ts.map +1 -0
  55. package/lib/{IndexMap.js → cjs/IndexMap.js} +0 -0
  56. package/lib/cjs/IndexMap.js.map +1 -0
  57. package/lib/{JsonUtils.d.ts → cjs/JsonUtils.d.ts} +0 -0
  58. package/lib/cjs/JsonUtils.d.ts.map +1 -0
  59. package/lib/{JsonUtils.js → cjs/JsonUtils.js} +0 -0
  60. package/lib/cjs/JsonUtils.js.map +1 -0
  61. package/lib/{LRUMap.d.ts → cjs/LRUMap.d.ts} +0 -0
  62. package/lib/cjs/LRUMap.d.ts.map +1 -0
  63. package/lib/{LRUMap.js → cjs/LRUMap.js} +0 -0
  64. package/lib/cjs/LRUMap.js.map +1 -0
  65. package/lib/{Logger.d.ts → cjs/Logger.d.ts} +0 -0
  66. package/lib/cjs/Logger.d.ts.map +1 -0
  67. package/lib/{Logger.js → cjs/Logger.js} +4 -2
  68. package/lib/cjs/Logger.js.map +1 -0
  69. package/lib/{ObservableSet.d.ts → cjs/ObservableSet.d.ts} +0 -0
  70. package/lib/cjs/ObservableSet.d.ts.map +1 -0
  71. package/lib/{ObservableSet.js → cjs/ObservableSet.js} +0 -0
  72. package/lib/cjs/ObservableSet.js.map +1 -0
  73. package/lib/{OneAtATimeAction.d.ts → cjs/OneAtATimeAction.d.ts} +0 -0
  74. package/lib/cjs/OneAtATimeAction.d.ts.map +1 -0
  75. package/lib/{OneAtATimeAction.js → cjs/OneAtATimeAction.js} +0 -0
  76. package/lib/cjs/OneAtATimeAction.js.map +1 -0
  77. package/lib/{OrderedId64Iterable.d.ts → cjs/OrderedId64Iterable.d.ts} +0 -0
  78. package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -0
  79. package/lib/{OrderedId64Iterable.js → cjs/OrderedId64Iterable.js} +0 -0
  80. package/lib/cjs/OrderedId64Iterable.js.map +1 -0
  81. package/lib/{OrderedSet.d.ts → cjs/OrderedSet.d.ts} +0 -0
  82. package/lib/cjs/OrderedSet.d.ts.map +1 -0
  83. package/lib/{OrderedSet.js → cjs/OrderedSet.js} +0 -0
  84. package/lib/cjs/OrderedSet.js.map +1 -0
  85. package/lib/{PriorityQueue.d.ts → cjs/PriorityQueue.d.ts} +0 -0
  86. package/lib/cjs/PriorityQueue.d.ts.map +1 -0
  87. package/lib/{PriorityQueue.js → cjs/PriorityQueue.js} +0 -0
  88. package/lib/cjs/PriorityQueue.js.map +1 -0
  89. package/lib/{ProcessDetector.d.ts → cjs/ProcessDetector.d.ts} +0 -0
  90. package/lib/cjs/ProcessDetector.d.ts.map +1 -0
  91. package/lib/{ProcessDetector.js → cjs/ProcessDetector.js} +0 -0
  92. package/lib/cjs/ProcessDetector.js.map +1 -0
  93. package/lib/{SortedArray.d.ts → cjs/SortedArray.d.ts} +0 -0
  94. package/lib/cjs/SortedArray.d.ts.map +1 -0
  95. package/lib/{SortedArray.js → cjs/SortedArray.js} +0 -0
  96. package/lib/cjs/SortedArray.js.map +1 -0
  97. package/lib/{StringUtils.d.ts → cjs/StringUtils.d.ts} +0 -0
  98. package/lib/cjs/StringUtils.d.ts.map +1 -0
  99. package/lib/{StringUtils.js → cjs/StringUtils.js} +0 -0
  100. package/lib/cjs/StringUtils.js.map +1 -0
  101. package/lib/{Time.d.ts → cjs/Time.d.ts} +0 -0
  102. package/lib/cjs/Time.d.ts.map +1 -0
  103. package/lib/{Time.js → cjs/Time.js} +0 -0
  104. package/lib/cjs/Time.js.map +1 -0
  105. package/lib/{UtilityTypes.d.ts → cjs/UtilityTypes.d.ts} +0 -0
  106. package/lib/cjs/UtilityTypes.d.ts.map +1 -0
  107. package/lib/{UtilityTypes.js → cjs/UtilityTypes.js} +0 -0
  108. package/lib/cjs/UtilityTypes.js.map +1 -0
  109. package/lib/{core-bentley.d.ts → cjs/core-bentley.d.ts} +0 -0
  110. package/lib/cjs/core-bentley.d.ts.map +1 -0
  111. package/lib/{core-bentley.js → cjs/core-bentley.js} +0 -0
  112. package/lib/cjs/core-bentley.js.map +1 -0
  113. package/lib/{partitionArray.d.ts → cjs/partitionArray.d.ts} +0 -0
  114. package/lib/cjs/partitionArray.d.ts.map +1 -0
  115. package/lib/{partitionArray.js → cjs/partitionArray.js} +0 -0
  116. package/lib/cjs/partitionArray.js.map +1 -0
  117. package/lib/esm/AccessToken.d.ts +9 -0
  118. package/lib/esm/AccessToken.d.ts.map +1 -0
  119. package/lib/esm/AccessToken.js +9 -0
  120. package/lib/esm/AccessToken.js.map +1 -0
  121. package/lib/esm/Assert.d.ts +16 -0
  122. package/lib/esm/Assert.d.ts.map +1 -0
  123. package/lib/esm/Assert.js +23 -0
  124. package/lib/esm/Assert.js.map +1 -0
  125. package/lib/esm/AsyncMutex.d.ts +27 -0
  126. package/lib/esm/AsyncMutex.d.ts.map +1 -0
  127. package/lib/esm/AsyncMutex.js +40 -0
  128. package/lib/esm/AsyncMutex.js.map +1 -0
  129. package/lib/esm/BeEvent.d.ts +82 -0
  130. package/lib/esm/BeEvent.d.ts.map +1 -0
  131. package/lib/esm/BeEvent.js +145 -0
  132. package/lib/esm/BeEvent.js.map +1 -0
  133. package/lib/esm/BeSQLite.d.ts +171 -0
  134. package/lib/esm/BeSQLite.d.ts.map +1 -0
  135. package/lib/esm/BeSQLite.js +181 -0
  136. package/lib/esm/BeSQLite.js.map +1 -0
  137. package/lib/esm/BentleyError.d.ts +378 -0
  138. package/lib/esm/BentleyError.d.ts.map +1 -0
  139. package/lib/esm/BentleyError.js +698 -0
  140. package/lib/esm/BentleyError.js.map +1 -0
  141. package/lib/esm/BentleyLoggerCategory.d.ts +12 -0
  142. package/lib/esm/BentleyLoggerCategory.d.ts.map +1 -0
  143. package/lib/esm/BentleyLoggerCategory.js +17 -0
  144. package/lib/esm/BentleyLoggerCategory.js.map +1 -0
  145. package/lib/esm/ByteStream.d.ts +63 -0
  146. package/lib/esm/ByteStream.d.ts.map +1 -0
  147. package/lib/esm/ByteStream.js +88 -0
  148. package/lib/esm/ByteStream.js.map +1 -0
  149. package/lib/esm/Compare.d.ts +48 -0
  150. package/lib/esm/Compare.d.ts.map +1 -0
  151. package/lib/esm/Compare.js +52 -0
  152. package/lib/esm/Compare.js.map +1 -0
  153. package/lib/esm/CompressedId64Set.d.ts +135 -0
  154. package/lib/esm/CompressedId64Set.d.ts.map +1 -0
  155. package/lib/esm/CompressedId64Set.js +424 -0
  156. package/lib/esm/CompressedId64Set.js.map +1 -0
  157. package/lib/esm/Dictionary.d.ts +126 -0
  158. package/lib/esm/Dictionary.d.ts.map +1 -0
  159. package/lib/esm/Dictionary.js +200 -0
  160. package/lib/esm/Dictionary.js.map +1 -0
  161. package/lib/esm/Disposable.d.ts +81 -0
  162. package/lib/esm/Disposable.d.ts.map +1 -0
  163. package/lib/esm/Disposable.js +113 -0
  164. package/lib/esm/Disposable.js.map +1 -0
  165. package/lib/esm/Id.d.ts +274 -0
  166. package/lib/esm/Id.d.ts.map +1 -0
  167. package/lib/esm/Id.js +612 -0
  168. package/lib/esm/Id.js.map +1 -0
  169. package/lib/esm/IndexMap.d.ts +66 -0
  170. package/lib/esm/IndexMap.d.ts.map +1 -0
  171. package/lib/esm/IndexMap.js +87 -0
  172. package/lib/esm/IndexMap.js.map +1 -0
  173. package/lib/esm/JsonUtils.d.ts +79 -0
  174. package/lib/esm/JsonUtils.d.ts.map +1 -0
  175. package/lib/esm/JsonUtils.js +131 -0
  176. package/lib/esm/JsonUtils.js.map +1 -0
  177. package/lib/esm/LRUMap.d.ts +130 -0
  178. package/lib/esm/LRUMap.d.ts.map +1 -0
  179. package/lib/esm/LRUMap.js +327 -0
  180. package/lib/esm/LRUMap.js.map +1 -0
  181. package/lib/esm/Logger.d.ts +140 -0
  182. package/lib/esm/Logger.d.ts.map +1 -0
  183. package/lib/esm/Logger.js +245 -0
  184. package/lib/esm/Logger.js.map +1 -0
  185. package/lib/esm/ObservableSet.d.ts +24 -0
  186. package/lib/esm/ObservableSet.d.ts.map +1 -0
  187. package/lib/esm/ObservableSet.js +48 -0
  188. package/lib/esm/ObservableSet.js.map +1 -0
  189. package/lib/esm/OneAtATimeAction.d.ts +32 -0
  190. package/lib/esm/OneAtATimeAction.d.ts.map +1 -0
  191. package/lib/esm/OneAtATimeAction.js +87 -0
  192. package/lib/esm/OneAtATimeAction.js.map +1 -0
  193. package/lib/esm/OrderedId64Iterable.d.ts +75 -0
  194. package/lib/esm/OrderedId64Iterable.d.ts.map +1 -0
  195. package/lib/esm/OrderedId64Iterable.js +233 -0
  196. package/lib/esm/OrderedId64Iterable.js.map +1 -0
  197. package/lib/esm/OrderedSet.d.ts +41 -0
  198. package/lib/esm/OrderedSet.d.ts.map +1 -0
  199. package/lib/esm/OrderedSet.js +60 -0
  200. package/lib/esm/OrderedSet.js.map +1 -0
  201. package/lib/esm/PriorityQueue.d.ts +71 -0
  202. package/lib/esm/PriorityQueue.d.ts.map +1 -0
  203. package/lib/esm/PriorityQueue.js +137 -0
  204. package/lib/esm/PriorityQueue.js.map +1 -0
  205. package/lib/esm/ProcessDetector.d.ts +60 -0
  206. package/lib/esm/ProcessDetector.d.ts.map +1 -0
  207. package/lib/esm/ProcessDetector.js +68 -0
  208. package/lib/esm/ProcessDetector.js.map +1 -0
  209. package/lib/esm/SortedArray.d.ts +233 -0
  210. package/lib/esm/SortedArray.d.ts.map +1 -0
  211. package/lib/esm/SortedArray.js +295 -0
  212. package/lib/esm/SortedArray.js.map +1 -0
  213. package/lib/esm/StringUtils.d.ts +23 -0
  214. package/lib/esm/StringUtils.d.ts.map +1 -0
  215. package/lib/esm/StringUtils.js +141 -0
  216. package/lib/esm/StringUtils.js.map +1 -0
  217. package/lib/esm/Time.d.ts +123 -0
  218. package/lib/esm/Time.d.ts.map +1 -0
  219. package/lib/esm/Time.js +141 -0
  220. package/lib/esm/Time.js.map +1 -0
  221. package/lib/esm/UtilityTypes.d.ts +75 -0
  222. package/lib/esm/UtilityTypes.d.ts.map +1 -0
  223. package/lib/esm/UtilityTypes.js +22 -0
  224. package/lib/esm/UtilityTypes.js.map +1 -0
  225. package/lib/esm/core-bentley.d.ts +71 -0
  226. package/lib/esm/core-bentley.d.ts.map +1 -0
  227. package/lib/esm/core-bentley.js +75 -0
  228. package/lib/esm/core-bentley.js.map +1 -0
  229. package/lib/esm/partitionArray.d.ts +22 -0
  230. package/lib/esm/partitionArray.d.ts.map +1 -0
  231. package/lib/esm/partitionArray.js +40 -0
  232. package/lib/esm/partitionArray.js.map +1 -0
  233. package/package.json +9 -6
  234. package/lib/AccessToken.d.ts.map +0 -1
  235. package/lib/AccessToken.js.map +0 -1
  236. package/lib/Assert.d.ts.map +0 -1
  237. package/lib/Assert.js.map +0 -1
  238. package/lib/AsyncMutex.d.ts.map +0 -1
  239. package/lib/AsyncMutex.js.map +0 -1
  240. package/lib/BeEvent.d.ts.map +0 -1
  241. package/lib/BeEvent.js.map +0 -1
  242. package/lib/BeSQLite.d.ts.map +0 -1
  243. package/lib/BeSQLite.js.map +0 -1
  244. package/lib/BentleyError.d.ts.map +0 -1
  245. package/lib/BentleyError.js.map +0 -1
  246. package/lib/BentleyLoggerCategory.d.ts.map +0 -1
  247. package/lib/BentleyLoggerCategory.js.map +0 -1
  248. package/lib/ByteStream.d.ts.map +0 -1
  249. package/lib/ByteStream.js.map +0 -1
  250. package/lib/Compare.d.ts.map +0 -1
  251. package/lib/Compare.js.map +0 -1
  252. package/lib/CompressedId64Set.d.ts.map +0 -1
  253. package/lib/CompressedId64Set.js.map +0 -1
  254. package/lib/Dictionary.d.ts.map +0 -1
  255. package/lib/Dictionary.js.map +0 -1
  256. package/lib/Disposable.d.ts.map +0 -1
  257. package/lib/Disposable.js.map +0 -1
  258. package/lib/Id.d.ts.map +0 -1
  259. package/lib/Id.js.map +0 -1
  260. package/lib/IndexMap.d.ts.map +0 -1
  261. package/lib/IndexMap.js.map +0 -1
  262. package/lib/JsonUtils.d.ts.map +0 -1
  263. package/lib/JsonUtils.js.map +0 -1
  264. package/lib/LRUMap.d.ts.map +0 -1
  265. package/lib/LRUMap.js.map +0 -1
  266. package/lib/Logger.d.ts.map +0 -1
  267. package/lib/Logger.js.map +0 -1
  268. package/lib/ObservableSet.d.ts.map +0 -1
  269. package/lib/ObservableSet.js.map +0 -1
  270. package/lib/OneAtATimeAction.d.ts.map +0 -1
  271. package/lib/OneAtATimeAction.js.map +0 -1
  272. package/lib/OrderedId64Iterable.d.ts.map +0 -1
  273. package/lib/OrderedId64Iterable.js.map +0 -1
  274. package/lib/OrderedSet.d.ts.map +0 -1
  275. package/lib/OrderedSet.js.map +0 -1
  276. package/lib/PriorityQueue.d.ts.map +0 -1
  277. package/lib/PriorityQueue.js.map +0 -1
  278. package/lib/ProcessDetector.d.ts.map +0 -1
  279. package/lib/ProcessDetector.js.map +0 -1
  280. package/lib/SortedArray.d.ts.map +0 -1
  281. package/lib/SortedArray.js.map +0 -1
  282. package/lib/StringUtils.d.ts.map +0 -1
  283. package/lib/StringUtils.js.map +0 -1
  284. package/lib/Time.d.ts.map +0 -1
  285. package/lib/Time.js.map +0 -1
  286. package/lib/UtilityTypes.d.ts.map +0 -1
  287. package/lib/UtilityTypes.js.map +0 -1
  288. package/lib/core-bentley.d.ts.map +0 -1
  289. package/lib/core-bentley.js.map +0 -1
  290. package/lib/partitionArray.d.ts.map +0 -1
  291. package/lib/partitionArray.js.map +0 -1
@@ -0,0 +1,126 @@
1
+ /** @packageDocumentation
2
+ * @module Collections
3
+ */
4
+ import { OrderedComparator } from "./Compare";
5
+ import { CloneFunction } from "./SortedArray";
6
+ /**
7
+ * Represents an entry in a [[Dictionary]].
8
+ * @public
9
+ */
10
+ export interface DictionaryEntry<K, V> {
11
+ /** The key used for lookup in the Dictionary. */
12
+ key: K;
13
+ /** The value associated with the key in the Dictionary. */
14
+ value: V;
15
+ }
16
+ /**
17
+ * Maintains a mapping of keys to values.
18
+ * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).
19
+ * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:
20
+ * - If lhs is equal to rhs, returns 0
21
+ * - If lhs is less than rhs, returns a negative value
22
+ * - If lhs is greater than rhs, returns a positive value
23
+ * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0
24
+ * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.
25
+ *
26
+ * Modifying a key in a way that affects the comparison function will produce unpredictable results, the
27
+ * most likely of which is that keys will cease to map to the values with which they were initially inserted.
28
+ * @public
29
+ */
30
+ export declare class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {
31
+ protected _keys: K[];
32
+ protected readonly _compareKeys: OrderedComparator<K>;
33
+ protected readonly _cloneKey: CloneFunction<K>;
34
+ protected _values: V[];
35
+ protected readonly _cloneValue: CloneFunction<V>;
36
+ /**
37
+ * Construct a new Dictionary<K, V>.
38
+ * @param compareKeys The function used to compare keys within the dictionary.
39
+ * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.
40
+ * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.
41
+ */
42
+ constructor(compareKeys: OrderedComparator<K>, cloneKey?: CloneFunction<K>, cloneValue?: CloneFunction<V>);
43
+ /** The number of entries in the dictionary. */
44
+ get size(): number;
45
+ /** 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. */
46
+ [Symbol.iterator](): Iterator<DictionaryEntry<K, V>>;
47
+ /** Provides iteration over the keys in this Dictionary, in sorted order. */
48
+ keys(): Iterable<K>;
49
+ /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */
50
+ values(): Iterable<V>;
51
+ /** Removes all entries from this dictionary */
52
+ clear(): void;
53
+ /**
54
+ * Looks up a value by its key.
55
+ * @param key The key to search for
56
+ * @returns the value associated with the key, or undefined if the key is not present in the dictionary.
57
+ */
58
+ get(key: K): V | undefined;
59
+ /**
60
+ * Determines if an entry exists for the specified key
61
+ * @param key The key to search for
62
+ * @returns true if an entry exists in this dictionary corresponding to the specified key.
63
+ */
64
+ has(key: K): boolean;
65
+ /**
66
+ * Deletes a value using its key.
67
+ * @param key The key to delete
68
+ * @returns true if the key was found and deleted.
69
+ */
70
+ delete(key: K): boolean;
71
+ /**
72
+ * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.
73
+ * 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.
74
+ * @param key The key to associate with the value
75
+ * @param value The value to associate with the key
76
+ * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.
77
+ */
78
+ insert(key: K, value: V): boolean;
79
+ /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.
80
+ * @param key The key to search for.
81
+ * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.
82
+ * @returns The found or inserted value and a flag indicating whether the new value was inserted.
83
+ */
84
+ findOrInsert(key: K, value: V): {
85
+ value: V;
86
+ inserted: boolean;
87
+ };
88
+ /**
89
+ * Sets the value associated with the specified key in the dictionary.
90
+ * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.
91
+ * In either case, the value will be cloned using the function supplied to the dictionary's constructor.
92
+ */
93
+ set(key: K, value: V): void;
94
+ /**
95
+ * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.
96
+ * @returns An array of { key, value } pairs sorted by key.
97
+ */
98
+ extractPairs(): Array<{
99
+ key: K;
100
+ value: V;
101
+ }>;
102
+ /**
103
+ * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.
104
+ * The array of keys is sorted according to the comparison criterion.
105
+ * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.
106
+ * @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.
107
+ */
108
+ extractArrays(): {
109
+ keys: K[];
110
+ values: V[];
111
+ };
112
+ /** Apply a function to each (key, value) pair in the dictionary, in sorted order.
113
+ * @param func The function to be applied.
114
+ */
115
+ forEach(func: (key: K, value: V) => void): void;
116
+ /**
117
+ * Computes the position at which the specified key should be inserted to maintain sorted order.
118
+ * @param key The key whose position is to be computed.
119
+ * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.
120
+ */
121
+ protected lowerBound(key: K): {
122
+ index: number;
123
+ equal: boolean;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,CAAC,CAAC,CAAC;IAW1B,wGAAwG;IACjG,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC;IAW5B,+CAA+C;IACxC,KAAK,IAAI,IAAI;IAKpB;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAKjC;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAI3B;;;;OAIG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAW9B;;;;;;OAMG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO;IAKxC;;;;OAIG;IACI,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE;IAWtE;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAWlC;;;OAGG;IACI,YAAY,IAAI,KAAK,CAAC;QAAE,GAAG,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAAC;IASlD;;;;;OAKG;IACI,aAAa,IAAI;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,MAAM,EAAE,CAAC,EAAE,CAAA;KAAE;IAMlD;;OAEG;IACI,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI;IAKtD;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAChE"}
@@ -0,0 +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
+ }
200
+ //# sourceMappingURL=Dictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dictionary.js","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAiB,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,kBAAkB;IAKtB,YAAmB,IAAS,EAAE,MAAW;QAFjC,cAAS,GAAG,CAAC,CAAC,CAAC;QAEsB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAAC,CAAC;IAEjF,IAAI;QACT,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACzC,0JAA0J;YAC1J,OAAO,EAAE,IAAI,EAAE,IAAI,EAAkD,CAAC;SACvE;aAAM;YACL,OAAO;gBACL,KAAK,EAAE;oBACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;iBACpC;gBACD,IAAI,EAAE,KAAK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AE7D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,aAAa;QAClB,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAgC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAM,IAAuC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Collections\n */\n\nimport { OrderedComparator } from \"./Compare\";\nimport { CloneFunction, lowerBound, shallowClone } from \"./SortedArray\";\n\nclass DictionaryIterator<K, V> implements Iterator<DictionaryEntry<K, V>> {\n private _keys: K[];\n private _values: V[];\n private _curIndex = -1;\n\n public constructor(keys: K[], values: V[]) { this._keys = keys; this._values = values; }\n\n public next(): IteratorResult<DictionaryEntry<K, V>> {\n if (++this._curIndex >= this._keys.length) {\n // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.\n return { done: true } as any as IteratorResult<DictionaryEntry<K, V>>;\n } else {\n return {\n value: {\n key: this._keys[this._curIndex],\n value: this._values[this._curIndex],\n },\n done: false,\n };\n }\n }\n}\n\n/**\n * Represents an entry in a [[Dictionary]].\n * @public\n */\nexport interface DictionaryEntry<K, V> {\n /** The key used for lookup in the Dictionary. */\n key: K;\n /** The value associated with the key in the Dictionary. */\n value: V;\n}\n\n/**\n * Maintains a mapping of keys to values.\n * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).\n * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:\n * - If lhs is equal to rhs, returns 0\n * - If lhs is less than rhs, returns a negative value\n * - If lhs is greater than rhs, returns a positive value\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\n *\n * Modifying a key in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that keys will cease to map to the values with which they were initially inserted.\n * @public\n */\nexport class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {\n protected _keys: K[] = [];\n protected readonly _compareKeys: OrderedComparator<K>;\n protected readonly _cloneKey: CloneFunction<K>;\n protected _values: V[] = [];\n protected readonly _cloneValue: CloneFunction<V>;\n\n /**\n * Construct a new Dictionary<K, V>.\n * @param compareKeys The function used to compare keys within the dictionary.\n * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.\n * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.\n */\n public constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone) {\n this._compareKeys = compareKeys;\n this._cloneKey = cloneKey;\n this._cloneValue = cloneValue;\n }\n\n /** The number of entries in the dictionary. */\n public get size(): number { return this._keys.length; }\n\n /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */\n public [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> {\n return new DictionaryIterator<K, V>(this._keys, this._values);\n }\n\n /** Provides iteration over the keys in this Dictionary, in sorted order. */\n public keys(): Iterable<K> {\n function * iterator(dict: Dictionary<K, V>) {\n for (const entry of dict)\n yield entry.key;\n }\n\n return {\n [Symbol.iterator]: () => iterator(this),\n };\n }\n\n /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */\n public values(): Iterable<V> {\n function * iterator(dict: Dictionary<K, V>) {\n for (const entry of dict)\n yield entry.value;\n }\n\n return {\n [Symbol.iterator]: () => iterator(this),\n };\n }\n\n /** Removes all entries from this dictionary */\n public clear(): void {\n this._keys = [];\n this._values = [];\n }\n\n /**\n * Looks up a value by its key.\n * @param key The key to search for\n * @returns the value associated with the key, or undefined if the key is not present in the dictionary.\n */\n public get(key: K): V | undefined {\n const bound = this.lowerBound(key);\n return bound.equal ? this._values[bound.index] : undefined;\n }\n\n /**\n * Determines if an entry exists for the specified key\n * @param key The key to search for\n * @returns true if an entry exists in this dictionary corresponding to the specified key.\n */\n public has(key: K): boolean {\n return this.lowerBound(key).equal;\n }\n\n /**\n * Deletes a value using its key.\n * @param key The key to delete\n * @returns true if the key was found and deleted.\n */\n public delete(key: K): boolean {\n const bound = this.lowerBound(key);\n if (bound.equal) {\n this._values.splice(bound.index, 1);\n this._keys.splice(bound.index, 1);\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.\n * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.\n * @param key The key to associate with the value\n * @param value The value to associate with the key\n * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.\n */\n public insert(key: K, value: V): boolean {\n const result = this.findOrInsert(key, value);\n return result.inserted;\n }\n\n /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.\n * @param key The key to search for.\n * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.\n * @returns The found or inserted value and a flag indicating whether the new value was inserted.\n */\n public findOrInsert(key: K, value: V): { value: V, inserted: boolean } {\n const bound = this.lowerBound(key);\n if (bound.equal)\n return { value: this._values[bound.index], inserted: false };\n\n value = this._cloneValue(value);\n this._keys.splice(bound.index, 0, this._cloneKey(key));\n this._values.splice(bound.index, 0, this._cloneValue(value));\n return { value, inserted: true };\n }\n\n /**\n * Sets the value associated with the specified key in the dictionary.\n * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.\n * In either case, the value will be cloned using the function supplied to the dictionary's constructor.\n */\n public set(key: K, value: V): void {\n value = this._cloneValue(value);\n const bound = this.lowerBound(key);\n if (bound.equal) {\n this._values[bound.index] = value;\n } else {\n this._keys.splice(bound.index, 0, this._cloneKey(key));\n this._values.splice(bound.index, 0, value);\n }\n }\n\n /**\n * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.\n * @returns An array of { key, value } pairs sorted by key.\n */\n public extractPairs(): Array<{ key: K, value: V }> {\n const pairs: Array<{ key: K, value: V }> = [];\n for (let i = 0; i < this.size; i++)\n pairs.push({ key: this._keys[i], value: this._values[i] });\n\n this.clear();\n return pairs;\n }\n\n /**\n * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.\n * The array of keys is sorted according to the comparison criterion.\n * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.\n * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.\n */\n public extractArrays(): { keys: K[], values: V[] } {\n const result = { keys: this._keys, values: this._values };\n this.clear();\n return result;\n }\n\n /** Apply a function to each (key, value) pair in the dictionary, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (key: K, value: V) => void): void {\n for (let i = 0; i < this.size; i++)\n func(this._keys[i], this._values[i]);\n }\n\n /**\n * Computes the position at which the specified key should be inserted to maintain sorted order.\n * @param key The key whose position is to be computed.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.\n */\n protected lowerBound(key: K): { index: number, equal: boolean } { return lowerBound(key, this._keys, this._compareKeys); }\n}\n"]}
@@ -0,0 +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 by imodel.js.
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
+ }
81
+ //# sourceMappingURL=Disposable.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,113 @@
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 Utils
7
+ */
8
+ /**
9
+ * A type guard that checks whether the given argument implements `IDisposable` interface
10
+ * @public
11
+ */
12
+ export function isIDisposable(obj) {
13
+ // eslint-disable-next-line @typescript-eslint/unbound-method
14
+ return !!obj && (obj instanceof Object) && !!obj.dispose && (typeof obj.dispose === "function");
15
+ }
16
+ /** Convenience function for disposing of a disposable object that may be undefined.
17
+ * This is primarily used to simplify implementations of [[IDisposable.dispose]].
18
+ * As a simple example:
19
+ * ```ts
20
+ * class Disposable implements IDisposable {
21
+ * public member1?: DisposableType1;
22
+ * public member2?: DisposableType2;
23
+ *
24
+ * public dispose() {
25
+ * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
26
+ * this.member2 = dispose(this.member2); // Likewise for member2.
27
+ * }
28
+ * }
29
+ * ```
30
+ * @param disposable The object to be disposed of.
31
+ * @returns undefined
32
+ * @public
33
+ */
34
+ export function dispose(disposable) {
35
+ if (undefined !== disposable)
36
+ disposable.dispose();
37
+ return undefined;
38
+ }
39
+ /** Disposes of and empties a list of disposable objects.
40
+ * @param list The list of disposable objects.
41
+ * @returns undefined
42
+ * @public
43
+ */
44
+ export function disposeArray(list) {
45
+ if (undefined === list)
46
+ return undefined;
47
+ for (const entry of list)
48
+ dispose(entry);
49
+ list.length = 0;
50
+ return undefined;
51
+ }
52
+ /** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'
53
+ * is called on the resource no matter if the func returns or throws. If func returns, the return value
54
+ * of this function is equal to return value of func. If func throws, this function also throws (after
55
+ * disposing the resource).
56
+ * @public
57
+ */
58
+ export function using(resources, func) {
59
+ if (!Array.isArray(resources))
60
+ return using([resources], func);
61
+ const doDispose = () => resources.forEach((disposable) => disposable.dispose());
62
+ let shouldDisposeImmediately = true;
63
+ try {
64
+ const result = func(...resources);
65
+ if (result instanceof Promise) {
66
+ shouldDisposeImmediately = false;
67
+ result.then(doDispose, doDispose);
68
+ }
69
+ return result;
70
+ }
71
+ finally {
72
+ if (shouldDisposeImmediately)
73
+ doDispose();
74
+ }
75
+ }
76
+ class FuncDisposable {
77
+ constructor(disposeFunc) { this._disposeFunc = disposeFunc; }
78
+ dispose() { this._disposeFunc(); }
79
+ }
80
+ /** A disposable container of disposable objects.
81
+ * @public
82
+ */
83
+ export class DisposableList {
84
+ /** Creates a disposable list. */
85
+ constructor(disposables = []) {
86
+ this._disposables = [];
87
+ disposables.forEach((disposable) => {
88
+ this.add(disposable);
89
+ });
90
+ }
91
+ isDisposable(x) {
92
+ return x.dispose !== undefined;
93
+ }
94
+ /** Register an object for disposal. */
95
+ add(disposable) {
96
+ if (this.isDisposable(disposable))
97
+ this._disposables.push(disposable);
98
+ else
99
+ this._disposables.push(new FuncDisposable(disposable));
100
+ }
101
+ /** Unregister disposable object. */
102
+ remove(disposable) {
103
+ const idx = this._disposables.indexOf(disposable);
104
+ if (-1 !== idx)
105
+ this._disposables.splice(idx, 1);
106
+ }
107
+ /** Disposes all registered objects. */
108
+ dispose() {
109
+ for (const disposable of this._disposables)
110
+ disposable.dispose();
111
+ }
112
+ }
113
+ //# sourceMappingURL=Disposable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwBH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,6DAA6D;IAC7D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,YAAY,MAAM,CAAC,IAAI,CAAC,CAAE,GAAmB,CAAC,OAAO,IAAI,CAAC,OAAQ,GAAmB,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;AACpI,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,UAAwB;IAC9C,IAAI,SAAS,KAAK,UAAU;QAC1B,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,IAAI,SAAS,KAAK,IAAI;QACpB,OAAO,SAAS,CAAC;IAEnB,KAAK,MAAM,KAAK,IAAI,IAAI;QACtB,OAAO,CAAC,KAAK,CAAC,CAAC;IAEjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAChB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAiC,SAAkB,EAAE,IAA4B;IACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO,KAAK,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,SAAS,GAAG,GAAG,EA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;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,GAAG;YACZ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY;YACxC,UAAU,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/** Interface adopted by a type which has deterministic cleanup logic.\n * For example:\n * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.\n * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.\n *\n * A similar concept exists in languages like C++ (implemented as \"destructors\") and C# (\"IDisposable\").\n * 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.\n * Failure to do so may result in memory leaks or leaking of other resources.\n *\n * 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.\n *\n * Implementations of IDisposable tend to be more \"low-level\" types. The disposal of such types is often handled on your behalf by imodel.js.\n * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.\n * @public\n */\nexport interface IDisposable {\n /** Disposes of any resources owned by this object.\n * @note The object is generally considered unusable after it has been disposed of.\n */\n dispose(): void;\n}\n\n/**\n * A type guard that checks whether the given argument implements `IDisposable` interface\n * @public\n */\nexport function isIDisposable(obj: unknown): obj is IDisposable {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n return !!obj && (obj instanceof Object) && !!(obj as IDisposable).dispose && (typeof (obj as IDisposable).dispose === \"function\");\n}\n\n/** Convenience function for disposing of a disposable object that may be undefined.\n * This is primarily used to simplify implementations of [[IDisposable.dispose]].\n * As a simple example:\n * ```ts\n * class Disposable implements IDisposable {\n * public member1?: DisposableType1;\n * public member2?: DisposableType2;\n *\n * public dispose() {\n * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.\n * this.member2 = dispose(this.member2); // Likewise for member2.\n * }\n * }\n * ```\n * @param disposable The object to be disposed of.\n * @returns undefined\n * @public\n */\nexport function dispose(disposable?: IDisposable): undefined {\n if (undefined !== disposable)\n disposable.dispose();\n return undefined;\n}\n\n/** Disposes of and empties a list of disposable objects.\n * @param list The list of disposable objects.\n * @returns undefined\n * @public\n */\nexport function disposeArray(list?: IDisposable[]): undefined {\n if (undefined === list)\n return undefined;\n\n for (const entry of list)\n dispose(entry);\n\n list.length = 0;\n return undefined;\n}\n\n/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'\n * is called on the resource no matter if the func returns or throws. If func returns, the return value\n * of this function is equal to return value of func. If func throws, this function also throws (after\n * disposing the resource).\n * @public\n */\nexport function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult {\n if (!Array.isArray(resources))\n return using([resources], func);\n\n const doDispose = () => resources.forEach((disposable) => disposable.dispose());\n let shouldDisposeImmediately = true;\n\n try {\n const result = func(...resources);\n if (result instanceof Promise) {\n shouldDisposeImmediately = false;\n result.then(doDispose, doDispose);\n }\n return result;\n } finally {\n if (shouldDisposeImmediately)\n doDispose();\n }\n}\n\n/** A definition of function which may be called to dispose an object\n * @public\n */\nexport type DisposeFunc = () => void;\n\nclass FuncDisposable implements IDisposable {\n private _disposeFunc: () => void;\n constructor(disposeFunc: () => void) { this._disposeFunc = disposeFunc; }\n public dispose() { this._disposeFunc(); }\n}\n\n/** A disposable container of disposable objects.\n * @public\n */\nexport class DisposableList implements IDisposable {\n private _disposables: IDisposable[];\n\n /** Creates a disposable list. */\n constructor(disposables: Array<IDisposable | DisposeFunc> = []) {\n this._disposables = [];\n disposables.forEach((disposable) => {\n this.add(disposable);\n });\n }\n\n private isDisposable(x: IDisposable | DisposeFunc): x is IDisposable {\n return (x as IDisposable).dispose !== undefined;\n }\n\n /** Register an object for disposal. */\n public add(disposable: IDisposable | DisposeFunc) {\n if (this.isDisposable(disposable))\n this._disposables.push(disposable);\n else\n this._disposables.push(new FuncDisposable(disposable));\n }\n\n /** Unregister disposable object. */\n public remove(disposable: IDisposable): void {\n const idx = this._disposables.indexOf(disposable);\n if (-1 !== idx)\n this._disposables.splice(idx, 1);\n }\n\n /** Disposes all registered objects. */\n public dispose(): void {\n for (const disposable of this._disposables)\n disposable.dispose();\n }\n}\n"]}