@itwin/core-bentley 3.7.0-dev.1 → 3.7.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -12,6 +12,13 @@ Wed, 08 Feb 2023 14:58:39 GMT
12
12
  - Added TransientIdSequence.peekNext to preview the next Id in the sequence.
13
13
  - Deprecate TransientIdSequence.next property in favor of getNext method.
14
14
 
15
+ ## 3.5.6
16
+ Fri, 24 Feb 2023 16:02:47 GMT
17
+
18
+ ### Updates
19
+
20
+ - Add SortedArray.slice.
21
+
15
22
  ## 3.5.5
16
23
  Thu, 26 Jan 2023 22:53:27 GMT
17
24
 
@@ -874,7 +881,7 @@ Thu, 28 May 2020 22:48:59 GMT
874
881
  ### Updates
875
882
 
876
883
  - Added FailedToGetProductSettings error
877
- - Setup Guid.normalize() for internal use.
884
+ - Setup Guid.normalize() for internal use.
878
885
  - channel rules
879
886
 
880
887
  ## 2.0.0
@@ -882,12 +889,12 @@ Wed, 06 May 2020 13:17:49 GMT
882
889
 
883
890
  ### Updates
884
891
 
885
- - Monitor progress of downloading briefcases, ability to cancel download of briefcases.
892
+ - Monitor progress of downloading briefcases, ability to cancel download of briefcases.
886
893
  - Update Config.App documentation to reflect the removal of the config.json file
887
894
  - Added ContextDoesNotExist error
888
895
  - BUG273249
889
- - Updated docs.
890
- - Updated error text.
896
+ - Updated docs.
897
+ - Updated error text.
891
898
  - added raw log method that bypass catogory check
892
899
  - order imports.
893
900
  - Add a type guard for `IDisposable`
@@ -921,7 +928,7 @@ Wed, 22 Jan 2020 19:24:11 GMT
921
928
 
922
929
  ### Updates
923
930
 
924
- - VSS$257397: Temporary fix for checking electron renderer.
931
+ - VSS$257397: Temporary fix for checking electron renderer.
925
932
  - Upgrade to TypeScript 3.7.2.
926
933
 
927
934
  ## 1.10.0
@@ -936,7 +943,7 @@ Tue, 10 Dec 2019 18:08:56 GMT
936
943
 
937
944
  ### Updates
938
945
 
939
- - Setup OidcDesktopClient for Electron use cases.
946
+ - Setup OidcDesktopClient for Electron use cases.
940
947
  - Added non-static wait and executeAfter to BeDuration
941
948
  - Fix warnings from static analysis
942
949
  - Added `BeDuration.race` for common timeout operations.
@@ -989,7 +996,7 @@ Mon, 01 Jul 2019 19:04:29 GMT
989
996
  ### Updates
990
997
 
991
998
  - Added OneAtATimeActivity class
992
- - Introduced AsyncMutex - a utility to run async blocks of code in sequence.
999
+ - Introduced AsyncMutex - a utility to run async blocks of code in sequence.
993
1000
  - Update to TypeScript 3.5
994
1001
 
995
1002
  ## 1.0.0
@@ -1016,10 +1023,10 @@ Mon, 13 May 2019 15:52:05 GMT
1016
1023
  - Logged the fields in ClientRequestContext
1017
1024
  - Logging fixes.
1018
1025
  - Put sourcemap in npm package.
1019
- - Fixed logger to not mutate incoming objects.
1026
+ - Fixed logger to not mutate incoming objects.
1020
1027
  - Improved performance logging
1021
1028
  - Added functions for iterating and obtaining the number of elements of a collection of Id64s represented as an Id64Arg.
1022
- - Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
1029
+ - Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
1023
1030
  - Use TextDecoder to decode binary utf-8 strings if supported.
1024
1031
  - Upgrade TypeDoc dependency to 0.14.2
1025
1032
 
@@ -1055,7 +1062,7 @@ Mon, 14 Jan 2019 23:09:10 GMT
1055
1062
 
1056
1063
  ### Updates
1057
1064
 
1058
- - Removed IModelDb's cache of accessToken. For long running operations like AutoPush, the user must explicitly supply an IAccessTokenManager to keep the token current.
1065
+ - Removed IModelDb's cache of accessToken. For long running operations like AutoPush, the user must explicitly supply an IAccessTokenManager to keep the token current.
1059
1066
 
1060
1067
  ## 0.185.0
1061
1068
  Fri, 11 Jan 2019 18:29:00 GMT
@@ -1162,7 +1169,7 @@ Fri, 16 Nov 2018 21:45:44 GMT
1162
1169
 
1163
1170
  ### Updates
1164
1171
 
1165
- - Changes to debug utilities.
1172
+ - Changes to debug utilities.
1166
1173
  - Fluentd Bunnyan Logger added
1167
1174
 
1168
1175
  ## 0.166.0
@@ -128,6 +128,8 @@ export declare class ReadonlySortedArray<T> implements Iterable<T> {
128
128
  * @param func The function to be applied.
129
129
  */
130
130
  forEach(func: (value: T) => void): void;
131
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
132
+ slice(start?: number, end?: number): ReadonlySortedArray<T>;
131
133
  /**
132
134
  * Computes the position at which the specified value should be inserted to maintain sorted order.
133
135
  * @param value The value whose position is to be computed.
@@ -229,5 +231,7 @@ export declare class SortedArray<T> extends ReadonlySortedArray<T> {
229
231
  * @returns the index of the deleted value, or -1 if no such element exists.
230
232
  */
231
233
  remove(value: T): number;
234
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
235
+ slice(start?: number, end?: number): SortedArray<T>;
232
236
  }
233
237
  //# sourceMappingURL=SortedArray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.d.ts","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAEvC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAE7H;A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AAK,GAAG,GAAG,MAAM;IAuBjE;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;CASpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACxD;;;;;OAKG;gBACgB,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,eAAe,GAAG,OAAe,EAAE,KAAK,GAAE,aAAa,CAAC,CAAC,CAAgB;IAI5I,+CAA+C;IACxC,KAAK,IAAI,IAAI;IAEpB;;OAEG;IACI,YAAY,IAAI,CAAC,EAAE;IAE1B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,MAAM;IAE7D;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;IAE/B,qIAAqI;IACrH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;CAKpE"}
@@ -168,6 +168,12 @@ class ReadonlySortedArray {
168
168
  for (let i = 0; i < this.length; i++)
169
169
  func(this._array[i]);
170
170
  }
171
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
172
+ slice(start, end) {
173
+ const slice = new ReadonlySortedArray(this._compare, this._duplicatePolicy, this._clone);
174
+ slice._array = this._array.slice(start, end);
175
+ return slice;
176
+ }
171
177
  /**
172
178
  * Computes the position at which the specified value should be inserted to maintain sorted order.
173
179
  * @param value The value whose position is to be computed.
@@ -299,6 +305,12 @@ class SortedArray extends ReadonlySortedArray {
299
305
  * @returns the index of the deleted value, or -1 if no such element exists.
300
306
  */
301
307
  remove(value) { return this._remove(value); }
308
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
309
+ slice(start, end) {
310
+ const slice = new SortedArray(this._compare, this._duplicatePolicy, this._clone);
311
+ slice._array = this._array.slice(start, end);
312
+ return slice;
313
+ }
302
314
  }
303
315
  exports.SortedArray = SortedArray;
304
316
  //# sourceMappingURL=SortedArray.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAWH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAI,KAAQ;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,oCAEC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAW,KAAQ,EAAE,IAAS,EAAE,OAAgC;IACxF,OAAO,sBAAsB,CAAC,IAAI,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAFD,gCAEC;AAED,SAAS,sBAAsB,CAAI,IAAS,EAAE,SAAiC;IAC7E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,IAAI;YACZ,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aAChC,IAAI,IAAI,GAAG,CAAC;YACf,IAAI,GAAG,GAAG,CAAC;;YAEX,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;KACj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KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACO,OAAO,CAAC,KAAQ;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;aAAM;YACL,OAAO,CAAC,CAAC,CAAC;SACX;IACH,CAAC;CACF;AA7KD,kDA6KC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,WAAe,SAAQ,mBAAsB;IACxD;;;;;OAKG;IACH,YAAmB,OAA6B,EAAE,kBAA6C,KAAK,EAAE,QAA0B,YAAY;QAC1I,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,+CAA+C;IACxC,KAAK,KAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEvC;;OAEG;IACI,YAAY,KAAU,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAQ,EAAE,QAA4B,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvG;;;;OAIG;IACI,MAAM,CAAC,KAAQ,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAChE;AA1CD,kCA0CC","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\";\n\n/**\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\n * @public\n */\nexport type CloneFunction<T> = (value: T) => T;\n\n/**\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\n * @param value The value to clone.\n * @returns the input value.\n * @public\n */\nexport function shallowClone<T>(value: T) {\n return value;\n}\n\n/**\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\n * @param value The value whose position is to be computed.\n * @param list An array of U already sorted according to the comparison criterion.\n * @param compare The function used to compare the value with elements in `list`.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\n * @public\n */\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\n}\n\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\n let low = 0;\n let high = list.length;\n while (low < high) {\n const mid = Math.floor((low + high) / 2);\n const comp = criterion(list[mid]);\n if (0 === comp)\n return { index: mid, equal: true };\n else if (comp < 0)\n high = mid;\n else\n low = mid + 1;\n }\n\n return { index: low, equal: false };\n}\n\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\n * @public\n */\nexport enum DuplicatePolicy {\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\n */\n Allow,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\n Retain,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\n */\n Replace,\n}\n\n/**\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\n *\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\n * @public\n */\nexport class ReadonlySortedArray<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n protected readonly _duplicatePolicy: DuplicatePolicy;\n\n /**\n * Construct a new ReadonlySortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n if (typeof duplicatePolicy === \"boolean\")\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\n\n this._duplicatePolicy = duplicatePolicy;\n }\n\n /** The number of elements in the array */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the array contains no elements. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n /**\n * Looks up the index of an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\n */\n public indexOf(value: T): number {\n const bound = this.lowerBound(value);\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Returns true if this array contains at least one value comparing equal to the specified value.\n * @param value The value to search for\n * @returns true if an equivalent element exists in the array.\n */\n public contains(value: T): boolean {\n return -1 !== this.indexOf(value);\n }\n\n /**\n * Looks up an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\n */\n public findEqual(value: T): T | undefined {\n const index = this.indexOf(value);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\n * @see [[indexOfEquivalent]].\n * @public\n */\n public findEquivalent(criterion: (element: T) => number): T | undefined {\n const index = this.indexOfEquivalent(criterion);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\n * @public\n */\n public indexOfEquivalent(criterion: (element: T) => number): number {\n // NB: Must invert the ordering.\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Looks up an element by its index in the array.\n * @param index The array index\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\n */\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\n\n /** Apply a function to each element in the array, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (value: T) => void): void {\n for (let i = 0; i < this.length; i++)\n func(this._array[i]);\n }\n\n /**\n * Computes the position at which the specified value should be inserted to maintain sorted order.\n * @param value The value 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 element already exists at that index.\n */\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\n\n /** Clears the contents of the sorted array. */\n protected _clear(): void { this._array.length = 0; }\n\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\n * @returns the contents of this ReadonlySortedArray as a T[].\n */\n protected _extractArray(): T[] {\n const result = this._array;\n this._array = [];\n return result;\n }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on the array's [[DuplicatePolicy]]:\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array:\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n protected _insert(value: T, onInsert?: (value: T) => any): number {\n const bound = this.lowerBound(value);\n\n if (bound.equal) {\n switch (this._duplicatePolicy) {\n case DuplicatePolicy.Retain:\n return bound.index;\n case DuplicatePolicy.Replace:\n this._array[bound.index] = this._clone(value);\n if (onInsert)\n onInsert(value);\n\n return bound.index;\n }\n }\n\n this._array.splice(bound.index, 0, this._clone(value));\n if (undefined !== onInsert)\n onInsert(value);\n\n return bound.index;\n }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n protected _remove(value: T): number {\n const bound = this.lowerBound(value);\n if (bound.equal) {\n this._array.splice(bound.index, 1);\n return bound.index;\n } else {\n return -1;\n }\n }\n}\n\n/**\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\n * by the user.\n * By default, only unique elements are permitted; attempting to insert a new element that compares\n * as equal to an element already in the array will not modify the contents of the array.\n *\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 an element in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that the array will cease to be sorted.\n * @public\n */\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\n /**\n * Construct a new SortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n super(compare, duplicatePolicy, clone);\n }\n\n /** Clears the contents of the sorted array. */\n public clear(): void { this._clear(); }\n\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\n * @returns the contents of this SortedArray as a T[].\n */\n public extractArray(): T[] { return this._extractArray(); }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on whether or not duplicate elements are permitted.\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n public remove(value: T): number { return this._remove(value); }\n}\n"]}
1
+ {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAWH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAI,KAAQ;IACtC,OAAO,KAAK,CAAC;AACf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CAAC;QACrC,IAAI,KAAK,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;aAAM;YACL,OAAO,CAAC,CAAC,CAAC;SACX;IACH,CAAC;CACF;AApLD,kDAoLC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,WAAe,SAAQ,mBAAsB;IACxD;;;;;OAKG;IACH,YAAmB,OAA6B,EAAE,kBAA6C,KAAK,EAAE,QAA0B,YAAY;QAC1I,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,+CAA+C;IACxC,KAAK,KAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEvC;;OAEG;IACI,YAAY,KAAU,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAQ,EAAE,QAA4B,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvG;;;;OAIG;IACI,MAAM,CAAC,KAAQ,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/D,qIAAqI;IACrH,KAAK,CAAC,KAAc,EAAE,GAAY;QAChD,MAAM,KAAK,GAAG,IAAI,WAAW,CAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACpF,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAjDD,kCAiDC","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\";\n\n/**\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\n * @public\n */\nexport type CloneFunction<T> = (value: T) => T;\n\n/**\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\n * @param value The value to clone.\n * @returns the input value.\n * @public\n */\nexport function shallowClone<T>(value: T) {\n return value;\n}\n\n/**\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\n * @param value The value whose position is to be computed.\n * @param list An array of U already sorted according to the comparison criterion.\n * @param compare The function used to compare the value with elements in `list`.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\n * @public\n */\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\n}\n\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\n let low = 0;\n let high = list.length;\n while (low < high) {\n const mid = Math.floor((low + high) / 2);\n const comp = criterion(list[mid]);\n if (0 === comp)\n return { index: mid, equal: true };\n else if (comp < 0)\n high = mid;\n else\n low = mid + 1;\n }\n\n return { index: low, equal: false };\n}\n\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\n * @public\n */\nexport enum DuplicatePolicy {\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\n */\n Allow,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\n Retain,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\n */\n Replace,\n}\n\n/**\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\n *\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\n * @public\n */\nexport class ReadonlySortedArray<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n protected readonly _duplicatePolicy: DuplicatePolicy;\n\n /**\n * Construct a new ReadonlySortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n if (typeof duplicatePolicy === \"boolean\")\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\n\n this._duplicatePolicy = duplicatePolicy;\n }\n\n /** The number of elements in the array */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the array contains no elements. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n /**\n * Looks up the index of an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\n */\n public indexOf(value: T): number {\n const bound = this.lowerBound(value);\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Returns true if this array contains at least one value comparing equal to the specified value.\n * @param value The value to search for\n * @returns true if an equivalent element exists in the array.\n */\n public contains(value: T): boolean {\n return -1 !== this.indexOf(value);\n }\n\n /**\n * Looks up an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\n */\n public findEqual(value: T): T | undefined {\n const index = this.indexOf(value);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\n * @see [[indexOfEquivalent]].\n * @public\n */\n public findEquivalent(criterion: (element: T) => number): T | undefined {\n const index = this.indexOfEquivalent(criterion);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\n * @public\n */\n public indexOfEquivalent(criterion: (element: T) => number): number {\n // NB: Must invert the ordering.\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Looks up an element by its index in the array.\n * @param index The array index\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\n */\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\n\n /** Apply a function to each element in the array, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (value: T) => void): void {\n for (let i = 0; i < this.length; i++)\n func(this._array[i]);\n }\n\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\n public slice(start?: number, end?: number): ReadonlySortedArray<T> {\n const slice = new ReadonlySortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\n slice._array = this._array.slice(start, end);\n return slice;\n }\n\n /**\n * Computes the position at which the specified value should be inserted to maintain sorted order.\n * @param value The value 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 element already exists at that index.\n */\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\n\n /** Clears the contents of the sorted array. */\n protected _clear(): void { this._array.length = 0; }\n\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\n * @returns the contents of this ReadonlySortedArray as a T[].\n */\n protected _extractArray(): T[] {\n const result = this._array;\n this._array = [];\n return result;\n }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on the array's [[DuplicatePolicy]]:\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array:\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n protected _insert(value: T, onInsert?: (value: T) => any): number {\n const bound = this.lowerBound(value);\n\n if (bound.equal) {\n switch (this._duplicatePolicy) {\n case DuplicatePolicy.Retain:\n return bound.index;\n case DuplicatePolicy.Replace:\n this._array[bound.index] = this._clone(value);\n if (onInsert)\n onInsert(value);\n\n return bound.index;\n }\n }\n\n this._array.splice(bound.index, 0, this._clone(value));\n if (undefined !== onInsert)\n onInsert(value);\n\n return bound.index;\n }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n protected _remove(value: T): number {\n const bound = this.lowerBound(value);\n if (bound.equal) {\n this._array.splice(bound.index, 1);\n return bound.index;\n } else {\n return -1;\n }\n }\n}\n\n/**\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\n * by the user.\n * By default, only unique elements are permitted; attempting to insert a new element that compares\n * as equal to an element already in the array will not modify the contents of the array.\n *\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 an element in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that the array will cease to be sorted.\n * @public\n */\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\n /**\n * Construct a new SortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n super(compare, duplicatePolicy, clone);\n }\n\n /** Clears the contents of the sorted array. */\n public clear(): void { this._clear(); }\n\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\n * @returns the contents of this SortedArray as a T[].\n */\n public extractArray(): T[] { return this._extractArray(); }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on whether or not duplicate elements are permitted.\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n public remove(value: T): number { return this._remove(value); }\n\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\n public override slice(start?: number, end?: number): SortedArray<T> {\n const slice = new SortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\n slice._array = this._array.slice(start, end);\n return slice;\n }\n}\n"]}
@@ -128,6 +128,8 @@ export declare class ReadonlySortedArray<T> implements Iterable<T> {
128
128
  * @param func The function to be applied.
129
129
  */
130
130
  forEach(func: (value: T) => void): void;
131
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
132
+ slice(start?: number, end?: number): ReadonlySortedArray<T>;
131
133
  /**
132
134
  * Computes the position at which the specified value should be inserted to maintain sorted order.
133
135
  * @param value The value whose position is to be computed.
@@ -229,5 +231,7 @@ export declare class SortedArray<T> extends ReadonlySortedArray<T> {
229
231
  * @returns the index of the deleted value, or -1 if no such element exists.
230
232
  */
231
233
  remove(value: T): number;
234
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
235
+ slice(start?: number, end?: number): SortedArray<T>;
232
236
  }
233
237
  //# sourceMappingURL=SortedArray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.d.ts","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,YAAY,CA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G;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;IAEjE,+CAA+C;IAC/C,SAAS,CAAC,MAAM,IAAI,IAAI;IAExB;;OAEG;IACH,SAAS,CAAC,aAAa,IAAI,CAAC,EAAE;IAM9B;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,MAAM;IAuBjE;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;CASpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACxD;;;;;OAKG;gBACgB,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,eAAe,GAAG,OAAe,EAAE,KAAK,GAAE,aAAa,CAAC,CAAC,CAAgB;IAI5I,+CAA+C;IACxC,KAAK,IAAI,IAAI;IAEpB;;OAEG;IACI,YAAY,IAAI,CAAC,EAAE;IAE1B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,MAAM;IAE7D;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;IAE/B,qIAAqI;IACrH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;CAKpE"}
@@ -163,6 +163,12 @@ export class ReadonlySortedArray {
163
163
  for (let i = 0; i < this.length; i++)
164
164
  func(this._array[i]);
165
165
  }
166
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
167
+ slice(start, end) {
168
+ const slice = new ReadonlySortedArray(this._compare, this._duplicatePolicy, this._clone);
169
+ slice._array = this._array.slice(start, end);
170
+ return slice;
171
+ }
166
172
  /**
167
173
  * Computes the position at which the specified value should be inserted to maintain sorted order.
168
174
  * @param value The value whose position is to be computed.
@@ -293,5 +299,11 @@ export class SortedArray extends ReadonlySortedArray {
293
299
  * @returns the index of the deleted value, or -1 if no such element exists.
294
300
  */
295
301
  remove(value) { return this._remove(value); }
302
+ /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */
303
+ slice(start, end) {
304
+ const slice = new SortedArray(this._compare, this._duplicatePolicy, this._clone);
305
+ slice._array = this._array.slice(start, end);
306
+ return slice;
307
+ }
296
308
  }
297
309
  //# sourceMappingURL=SortedArray.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAWH;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAI,KAAQ;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAW,KAAQ,EAAE,IAAS,EAAE,OAAgC;IACxF,OAAO,sBAAsB,CAAC,IAAI,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,sBAAsB,CAAI,IAAS,EAAE,SAAiC;IAC7E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI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,CAAC,CAAC,CAAC,CAAC;CAChE","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\";\n\n/**\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\n * @public\n */\nexport type CloneFunction<T> = (value: T) => T;\n\n/**\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\n * @param value The value to clone.\n * @returns the input value.\n * @public\n */\nexport function shallowClone<T>(value: T) {\n return value;\n}\n\n/**\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\n * @param value The value whose position is to be computed.\n * @param list An array of U already sorted according to the comparison criterion.\n * @param compare The function used to compare the value with elements in `list`.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\n * @public\n */\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\n}\n\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\n let low = 0;\n let high = list.length;\n while (low < high) {\n const mid = Math.floor((low + high) / 2);\n const comp = criterion(list[mid]);\n if (0 === comp)\n return { index: mid, equal: true };\n else if (comp < 0)\n high = mid;\n else\n low = mid + 1;\n }\n\n return { index: low, equal: false };\n}\n\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\n * @public\n */\nexport enum DuplicatePolicy {\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\n */\n Allow,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\n Retain,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\n */\n Replace,\n}\n\n/**\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\n *\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\n * @public\n */\nexport class ReadonlySortedArray<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n protected readonly _duplicatePolicy: DuplicatePolicy;\n\n /**\n * Construct a new ReadonlySortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n if (typeof duplicatePolicy === \"boolean\")\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\n\n this._duplicatePolicy = duplicatePolicy;\n }\n\n /** The number of elements in the array */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the array contains no elements. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n /**\n * Looks up the index of an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\n */\n public indexOf(value: T): number {\n const bound = this.lowerBound(value);\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Returns true if this array contains at least one value comparing equal to the specified value.\n * @param value The value to search for\n * @returns true if an equivalent element exists in the array.\n */\n public contains(value: T): boolean {\n return -1 !== this.indexOf(value);\n }\n\n /**\n * Looks up an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\n */\n public findEqual(value: T): T | undefined {\n const index = this.indexOf(value);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\n * @see [[indexOfEquivalent]].\n * @public\n */\n public findEquivalent(criterion: (element: T) => number): T | undefined {\n const index = this.indexOfEquivalent(criterion);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\n * @public\n */\n public indexOfEquivalent(criterion: (element: T) => number): number {\n // NB: Must invert the ordering.\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Looks up an element by its index in the array.\n * @param index The array index\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\n */\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\n\n /** Apply a function to each element in the array, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (value: T) => void): void {\n for (let i = 0; i < this.length; i++)\n func(this._array[i]);\n }\n\n /**\n * Computes the position at which the specified value should be inserted to maintain sorted order.\n * @param value The value 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 element already exists at that index.\n */\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\n\n /** Clears the contents of the sorted array. */\n protected _clear(): void { this._array.length = 0; }\n\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\n * @returns the contents of this ReadonlySortedArray as a T[].\n */\n protected _extractArray(): T[] {\n const result = this._array;\n this._array = [];\n return result;\n }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on the array's [[DuplicatePolicy]]:\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array:\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n protected _insert(value: T, onInsert?: (value: T) => any): number {\n const bound = this.lowerBound(value);\n\n if (bound.equal) {\n switch (this._duplicatePolicy) {\n case DuplicatePolicy.Retain:\n return bound.index;\n case DuplicatePolicy.Replace:\n this._array[bound.index] = this._clone(value);\n if (onInsert)\n onInsert(value);\n\n return bound.index;\n }\n }\n\n this._array.splice(bound.index, 0, this._clone(value));\n if (undefined !== onInsert)\n onInsert(value);\n\n return bound.index;\n }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n protected _remove(value: T): number {\n const bound = this.lowerBound(value);\n if (bound.equal) {\n this._array.splice(bound.index, 1);\n return bound.index;\n } else {\n return -1;\n }\n }\n}\n\n/**\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\n * by the user.\n * By default, only unique elements are permitted; attempting to insert a new element that compares\n * as equal to an element already in the array will not modify the contents of the array.\n *\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 an element in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that the array will cease to be sorted.\n * @public\n */\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\n /**\n * Construct a new SortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n super(compare, duplicatePolicy, clone);\n }\n\n /** Clears the contents of the sorted array. */\n public clear(): void { this._clear(); }\n\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\n * @returns the contents of this SortedArray as a T[].\n */\n public extractArray(): T[] { return this._extractArray(); }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on whether or not duplicate elements are permitted.\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n public remove(value: T): number { return this._remove(value); }\n}\n"]}
1
+ {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAWH;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAI,KAAQ;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAW,KAAQ,EAAE,IAAS,EAAE,OAAgC;IACxF,OAAO,sBAAsB,CAAC,IAAI,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,sBAAsB,CAAI,IAAS,EAAE,SAAiC;IAC7E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,IAAI;YACZ,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aAChC,IAAI,IAAI,GAAG,CAAC;YACf,IAAI,GAAG,GAAG,CAAC;;YAEX,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;KACjB;IAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB;;OAEG;IACH,uDAAK,CAAA;IACL,mJAAmJ;IACnJ,yDAAM,CAAA;IACN;;OAEG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,CAAC,MAAM,CAAC,CAAC;QACpF,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,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 Collections\n */\n\nimport { OrderedComparator } from \"./Compare\";\n\n/**\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\n * @public\n */\nexport type CloneFunction<T> = (value: T) => T;\n\n/**\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\n * @param value The value to clone.\n * @returns the input value.\n * @public\n */\nexport function shallowClone<T>(value: T) {\n return value;\n}\n\n/**\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\n * @param value The value whose position is to be computed.\n * @param list An array of U already sorted according to the comparison criterion.\n * @param compare The function used to compare the value with elements in `list`.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\n * @public\n */\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\n}\n\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\n let low = 0;\n let high = list.length;\n while (low < high) {\n const mid = Math.floor((low + high) / 2);\n const comp = criterion(list[mid]);\n if (0 === comp)\n return { index: mid, equal: true };\n else if (comp < 0)\n high = mid;\n else\n low = mid + 1;\n }\n\n return { index: low, equal: false };\n}\n\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\n * @public\n */\nexport enum DuplicatePolicy {\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\n */\n Allow,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\n Retain,\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\n */\n Replace,\n}\n\n/**\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\n *\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\n * @public\n */\nexport class ReadonlySortedArray<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n protected readonly _duplicatePolicy: DuplicatePolicy;\n\n /**\n * Construct a new ReadonlySortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n if (typeof duplicatePolicy === \"boolean\")\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\n\n this._duplicatePolicy = duplicatePolicy;\n }\n\n /** The number of elements in the array */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the array contains no elements. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n /**\n * Looks up the index of an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\n */\n public indexOf(value: T): number {\n const bound = this.lowerBound(value);\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Returns true if this array contains at least one value comparing equal to the specified value.\n * @param value The value to search for\n * @returns true if an equivalent element exists in the array.\n */\n public contains(value: T): boolean {\n return -1 !== this.indexOf(value);\n }\n\n /**\n * Looks up an element comparing equal to the specified value using binary search.\n * @param value The value to search for\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\n */\n public findEqual(value: T): T | undefined {\n const index = this.indexOf(value);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\n * @see [[indexOfEquivalent]].\n * @public\n */\n public findEquivalent(criterion: (element: T) => number): T | undefined {\n const index = this.indexOfEquivalent(criterion);\n return -1 !== index ? this._array[index] : undefined;\n }\n\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\n * @public\n */\n public indexOfEquivalent(criterion: (element: T) => number): number {\n // NB: Must invert the ordering.\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\n return bound.equal ? bound.index : -1;\n }\n\n /**\n * Looks up an element by its index in the array.\n * @param index The array index\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\n */\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\n\n /** Apply a function to each element in the array, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (value: T) => void): void {\n for (let i = 0; i < this.length; i++)\n func(this._array[i]);\n }\n\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\n public slice(start?: number, end?: number): ReadonlySortedArray<T> {\n const slice = new ReadonlySortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\n slice._array = this._array.slice(start, end);\n return slice;\n }\n\n /**\n * Computes the position at which the specified value should be inserted to maintain sorted order.\n * @param value The value 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 element already exists at that index.\n */\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\n\n /** Clears the contents of the sorted array. */\n protected _clear(): void { this._array.length = 0; }\n\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\n * @returns the contents of this ReadonlySortedArray as a T[].\n */\n protected _extractArray(): T[] {\n const result = this._array;\n this._array = [];\n return result;\n }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on the array's [[DuplicatePolicy]]:\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array:\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n protected _insert(value: T, onInsert?: (value: T) => any): number {\n const bound = this.lowerBound(value);\n\n if (bound.equal) {\n switch (this._duplicatePolicy) {\n case DuplicatePolicy.Retain:\n return bound.index;\n case DuplicatePolicy.Replace:\n this._array[bound.index] = this._clone(value);\n if (onInsert)\n onInsert(value);\n\n return bound.index;\n }\n }\n\n this._array.splice(bound.index, 0, this._clone(value));\n if (undefined !== onInsert)\n onInsert(value);\n\n return bound.index;\n }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n protected _remove(value: T): number {\n const bound = this.lowerBound(value);\n if (bound.equal) {\n this._array.splice(bound.index, 1);\n return bound.index;\n } else {\n return -1;\n }\n }\n}\n\n/**\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\n * by the user.\n * By default, only unique elements are permitted; attempting to insert a new element that compares\n * as equal to an element already in the array will not modify the contents of the array.\n *\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\n * by some criterion other than object identity.\n *\n * Because the array is always sorted, querying for the presence of an element is performed using binary\n * search, which is more efficient than a linear search for reasonably large arrays.\n *\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\n *\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\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 an element in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that the array will cease to be sorted.\n * @public\n */\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\n /**\n * Construct a new SortedArray<T>.\n * @param compare The function used to compare elements within the array.\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\n super(compare, duplicatePolicy, clone);\n }\n\n /** Clears the contents of the sorted array. */\n public clear(): void { this._clear(); }\n\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\n * @returns the contents of this SortedArray as a T[].\n */\n public extractArray(): T[] { return this._extractArray(); }\n\n /**\n * Attempts to insert a new value into the array at a position determined by the ordering.\n * The behavior differs based on whether or not duplicate elements are permitted.\n * If duplicates are **not** permitted, then:\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\n * - Otherwise, the element is inserted and its index is returned.\n * If duplicates **are** permitted, then:\n * - The element will be inserted in a correct position based on the sorting criterion;\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\n * - The actual index of the newly-inserted element is returned.\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\n * @param value The value to insert\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\n */\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\n\n /**\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\n * @param value The value of the element to delete\n * @returns the index of the deleted value, or -1 if no such element exists.\n */\n public remove(value: T): number { return this._remove(value); }\n\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\n public override slice(start?: number, end?: number): SortedArray<T> {\n const slice = new SortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\n slice._array = this._array.slice(start, end);\n return slice;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-bentley",
3
- "version": "3.7.0-dev.1",
3
+ "version": "3.7.0-dev.2",
4
4
  "description": "Bentley JavaScript core components",
5
5
  "main": "lib/cjs/core-bentley.js",
6
6
  "module": "lib/esm/core-bentley.js",
@@ -21,8 +21,8 @@
21
21
  "url": "http://www.bentley.com"
22
22
  },
23
23
  "devDependencies": {
24
- "@itwin/build-tools": "3.7.0-dev.1",
25
- "@itwin/eslint-plugin": "3.7.0-dev.1",
24
+ "@itwin/build-tools": "3.7.0-dev.2",
25
+ "@itwin/eslint-plugin": "3.7.0-dev.2",
26
26
  "@opentelemetry/api": "1.0.4",
27
27
  "@types/chai": "4.3.1",
28
28
  "@types/chai-as-promised": "^7",