@itwin/core-bentley 5.0.0-dev.9 → 5.0.0-dev.90
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 +51 -1
- package/lib/cjs/AccessToken.js.map +1 -1
- package/lib/cjs/Assert.js.map +1 -1
- package/lib/cjs/BeEvent.js +3 -7
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/BeSQLite.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +3 -0
- package/lib/cjs/BentleyError.d.ts.map +1 -1
- package/lib/cjs/BentleyError.js +6 -1
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/BentleyLoggerCategory.js.map +1 -1
- package/lib/cjs/ByteStream.d.ts +3 -22
- package/lib/cjs/ByteStream.d.ts.map +1 -1
- package/lib/cjs/ByteStream.js +7 -21
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/ClassUtils.js.map +1 -1
- package/lib/cjs/Compare.d.ts +15 -0
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +48 -0
- package/lib/cjs/Compare.js.map +1 -1
- package/lib/cjs/CompressedId64Set.js +6 -3
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.js +8 -3
- package/lib/cjs/Dictionary.js.map +1 -1
- package/lib/cjs/Disposable.d.ts +18 -0
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +25 -25
- package/lib/cjs/Disposable.js.map +1 -1
- package/lib/cjs/Id.d.ts +0 -4
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +9 -11
- package/lib/cjs/Id.js.map +1 -1
- package/lib/cjs/IndexMap.js +6 -1
- package/lib/cjs/IndexMap.js.map +1 -1
- package/lib/cjs/JsonSchema.js.map +1 -1
- package/lib/cjs/JsonUtils.js.map +1 -1
- package/lib/cjs/LRUMap.js +16 -0
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/Logger.d.ts +24 -2
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +26 -7
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.js +6 -6
- package/lib/cjs/ObservableSet.js.map +1 -1
- package/lib/cjs/OneAtATimeAction.js +9 -0
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedId64Iterable.js.map +1 -1
- package/lib/cjs/OrderedSet.js +1 -0
- package/lib/cjs/OrderedSet.js.map +1 -1
- package/lib/cjs/PriorityQueue.js +3 -1
- package/lib/cjs/PriorityQueue.js.map +1 -1
- package/lib/cjs/ProcessDetector.js.map +1 -1
- package/lib/cjs/SortedArray.js +4 -1
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.js +42 -105
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/StringUtils.js.map +1 -1
- package/lib/cjs/Time.js +5 -0
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.js +2 -0
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.js +2 -2
- package/lib/cjs/TupleKeyedMap.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +8 -0
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +10 -12
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/UtilityTypes.js.map +1 -1
- package/lib/cjs/YieldManager.js +3 -1
- package/lib/cjs/YieldManager.js.map +1 -1
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/cjs/internal/BeSQLiteInternal.js.map +1 -1
- package/lib/cjs/internal/RepositoryStatus.js.map +1 -1
- package/lib/cjs/internal/cross-package.d.ts +0 -1
- package/lib/cjs/internal/cross-package.d.ts.map +1 -1
- package/lib/cjs/internal/cross-package.js +1 -3
- package/lib/cjs/internal/cross-package.js.map +1 -1
- package/lib/cjs/partitionArray.js.map +1 -1
- package/lib/esm/AccessToken.js.map +1 -1
- package/lib/esm/Assert.js.map +1 -1
- package/lib/esm/BeEvent.js +3 -7
- package/lib/esm/BeEvent.js.map +1 -1
- package/lib/esm/BeSQLite.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +3 -0
- package/lib/esm/BentleyError.d.ts.map +1 -1
- package/lib/esm/BentleyError.js +6 -1
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/BentleyLoggerCategory.js.map +1 -1
- package/lib/esm/ByteStream.d.ts +3 -22
- package/lib/esm/ByteStream.d.ts.map +1 -1
- package/lib/esm/ByteStream.js +7 -21
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/ClassUtils.js.map +1 -1
- package/lib/esm/Compare.d.ts +15 -0
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +46 -0
- package/lib/esm/Compare.js.map +1 -1
- package/lib/esm/CompressedId64Set.js +6 -3
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.js +8 -3
- package/lib/esm/Dictionary.js.map +1 -1
- package/lib/esm/Disposable.d.ts +18 -0
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +24 -25
- package/lib/esm/Disposable.js.map +1 -1
- package/lib/esm/Id.d.ts +0 -4
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +9 -11
- package/lib/esm/Id.js.map +1 -1
- package/lib/esm/IndexMap.js +6 -1
- package/lib/esm/IndexMap.js.map +1 -1
- package/lib/esm/JsonSchema.js.map +1 -1
- package/lib/esm/JsonUtils.js.map +1 -1
- package/lib/esm/LRUMap.js +16 -0
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/Logger.d.ts +24 -2
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +26 -7
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.js +6 -6
- package/lib/esm/ObservableSet.js.map +1 -1
- package/lib/esm/OneAtATimeAction.js +9 -0
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedId64Iterable.js.map +1 -1
- package/lib/esm/OrderedSet.js +1 -0
- package/lib/esm/OrderedSet.js.map +1 -1
- package/lib/esm/PriorityQueue.js +3 -1
- package/lib/esm/PriorityQueue.js.map +1 -1
- package/lib/esm/ProcessDetector.js.map +1 -1
- package/lib/esm/SortedArray.js +4 -1
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.js +42 -105
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/StringUtils.js.map +1 -1
- package/lib/esm/Time.js +5 -0
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.js +2 -0
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.js +2 -2
- package/lib/esm/TupleKeyedMap.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +8 -0
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.js +10 -12
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/UtilityTypes.js.map +1 -1
- package/lib/esm/YieldManager.js +3 -1
- package/lib/esm/YieldManager.js.map +1 -1
- package/lib/esm/core-bentley.js.map +1 -1
- package/lib/esm/internal/BeSQLiteInternal.js.map +1 -1
- package/lib/esm/internal/RepositoryStatus.js.map +1 -1
- package/lib/esm/internal/cross-package.d.ts +0 -1
- package/lib/esm/internal/cross-package.d.ts.map +1 -1
- package/lib/esm/internal/cross-package.js +0 -1
- package/lib/esm/internal/cross-package.js.map +1 -1
- package/lib/esm/partitionArray.js.map +1 -1
- package/package.json +8 -8
- package/lib/cjs/internal/staticLoggerMetadata.d.ts +0 -11
- package/lib/cjs/internal/staticLoggerMetadata.d.ts.map +0 -1
- package/lib/cjs/internal/staticLoggerMetadata.js +0 -17
- package/lib/cjs/internal/staticLoggerMetadata.js.map +0 -1
- package/lib/esm/internal/staticLoggerMetadata.d.ts +0 -11
- package/lib/esm/internal/staticLoggerMetadata.d.ts.map +0 -1
- package/lib/esm/internal/staticLoggerMetadata.js +0 -14
- package/lib/esm/internal/staticLoggerMetadata.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderedId64Iterable.js","sourceRoot":"","sources":["../../src/OrderedId64Iterable.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAOlC;;;;;;;GAOG;AACH,MAAM,KAAW,mBAAmB,CAwOnC;AAxOD,WAAiB,mBAAmB;IAClC;;;;;;OAMG;IACH,SAAgB,OAAO,CAAC,GAAe,EAAE,GAAe;QACtD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;YAC3B,OAAO,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1C,+GAA+G;QAC/G,0BAA0B;QAC1B,IAAI,GAAG,KAAK,GAAG;YACb,OAAO,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5B,OAAO,CAAC,CAAC;IACX,CAAC;IAVe,2BAAO,UAUtB,CAAA;IAED;;;;;;OAMG;IACH,SAAgB,SAAS,CAAC,GAAc;QACtC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,GAAG,CAAC;IACb,CAAC;IAHe,6BAAS,YAGxB,CAAA;IAED;;OAEG;IACH,SAAgB,YAAY,CAAC,IAAyB,EAAE,IAAyB;QAC/E,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,SAAS,G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YAC7B,CAAC;YAED,IAAI,GAAG,GAAG,CAAC;gBACT,MAAM,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAjCgB,sCAAkB,qBAiClC,CAAA;AACH,CAAC,EAxOgB,mBAAmB,KAAnB,mBAAmB,QAwOnC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Ids\r\n */\r\n\r\nimport { assert } from \"./Assert\";\r\nimport { CompressedId64Set } from \"./CompressedId64Set\";\r\nimport { Id64Array, Id64String } from \"./Id\";\r\n\r\n/** @public */\r\nexport type OrderedId64Iterable = Iterable<Id64String>;\r\n\r\n/** A collection of **valid** [[Id64String]]s sorted in ascending order by the unsigned 64-bit integer value of the Ids.\r\n * This ordering is a requirement for several groups of APIs including [[CompressedId64Set]].\r\n * When used as input to a function, duplicate Ids are ignored; when returned as a function output, no duplicates are present.\r\n * @see [[CompressedId64Set]] for a compact string representation of such an ordered collection.\r\n * @see [[OrderedId64Iterable.compare]] for a function that compares Ids based on this criterion.\r\n * @see [[OrderedId64Array]] for a mutable implementation.\r\n * @public\r\n */\r\nexport namespace OrderedId64Iterable { // eslint-disable-line @typescript-eslint/no-redeclare\r\n /** An ordered comparison of [[Id64String]]s suitable for use with sorting routines like\r\n * [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) and sorted containers\r\n * like [[SortedArray]] and [[Dictionary]]. The comparison compares the 64-bit numerical values of the two Ids, returning a negative number if lhs < rhs,\r\n * a positive number if lhs > rhs, or zero if lhs == rhs.\r\n * The default string comparison is fine (and more efficient) when numerical ordering is not required; use this instead if you want e.g., \"0x100\" to be greater than \"0xf\".\r\n * @see [[OrderedId64Iterable.sortArray]] for a convenient way to sort an array of Id64Strings.\r\n */\r\n export function compare(lhs: Id64String, rhs: Id64String): number {\r\n if (lhs.length !== rhs.length)\r\n return lhs.length < rhs.length ? -1 : 1;\r\n\r\n // This is faster than localeCompare(). Unclear why there is no string.compare() - would be generally useful in\r\n // array sort functions...\r\n if (lhs !== rhs)\r\n return lhs < rhs ? -1 : 1;\r\n\r\n return 0;\r\n }\r\n\r\n /** Sort an array of [[Id64String]]s **in-place** in ascending order by their 64-bit numerical values.\r\n * @see [[OrderedId64Iterable.compare]] for the comparison routine used.\r\n * @returns the input array.\r\n * @note This function returns its input for consistency with Javascript's\r\n * [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) method.\r\n * It **does not** create a **new** array.\r\n */\r\n export function sortArray(ids: Id64Array): Id64Array {\r\n ids.sort((x, y) => compare(x, y));\r\n return ids;\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, determine whether they are identical sets. Duplicate Ids are ignored.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function areEqualSets(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): boolean {\r\n const leftIter = uniqueIterator(ids1);\r\n const rightIter = uniqueIterator(ids2);\r\n let leftState = leftIter.next();\r\n let rightState = rightIter.next();\r\n\r\n while (!leftState.done && !rightState.done) {\r\n const left = leftState.value;\r\n const right = rightState.value;\r\n if (0 !== compare(left, right))\r\n return false;\r\n\r\n leftState = leftIter.next();\r\n rightState = rightIter.next();\r\n }\r\n\r\n if (leftState.done && rightState.done)\r\n return true;\r\n\r\n return false;\r\n }\r\n\r\n /** Given an ordered collection of [[Id64String]]s, determine if it contains any Ids.\r\n * @param ids A well-formed, ordered collection of zero or more valid Ids.\r\n * @returns true if the input represents an empty set of Ids. The result is unspecified if the input does not meet the criteria for the input type.\r\n */\r\n export function isEmptySet(ids: OrderedId64Iterable | CompressedId64Set): boolean {\r\n if (typeof ids === \"string\")\r\n return \"\" === ids;\r\n\r\n return true === ids[Symbol.iterator]().next().done;\r\n }\r\n\r\n /** Given an ordered collection of [[Id64String]]s possibly containing duplicates, produce an ordered collection containing no duplicates.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function unique(ids: OrderedId64Iterable): OrderedId64Iterable {\r\n return { [Symbol.iterator]: () => uniqueIterator(ids) };\r\n }\r\n\r\n /** Given an ordered collection of [[Id64String]]s possibly containing duplicates, produce an ordered iterator over the distinct Ids, eliminating duplicates.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function* uniqueIterator(ids: OrderedId64Iterable) {\r\n const iter = ids[Symbol.iterator]();\r\n let state = iter.next();\r\n let prev: Id64String | undefined;\r\n\r\n while (!state.done) {\r\n const id = state.value;\r\n state = iter.next();\r\n if (id !== prev) {\r\n prev = id;\r\n yield id;\r\n }\r\n }\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce a collection representing their union - i.e., the Ids that are present in either or both collections.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function union(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\r\n return { [Symbol.iterator]: () => unionIterator(ids1, ids2) };\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their intersection - i.e., the Ids that are present in both collections.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function intersection(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\r\n return { [Symbol.iterator]: () => intersectionIterator(ids1, ids2) };\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their difference - i.e., the Ids that are present in `ids1` but not present in `ids2`.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function difference(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\r\n return { [Symbol.iterator]: () => differenceIterator(ids1, ids2) };\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their union - i.e., the Ids that are present in either or both collections.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function* unionIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\r\n const leftIter = ids1[Symbol.iterator]();\r\n const rightIter = ids2[Symbol.iterator]();\r\n let leftState = leftIter.next();\r\n let rightState = rightIter.next();\r\n\r\n let prev: string | undefined;\r\n while (!leftState.done || !rightState.done) {\r\n const left = leftState.done ? undefined : leftState.value;\r\n const right = rightState.done ? undefined : rightState.value;\r\n\r\n assert(undefined !== left || undefined !== right);\r\n if (undefined === left && undefined === right)\r\n break;\r\n\r\n let next: Id64String;\r\n if (undefined === left) {\r\n assert(undefined !== right);\r\n next = right;\r\n rightState = rightIter.next();\r\n } else if (undefined === right) {\r\n next = left;\r\n leftState = leftIter.next();\r\n } else {\r\n const cmp = compare(left, right);\r\n if (cmp <= 0) {\r\n next = left;\r\n leftState = leftIter.next();\r\n if (0 === cmp)\r\n rightState = rightIter.next();\r\n } else {\r\n next = right;\r\n rightState = rightIter.next();\r\n }\r\n }\r\n\r\n if (prev === next)\r\n continue;\r\n\r\n prev = next;\r\n yield next;\r\n }\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their intersection - i.e., the Ids that are present in both collections.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function* intersectionIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\r\n const leftIter = ids1[Symbol.iterator]();\r\n const rightIter = ids2[Symbol.iterator]();\r\n let leftState = leftIter.next();\r\n let rightState = rightIter.next();\r\n\r\n let prev: string | undefined;\r\n while (!leftState.done && !rightState.done) {\r\n const left = leftState.value;\r\n leftState = leftIter.next();\r\n if (left === prev)\r\n continue;\r\n\r\n prev = left;\r\n\r\n let right = rightState.value;\r\n let cmp = compare(left, right);\r\n while (cmp > 0) {\r\n rightState = rightIter.next();\r\n if (rightState.done)\r\n return;\r\n\r\n right = rightState.value;\r\n cmp = compare(left, right);\r\n }\r\n\r\n if (0 === cmp)\r\n yield left;\r\n }\r\n }\r\n\r\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their difference - i.e., the Ids that are present in `ids1` but not present in `ids2`.\r\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\r\n */\r\n export function* differenceIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\r\n const leftIter = ids1[Symbol.iterator]();\r\n const rightIter = ids2[Symbol.iterator]();\r\n let leftState = leftIter.next();\r\n let rightState = rightIter.next();\r\n\r\n let prev: string | undefined;\r\n while (!leftState.done) {\r\n const left = leftState.value;\r\n leftState = leftIter.next();\r\n if (left === prev)\r\n continue;\r\n else if (rightState.done) {\r\n yield prev = left;\r\n continue;\r\n }\r\n\r\n let right = rightState.value;\r\n let cmp = compare(left, right);\r\n while (cmp > 0 && !rightState.done) {\r\n rightState = rightIter.next();\r\n if (rightState.done) {\r\n yield prev = left;\r\n continue;\r\n }\r\n\r\n right = rightState.value;\r\n cmp = compare(left, right);\r\n }\r\n\r\n if (cmp < 0)\r\n yield prev = left;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"OrderedId64Iterable.js","sourceRoot":"","sources":["../../src/OrderedId64Iterable.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAOlC;;;;;;;GAOG;AACH,MAAM,KAAW,mBAAmB,CAwOnC;AAxOD,WAAiB,mBAAmB;IAClC;;;;;;OAMG;IACH,SAAgB,OAAO,CAAC,GAAe,EAAE,GAAe;QACtD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;YAC3B,OAAO,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC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C7B,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,IAAI,KAAK,IAAI;gBACf,SAAS;iBACN,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;gBACzB,MAAM,IAAI,GAAG,IAAI,CAAC;gBAClB,SAAS;YACX,CAAC;YAED,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;YAC7B,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC/B,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;gBACnC,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;gBAC9B,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;oBACpB,MAAM,IAAI,GAAG,IAAI,CAAC;oBAClB,SAAS;gBACX,CAAC;gBAED,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;gBACzB,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC7B,CAAC;YAED,IAAI,GAAG,GAAG,CAAC;gBACT,MAAM,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAjCgB,sCAAkB,qBAiClC,CAAA;AACH,CAAC,EAxOgB,mBAAmB,KAAnB,mBAAmB,QAwOnC","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 Ids\n */\n\nimport { assert } from \"./Assert\";\nimport { CompressedId64Set } from \"./CompressedId64Set\";\nimport { Id64Array, Id64String } from \"./Id\";\n\n/** @public */\nexport type OrderedId64Iterable = Iterable<Id64String>;\n\n/** A collection of **valid** [[Id64String]]s sorted in ascending order by the unsigned 64-bit integer value of the Ids.\n * This ordering is a requirement for several groups of APIs including [[CompressedId64Set]].\n * When used as input to a function, duplicate Ids are ignored; when returned as a function output, no duplicates are present.\n * @see [[CompressedId64Set]] for a compact string representation of such an ordered collection.\n * @see [[OrderedId64Iterable.compare]] for a function that compares Ids based on this criterion.\n * @see [[OrderedId64Array]] for a mutable implementation.\n * @public\n */\nexport namespace OrderedId64Iterable { // eslint-disable-line @typescript-eslint/no-redeclare\n /** An ordered comparison of [[Id64String]]s suitable for use with sorting routines like\n * [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) and sorted containers\n * like [[SortedArray]] and [[Dictionary]]. The comparison compares the 64-bit numerical values of the two Ids, returning a negative number if lhs < rhs,\n * a positive number if lhs > rhs, or zero if lhs == rhs.\n * The default string comparison is fine (and more efficient) when numerical ordering is not required; use this instead if you want e.g., \"0x100\" to be greater than \"0xf\".\n * @see [[OrderedId64Iterable.sortArray]] for a convenient way to sort an array of Id64Strings.\n */\n export function compare(lhs: Id64String, rhs: Id64String): number {\n if (lhs.length !== rhs.length)\n return lhs.length < rhs.length ? -1 : 1;\n\n // This is faster than localeCompare(). Unclear why there is no string.compare() - would be generally useful in\n // array sort functions...\n if (lhs !== rhs)\n return lhs < rhs ? -1 : 1;\n\n return 0;\n }\n\n /** Sort an array of [[Id64String]]s **in-place** in ascending order by their 64-bit numerical values.\n * @see [[OrderedId64Iterable.compare]] for the comparison routine used.\n * @returns the input array.\n * @note This function returns its input for consistency with Javascript's\n * [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) method.\n * It **does not** create a **new** array.\n */\n export function sortArray(ids: Id64Array): Id64Array {\n ids.sort((x, y) => compare(x, y));\n return ids;\n }\n\n /** Given two ordered collections of [[Id64String]]s, determine whether they are identical sets. Duplicate Ids are ignored.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function areEqualSets(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): boolean {\n const leftIter = uniqueIterator(ids1);\n const rightIter = uniqueIterator(ids2);\n let leftState = leftIter.next();\n let rightState = rightIter.next();\n\n while (!leftState.done && !rightState.done) {\n const left = leftState.value;\n const right = rightState.value;\n if (0 !== compare(left, right))\n return false;\n\n leftState = leftIter.next();\n rightState = rightIter.next();\n }\n\n if (leftState.done && rightState.done)\n return true;\n\n return false;\n }\n\n /** Given an ordered collection of [[Id64String]]s, determine if it contains any Ids.\n * @param ids A well-formed, ordered collection of zero or more valid Ids.\n * @returns true if the input represents an empty set of Ids. The result is unspecified if the input does not meet the criteria for the input type.\n */\n export function isEmptySet(ids: OrderedId64Iterable | CompressedId64Set): boolean {\n if (typeof ids === \"string\")\n return \"\" === ids;\n\n return true === ids[Symbol.iterator]().next().done;\n }\n\n /** Given an ordered collection of [[Id64String]]s possibly containing duplicates, produce an ordered collection containing no duplicates.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function unique(ids: OrderedId64Iterable): OrderedId64Iterable {\n return { [Symbol.iterator]: () => uniqueIterator(ids) };\n }\n\n /** Given an ordered collection of [[Id64String]]s possibly containing duplicates, produce an ordered iterator over the distinct Ids, eliminating duplicates.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function* uniqueIterator(ids: OrderedId64Iterable) {\n const iter = ids[Symbol.iterator]();\n let state = iter.next();\n let prev: Id64String | undefined;\n\n while (!state.done) {\n const id = state.value;\n state = iter.next();\n if (id !== prev) {\n prev = id;\n yield id;\n }\n }\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce a collection representing their union - i.e., the Ids that are present in either or both collections.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function union(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\n return { [Symbol.iterator]: () => unionIterator(ids1, ids2) };\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their intersection - i.e., the Ids that are present in both collections.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function intersection(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\n return { [Symbol.iterator]: () => intersectionIterator(ids1, ids2) };\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their difference - i.e., the Ids that are present in `ids1` but not present in `ids2`.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function difference(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable): OrderedId64Iterable {\n return { [Symbol.iterator]: () => differenceIterator(ids1, ids2) };\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their union - i.e., the Ids that are present in either or both collections.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function* unionIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\n const leftIter = ids1[Symbol.iterator]();\n const rightIter = ids2[Symbol.iterator]();\n let leftState = leftIter.next();\n let rightState = rightIter.next();\n\n let prev: string | undefined;\n while (!leftState.done || !rightState.done) {\n const left = leftState.done ? undefined : leftState.value;\n const right = rightState.done ? undefined : rightState.value;\n\n assert(undefined !== left || undefined !== right);\n if (undefined === left && undefined === right)\n break;\n\n let next: Id64String;\n if (undefined === left) {\n assert(undefined !== right);\n next = right;\n rightState = rightIter.next();\n } else if (undefined === right) {\n next = left;\n leftState = leftIter.next();\n } else {\n const cmp = compare(left, right);\n if (cmp <= 0) {\n next = left;\n leftState = leftIter.next();\n if (0 === cmp)\n rightState = rightIter.next();\n } else {\n next = right;\n rightState = rightIter.next();\n }\n }\n\n if (prev === next)\n continue;\n\n prev = next;\n yield next;\n }\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their intersection - i.e., the Ids that are present in both collections.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function* intersectionIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\n const leftIter = ids1[Symbol.iterator]();\n const rightIter = ids2[Symbol.iterator]();\n let leftState = leftIter.next();\n let rightState = rightIter.next();\n\n let prev: string | undefined;\n while (!leftState.done && !rightState.done) {\n const left = leftState.value;\n leftState = leftIter.next();\n if (left === prev)\n continue;\n\n prev = left;\n\n let right = rightState.value;\n let cmp = compare(left, right);\n while (cmp > 0) {\n rightState = rightIter.next();\n if (rightState.done)\n return;\n\n right = rightState.value;\n cmp = compare(left, right);\n }\n\n if (0 === cmp)\n yield left;\n }\n }\n\n /** Given two ordered collections of [[Id64String]]s, produce an iterator representing their difference - i.e., the Ids that are present in `ids1` but not present in `ids2`.\n * @note If the inputs are not ordered as required by [[OrderedId64Iterable]], the results are unpredictable.\n */\n export function* differenceIterator(ids1: OrderedId64Iterable, ids2: OrderedId64Iterable) {\n const leftIter = ids1[Symbol.iterator]();\n const rightIter = ids2[Symbol.iterator]();\n let leftState = leftIter.next();\n let rightState = rightIter.next();\n\n let prev: string | undefined;\n while (!leftState.done) {\n const left = leftState.value;\n leftState = leftIter.next();\n if (left === prev)\n continue;\n else if (rightState.done) {\n yield prev = left;\n continue;\n }\n\n let right = rightState.value;\n let cmp = compare(left, right);\n while (cmp > 0 && !rightState.done) {\n rightState = rightIter.next();\n if (rightState.done) {\n yield prev = left;\n continue;\n }\n\n right = rightState.value;\n cmp = compare(left, right);\n }\n\n if (cmp < 0)\n yield prev = left;\n }\n }\n}\n"]}
|
package/lib/esm/OrderedSet.js
CHANGED
|
@@ -12,6 +12,7 @@ import { shallowClone, SortedArray } from "./SortedArray";
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
export class ReadonlyOrderedSet {
|
|
15
|
+
_array;
|
|
15
16
|
/** Construct a new ReadonlyOrderedSet<T>.
|
|
16
17
|
* @param compare The function used to compare elements within the set, determining their ordering.
|
|
17
18
|
* @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderedSet.js","sourceRoot":"","sources":["../../src/Order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AAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6FAA6F;IACtF,MAAM,CAAC,KAAQ;QACpB,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,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\";\nimport { CloneFunction, shallowClone, SortedArray } from \"./SortedArray\";\n\n/** A read-only equivalent of `Set<T>` that maintains its elements in sorted order as specified by a comparison function.\n * Iteration returns elements in the order specified by the comparison function, as opposed to `Set` which returns elements in insertion order.\n * Implemented in terms of [[SortedArray]].\n * @public\n */\nexport class ReadonlyOrderedSet<T> implements Iterable<T> {\n protected readonly _array: SortedArray<T>;\n\n /** Construct a new ReadonlyOrderedSet<T>.\n * @param compare The function used to compare elements within the set, determining their ordering.\n * @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n this._array = new SortedArray<T>(compare, false, clone);\n }\n\n /** The number of elements in the set. */\n public get size(): number {\n return this._array.length;\n }\n\n /** Returns true if `value` is present in the set. */\n public has(value: T): boolean {\n return -1 !== this._array.indexOf(value);\n }\n\n /** Iterate over the elements in sorted order (as opposed to `Set`'s iterator, which returns elements in insertion order). */\n public [Symbol.iterator](): Iterator<T> {\n return this._array[Symbol.iterator]();\n }\n}\n\n/** A mutable [[ReadonlyOrderedSet]].\n * @public\n */\nexport class OrderedSet<T> extends ReadonlyOrderedSet<T> {\n /** Construct a new OrderedSet<T>.\n * @param compare The function used to compare elements within the set, determining their ordering.\n * @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n super(compare, clone);\n }\n\n /** Remove all elements from the set. */\n public clear(): void {\n this._array.clear();\n }\n\n /** Add the specified element to the set. Returns this set. */\n public add(value: T): this {\n this._array.insert(value);\n return this;\n }\n\n /** Removes the specified element from the set. Returns `true` if the element was present. */\n public delete(value: T): boolean {\n return -1 !== this._array.remove(value);\n }\n}\n"]}
|
package/lib/esm/PriorityQueue.js
CHANGED
|
@@ -12,6 +12,9 @@ import { shallowClone } from "./SortedArray";
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
export class PriorityQueue {
|
|
15
|
+
_array = [];
|
|
16
|
+
_compare;
|
|
17
|
+
_clone;
|
|
15
18
|
/**
|
|
16
19
|
* Constructor
|
|
17
20
|
* @param compare The function used to compare values in the queue. If `compare(x, y)` returns a negative value, then x is placed before y in the queue.
|
|
@@ -19,7 +22,6 @@ export class PriorityQueue {
|
|
|
19
22
|
* @note If the criterion which control the result of the `compare` function changes, then [[PriorityQueue.sort]] should be used to reorder the queue according to the new criterion.
|
|
20
23
|
*/
|
|
21
24
|
constructor(compare, clone = shallowClone) {
|
|
22
|
-
this._array = [];
|
|
23
25
|
this._compare = compare;
|
|
24
26
|
this._clone = clone;
|
|
25
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PriorityQueue.js","sourceRoot":"","sources":["../../src/PriorityQueue.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAC;AAK5D;;;;GAIG;AACH,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"PriorityQueue.js","sourceRoot":"","sources":["../../src/PriorityQueue.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAC;AAK5D;;;;GAIG;AACH,MAAM,OAAO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/*---------------------------------------------------------------------------------------------\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, shallowClone } from \"./SortedArray\";\n\n/** @public */\nexport type ComputePriorityFunction<T> = (value: T) => number;\n\n/**\n * A [priority queue](https://en.wikipedia.org/wiki/Priority_queue) implemented as a heap array.\n * The queue is ordered by an [[OrderedComparator]] function supplied by the user such that the value in the queue that compares less than all other values is always located at the front of the queue.\n * @public\n */\nexport class PriorityQueue<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n\n /**\n * Constructor\n * @param compare The function used to compare values in the queue. If `compare(x, y)` returns a negative value, then x is placed before y in the queue.\n * @param clone The function used to clone a value for insertion onto the queue. The default implementation simply returns its input.\n * @note If the criterion which control the result of the `compare` function changes, then [[PriorityQueue.sort]] should be used to reorder the queue according to the new criterion.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n }\n\n /** The number of values in the queue. */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the queue contains no values. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the heap suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n protected _swap(a: number, b: number) {\n const temp = this._array[a];\n this._array[a] = this._array[b];\n this._array[b] = temp;\n }\n\n protected _heapify(index: number): void {\n let candidate = -1;\n while (true) {\n const right = 2 * (index + 1);\n const left = right - 1;\n if (left < this.length && this._compare(this._array[left], this._array[index]) < 0)\n candidate = left;\n else\n candidate = index;\n\n if (right < this.length && this._compare(this._array[right], this._array[candidate]) < 0)\n candidate = right;\n\n if (candidate !== index) {\n this._swap(candidate, index);\n index = candidate;\n } else {\n break;\n }\n }\n }\n\n /**\n * Reorders the queue. This function should only (and *always*) be called when the criteria governing the ordering of items on the queue have changed.\n * For example, a priority queue containing graphics sorted by their distance from the camera would need to be reordered when the position of the camera changes.\n */\n public sort(): void {\n for (let i = Math.ceil(this.length / 2); i >= 0; i--)\n this._heapify(i);\n }\n\n /**\n * Pushes a value onto the queue according to the sorting criterion.\n * @param value The value to insert\n * @returns The inserted value, cloned according to the [[CloneFunction]] supplied to this queue's constructor.\n */\n public push(value: T): T {\n const clone = this._clone(value);\n\n let index = this.length;\n this._array.push(clone);\n\n while (index !== 0) {\n const parent = Math.floor((index - 1) / 2);\n if (this._compare(this._array[index], this._array[parent]) < 0) {\n this._swap(index, parent);\n index = parent;\n } else {\n break;\n }\n }\n\n return clone;\n }\n\n /** Pushes a value onto the back of the queue without making any attempt to enforce ordering.\n * After using this function, you must manually invoke sort() to ensure the queue is sorted again.\n * @param value The value to append\n * @returns The appended value, cloned according to the [[CloneFunction]] supplied to this queue's constructor.\n */\n public append(value: T): T {\n const clone = this._clone(value);\n this._array.push(clone);\n return clone;\n }\n\n /** Returns the element at the front of the queue, or `undefined` if the queue is empty. */\n public get front(): T | undefined {\n return this._peek(0);\n }\n\n /**\n * Removes the front-most element off of the queue and returns it.\n * @returns The front-most element, or undefined if the queue is empty.\n */\n public pop(): T | undefined {\n return this._pop(0);\n }\n\n /** Removes all values from the queue. */\n public clear(): void {\n this._array.length = 0;\n }\n\n /**\n * Removes the value at the specified index from the queue and reorders the queue.\n * @param index The index of the value to remove\n * @returns the value at the specified index, or undefined if the index is out of range.\n */\n protected _pop(index: number): T | undefined {\n if (index < 0 || index >= this.length)\n return undefined;\n\n const root = this._array[index];\n this._swap(index, this.length - 1);\n this._array.length--;\n\n this._heapify(index);\n return root;\n }\n\n /**\n * Returns the value at the specified index in the queue.\n * @param index The index of the value to retrieve\n * @returns the value at the specified index, or undefined if the index is out of range.\n */\n protected _peek(index: number): T | undefined {\n if (index < 0 || index >= this.length)\n return undefined;\n else\n return this._array[index];\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessDetector.js","sourceRoot":"","sources":["../../src/ProcessDetector.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,eAAe;IAE1B;;OAEG;IACI,MAAM,KAAK,gBAAgB,KAAK,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC;IAEnH;;MAEE;IACK,MAAM,KAAK,aAAa,KAAK,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE3G,uDAAuD;IAChD,MAAM,KAAK,qBAAqB,KAAK,OAAO,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEjJ,sDAAsD;IAC/C,MAAM,KAAK,oBAAoB,KAAK,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAE/H;;OAEG;IACI,MAAM,KAAK,aAAa;QAC7B,OAAO,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,0DAA0D;IAClP,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,eAAe,KAAK,OAAO,IAAI,CAAC,gBAAgB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAA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AAM,KAAK,eAAe,KAAK,OAAO,IAAI,CAAC,aAAa,IAAK,OAAO,CAAC,QAAgB,KAAK,KAAK,CAAC,CAAC,CAAC;IAEzG,oEAAoE;IAC7D,MAAM,KAAK,mBAAmB,KAAK,OAAO,IAAI,CAAC,aAAa,IAAK,OAAO,CAAC,QAAgB,KAAK,SAAS,CAAC,CAAC,CAAC;IAEjH,6CAA6C;IACtC,MAAM,KAAK,kBAAkB,KAAK,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEnG,yEAAyE;IAClE,MAAM,KAAK,mBAAmB,KAAK,OAAO,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;CAC3G","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"ProcessDetector.js","sourceRoot":"","sources":["../../src/ProcessDetector.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,eAAe;IAE1B;;OAEG;IACI,MAAM,KAAK,gBAAgB,KAAK,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC;IAEnH;;MAEE;IACK,MAAM,KAAK,aAAa,KAAK,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE3G,uDAAuD;IAChD,MAAM,KAAK,qBAAqB,KAAK,OAAO,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEjJ,sDAAsD;IAC/C,MAAM,KAAK,oBAAoB,KAAK,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA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AAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEtG,iEAAiE;IAC1D,MAAM,KAAK,gBAAgB,KAAK,OAAO,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7H,qEAAqE;IAC9D,MAAM,KAAK,oBAAoB,KAAK,OAAO,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAErI,gEAAgE;IACzD,MAAM,KAAK,eAAe,KAAK,OAAO,IAAI,CAAC,aAAa,IAAK,OAAO,CAAC,QAAgB,KAAK,KAAK,CAAC,CAAC,CAAC;IAEzG,oEAAoE;IAC7D,MAAM,KAAK,mBAAmB,KAAK,OAAO,IAAI,CAAC,aAAa,IAAK,OAAO,CAAC,QAAgB,KAAK,SAAS,CAAC,CAAC,CAAC;IAEjH,6CAA6C;IACtC,MAAM,KAAK,kBAAkB,KAAK,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEnG,yEAAyE;IAClE,MAAM,KAAK,mBAAmB,KAAK,OAAO,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;CAC3G","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 ProcessDetector\n */\n\n/** Functions to determine the type of JavaScript process currently executing.\n * @public\n */\nexport class ProcessDetector {\n\n /** Is this a browser process?\n * @note this method will also return `true` for the frontend of Electron or Mobile apps. They *are* browser processes.\n */\n public static get isBrowserProcess() { return typeof window === \"object\" && typeof window.navigator === \"object\"; }\n\n /** Is this a Node process?\n * @note this means \"is this a backend process\"? It will return `true` for all backend process, including Electron and mobile apps.\n */\n public static get isNodeProcess() { return typeof process === \"object\" && undefined !== process.platform; }\n\n /** Is this process the frontend of an Electron app? */\n public static get isElectronAppFrontend() { return typeof navigator === \"object\" && navigator.userAgent.toLowerCase().indexOf(\"electron\") >= 0; }\n\n /** Is this process the backend of an Electron app? */\n public static get isElectronAppBackend() { return typeof process === \"object\" && process.versions.hasOwnProperty(\"electron\"); }\n\n /** Is this process running in a browser on an iPad?\n * @note This method will return `true` for any frontend running on an iPad, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app.\n */\n public static get isIPadBrowser() {\n return this.isBrowserProcess && window.navigator.platform === \"iPad\" || (window.navigator.platform === \"MacIntel\" && window.navigator.maxTouchPoints > 0 && !(\"MSStream\" in window)); /* eslint-disable-line @typescript-eslint/no-deprecated */\n }\n\n /** Is this process running in a browser on an iPhone?\n * @note This method will return `true` for any frontend running on an iPhone, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app.\n */\n public static get isIPhoneBrowser() { return this.isBrowserProcess && (/(iphone|ipod)/i.test(window.navigator.userAgent)); }\n\n /** Is this process running in a browser on an iOS device?\n * @note This method will return `true` for any frontend running on an iOS device, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app.\n */\n public static get isIOSBrowser() { return this.isIPadBrowser || this.isIPhoneBrowser; }\n\n /** Is this process running in a browser on an Android device?\n * @note This method will return `true` for any frontend running on an Android device, whether it is a user-launched web browser (e.g. Chrome) or the frontend of a mobile app.\n */\n public static get isAndroidBrowser() { return this.isBrowserProcess && /android/i.test(window.navigator.userAgent); }\n\n /** Is this process running in a browser on a mobile device?\n * @note This method will return `true` for any frontend running on a mobile device, whether it is a user-launched web browser or the frontend of a mobile app.\n */\n public static get isMobileBrowser() { return this.isIOSBrowser || this.isAndroidBrowser; }\n\n /** Is this process running in a Chromium based browser (Chrome / new Edge / Electron front end)? */\n public static get isChromium() {\n return (this.isBrowserProcess && window.navigator.userAgent.indexOf(\"Chrome\") > -1 && window.navigator.userAgent.indexOf(\"OP\") === -1) || this.isElectronAppFrontend;\n }\n\n /** Is this process the frontend of an iTwin mobile application?\n * @note this indicates that this is a browser process started by an iTwin mobile application.\n * It will return `false` when running user-launched web browsers on a mobile device.\n */\n public static get isMobileAppFrontend() { return this.isAndroidAppFrontend || this.isIOSAppFrontend; }\n\n /** Is this process the frontend of an iOS mobile application? */\n public static get isIOSAppFrontend() { return this.isBrowserProcess && window.location.hash.indexOf(\"platform=ios\") !== -1; }\n\n /** Is this process the frontend of an Android mobile application? */\n public static get isAndroidAppFrontend() { return this.isBrowserProcess && window.location.hash.indexOf(\"platform=android\") !== -1; }\n\n /** Is this process the backend of an iOS mobile application? */\n public static get isIOSAppBackend() { return this.isNodeProcess && (process.platform as any) === \"ios\"; }\n\n /** Is this process the backend of an Android mobile application? */\n public static get isAndroidAppBackend() { return this.isNodeProcess && (process.platform as any) === \"android\"; }\n\n /** Is this process a mobile app backend? */\n public static get isMobileAppBackend() { return this.isIOSAppBackend || this.isAndroidAppBackend; }\n\n /** Is this process the frontend of a native (Electron or Mobile) app? */\n public static get isNativeAppFrontend() { return this.isElectronAppFrontend || this.isMobileAppFrontend; }\n}\n"]}
|
package/lib/esm/SortedArray.js
CHANGED
|
@@ -80,6 +80,10 @@ export var DuplicatePolicy;
|
|
|
80
80
|
* @public
|
|
81
81
|
*/
|
|
82
82
|
export class ReadonlySortedArray {
|
|
83
|
+
_array = [];
|
|
84
|
+
_compare;
|
|
85
|
+
_clone;
|
|
86
|
+
_duplicatePolicy;
|
|
83
87
|
/**
|
|
84
88
|
* Construct a new ReadonlySortedArray<T>.
|
|
85
89
|
* @param compare The function used to compare elements within the array.
|
|
@@ -87,7 +91,6 @@ export class ReadonlySortedArray {
|
|
|
87
91
|
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.
|
|
88
92
|
*/
|
|
89
93
|
constructor(compare, duplicatePolicy = false, clone = shallowClone) {
|
|
90
|
-
this._array = [];
|
|
91
94
|
this._compare = compare;
|
|
92
95
|
this._clone = clone;
|
|
93
96
|
if (typeof duplicatePolicy === "boolean")
|
|
@@ -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,CAAC;QAClB,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;IAClB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,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C,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","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\n\r\n/**\r\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\r\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\r\n * @public\r\n */\r\nexport type CloneFunction<T> = (value: T) => T;\r\n\r\n/**\r\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\r\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\r\n * @param value The value to clone.\r\n * @returns the input value.\r\n * @public\r\n */\r\nexport function shallowClone<T>(value: T) {\r\n return value;\r\n}\r\n\r\n/**\r\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.\r\n * @param value The value whose position is to be computed.\r\n * @param list An array of U already sorted according to the comparison criterion.\r\n * @param compare The function used to compare the value with elements in `list`.\r\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.\r\n * @public\r\n */\r\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\r\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\r\n}\r\n\r\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\r\n let low = 0;\r\n let high = list.length;\r\n while (low < high) {\r\n const mid = Math.floor((low + high) / 2);\r\n const comp = criterion(list[mid]);\r\n if (0 === comp)\r\n return { index: mid, equal: true };\r\n else if (comp < 0)\r\n high = mid;\r\n else\r\n low = mid + 1;\r\n }\r\n\r\n return { index: low, equal: false };\r\n}\r\n\r\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\r\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\r\n * @public\r\n */\r\nexport enum DuplicatePolicy {\r\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.\r\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.\r\n */\r\n Allow,\r\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\r\n Retain,\r\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.\r\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\r\n */\r\n Replace,\r\n}\r\n\r\n/**\r\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\r\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\r\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\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.\r\n *\r\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\r\n * @public\r\n */\r\nexport class ReadonlySortedArray<T> implements Iterable<T> {\r\n protected _array: T[] = [];\r\n protected readonly _compare: OrderedComparator<T>;\r\n protected readonly _clone: CloneFunction<T>;\r\n protected readonly _duplicatePolicy: DuplicatePolicy;\r\n\r\n /**\r\n * Construct a new ReadonlySortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\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]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n this._compare = compare;\r\n this._clone = clone;\r\n if (typeof duplicatePolicy === \"boolean\")\r\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\r\n\r\n this._duplicatePolicy = duplicatePolicy;\r\n }\r\n\r\n /** The number of elements in the array */\r\n public get length(): number { return this._array.length; }\r\n\r\n /** Returns true if the array contains no elements. */\r\n public get isEmpty(): boolean { return 0 === this.length; }\r\n\r\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\r\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\r\n\r\n /**\r\n * Looks up the index of an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\r\n */\r\n public indexOf(value: T): number {\r\n const bound = this.lowerBound(value);\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Returns true if this array contains at least one value comparing equal to the specified value.\r\n * @param value The value to search for\r\n * @returns true if an equivalent element exists in the array.\r\n */\r\n public contains(value: T): boolean {\r\n return -1 !== this.indexOf(value);\r\n }\r\n\r\n /**\r\n * Looks up an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\r\n */\r\n public findEqual(value: T): T | undefined {\r\n const index = this.indexOf(value);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\r\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\r\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\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\".\r\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\r\n * @see [[indexOfEquivalent]].\r\n * @public\r\n */\r\n public findEquivalent(criterion: (element: T) => number): T | undefined {\r\n const index = this.indexOfEquivalent(criterion);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\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.\r\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,\r\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\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\".\r\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\r\n * @public\r\n */\r\n public indexOfEquivalent(criterion: (element: T) => number): number {\r\n // NB: Must invert the ordering.\r\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Looks up an element by its index in the array.\r\n * @param index The array index\r\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\r\n */\r\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\r\n\r\n /** Apply a function to each element in the array, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (value: T) => void): void {\r\n for (let i = 0; i < this.length; i++)\r\n func(this._array[i]);\r\n }\r\n\r\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\r\n public slice(start?: number, end?: number): ReadonlySortedArray<T> {\r\n const slice = new ReadonlySortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\r\n slice._array = this._array.slice(start, end);\r\n return slice;\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified value should be inserted to maintain sorted order.\r\n * @param value The value whose position is to be computed.\r\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.\r\n */\r\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\r\n\r\n /** Clears the contents of the sorted array. */\r\n protected _clear(): void { this._array.length = 0; }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\r\n * @returns the contents of this ReadonlySortedArray as a T[].\r\n */\r\n protected _extractArray(): T[] {\r\n const result = this._array;\r\n this._array = [];\r\n return result;\r\n }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on the array's [[DuplicatePolicy]]:\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array:\r\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\r\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\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.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\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.\r\n */\r\n protected _insert(value: T, onInsert?: (value: T) => any): number {\r\n const bound = this.lowerBound(value);\r\n\r\n if (bound.equal) {\r\n switch (this._duplicatePolicy) {\r\n case DuplicatePolicy.Retain:\r\n return bound.index;\r\n case DuplicatePolicy.Replace:\r\n this._array[bound.index] = this._clone(value);\r\n if (onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n }\r\n\r\n this._array.splice(bound.index, 0, this._clone(value));\r\n if (undefined !== onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n protected _remove(value: T): number {\r\n const bound = this.lowerBound(value);\r\n if (bound.equal) {\r\n this._array.splice(bound.index, 1);\r\n return bound.index;\r\n } else {\r\n return -1;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\r\n * by the user.\r\n * By default, only unique elements are permitted; attempting to insert a new element that compares\r\n * as equal to an element already in the array will not modify the contents of the array.\r\n *\r\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Modifying an element in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that the array will cease to be sorted.\r\n * @public\r\n */\r\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\r\n /**\r\n * Construct a new SortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\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]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n super(compare, duplicatePolicy, clone);\r\n }\r\n\r\n /** Clears the contents of the sorted array. */\r\n public clear(): void { this._clear(); }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\r\n * @returns the contents of this SortedArray as a T[].\r\n */\r\n public extractArray(): T[] { return this._extractArray(); }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on whether or not duplicate elements are permitted.\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\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.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\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.\r\n */\r\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n public remove(value: T): number { return this._remove(value); }\r\n\r\n /** The equivalent of [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). */\r\n public override slice(start?: number, end?: number): SortedArray<T> {\r\n const slice = new SortedArray<T>(this._compare, this._duplicatePolicy, this._clone);\r\n slice._array = this._array.slice(start, end);\r\n return slice;\r\n }\r\n}\r\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,CAAC;QAClB,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,IA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Aa,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","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"]}
|
|
@@ -11,6 +11,7 @@ import { RepositoryStatus } from "./internal/RepositoryStatus";
|
|
|
11
11
|
* @alpha
|
|
12
12
|
*/
|
|
13
13
|
export class StatusCategory {
|
|
14
|
+
static handlers = new Set();
|
|
14
15
|
static for(error) {
|
|
15
16
|
for (const handler of this.handlers) {
|
|
16
17
|
const category = handler(error);
|
|
@@ -24,179 +25,115 @@ export class StatusCategory {
|
|
|
24
25
|
return new UnknownError();
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
StatusCategory.handlers = new Set();
|
|
28
28
|
/***
|
|
29
29
|
* A success status.
|
|
30
30
|
* @alpha
|
|
31
31
|
*/
|
|
32
32
|
export class SuccessCategory extends StatusCategory {
|
|
33
|
-
|
|
34
|
-
super(...arguments);
|
|
35
|
-
this.error = false;
|
|
36
|
-
}
|
|
33
|
+
error = false;
|
|
37
34
|
}
|
|
38
35
|
/**
|
|
39
36
|
* An error status.
|
|
40
37
|
* @alpha
|
|
41
38
|
*/
|
|
42
39
|
export class ErrorCategory extends StatusCategory {
|
|
43
|
-
|
|
44
|
-
super(...arguments);
|
|
45
|
-
this.error = true;
|
|
46
|
-
}
|
|
40
|
+
error = true;
|
|
47
41
|
}
|
|
48
42
|
var HTTP;
|
|
49
43
|
(function (HTTP) {
|
|
50
44
|
class OK extends SuccessCategory {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.name = "OK";
|
|
54
|
-
this.code = 200;
|
|
55
|
-
}
|
|
45
|
+
name = "OK";
|
|
46
|
+
code = 200;
|
|
56
47
|
}
|
|
57
48
|
HTTP.OK = OK;
|
|
58
49
|
class Accepted extends SuccessCategory {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.name = "Accepted";
|
|
62
|
-
this.code = 202;
|
|
63
|
-
}
|
|
50
|
+
name = "Accepted";
|
|
51
|
+
code = 202;
|
|
64
52
|
}
|
|
65
53
|
HTTP.Accepted = Accepted;
|
|
66
54
|
class NoContent extends SuccessCategory {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.name = "NoContent";
|
|
70
|
-
this.code = 204;
|
|
71
|
-
}
|
|
55
|
+
name = "NoContent";
|
|
56
|
+
code = 204;
|
|
72
57
|
}
|
|
73
58
|
HTTP.NoContent = NoContent;
|
|
74
59
|
class BadRequest extends ErrorCategory {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.name = "BadRequest";
|
|
78
|
-
this.code = 400;
|
|
79
|
-
}
|
|
60
|
+
name = "BadRequest";
|
|
61
|
+
code = 400;
|
|
80
62
|
}
|
|
81
63
|
HTTP.BadRequest = BadRequest;
|
|
82
64
|
class Unauthorized extends ErrorCategory {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.name = "Unauthorized";
|
|
86
|
-
this.code = 401;
|
|
87
|
-
}
|
|
65
|
+
name = "Unauthorized";
|
|
66
|
+
code = 401;
|
|
88
67
|
}
|
|
89
68
|
HTTP.Unauthorized = Unauthorized;
|
|
90
69
|
class Forbidden extends ErrorCategory {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.name = "Forbidden";
|
|
94
|
-
this.code = 403;
|
|
95
|
-
}
|
|
70
|
+
name = "Forbidden";
|
|
71
|
+
code = 403;
|
|
96
72
|
}
|
|
97
73
|
HTTP.Forbidden = Forbidden;
|
|
98
74
|
class NotFound extends ErrorCategory {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.name = "NotFound";
|
|
102
|
-
this.code = 404;
|
|
103
|
-
}
|
|
75
|
+
name = "NotFound";
|
|
76
|
+
code = 404;
|
|
104
77
|
}
|
|
105
78
|
HTTP.NotFound = NotFound;
|
|
106
79
|
class RequestTimeout extends ErrorCategory {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.name = "RequestTimeout";
|
|
110
|
-
this.code = 408;
|
|
111
|
-
}
|
|
80
|
+
name = "RequestTimeout";
|
|
81
|
+
code = 408;
|
|
112
82
|
}
|
|
113
83
|
HTTP.RequestTimeout = RequestTimeout;
|
|
114
84
|
class Conflict extends ErrorCategory {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.name = "Conflict";
|
|
118
|
-
this.code = 409;
|
|
119
|
-
}
|
|
85
|
+
name = "Conflict";
|
|
86
|
+
code = 409;
|
|
120
87
|
}
|
|
121
88
|
HTTP.Conflict = Conflict;
|
|
122
89
|
class Gone extends ErrorCategory {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.name = "Gone";
|
|
126
|
-
this.code = 410;
|
|
127
|
-
}
|
|
90
|
+
name = "Gone";
|
|
91
|
+
code = 410;
|
|
128
92
|
}
|
|
129
93
|
HTTP.Gone = Gone;
|
|
130
94
|
class PreconditionFailed extends ErrorCategory {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.name = "PreconditionFailed";
|
|
134
|
-
this.code = 412;
|
|
135
|
-
}
|
|
95
|
+
name = "PreconditionFailed";
|
|
96
|
+
code = 412;
|
|
136
97
|
}
|
|
137
98
|
HTTP.PreconditionFailed = PreconditionFailed;
|
|
138
99
|
class ExpectationFailed extends ErrorCategory {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.name = "ExpectationFailed";
|
|
142
|
-
this.code = 417;
|
|
143
|
-
}
|
|
100
|
+
name = "ExpectationFailed";
|
|
101
|
+
code = 417;
|
|
144
102
|
}
|
|
145
103
|
HTTP.ExpectationFailed = ExpectationFailed;
|
|
146
104
|
class MisdirectedRequest extends ErrorCategory {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
this.name = "MisdirectedRequest";
|
|
150
|
-
this.code = 421;
|
|
151
|
-
}
|
|
105
|
+
name = "MisdirectedRequest";
|
|
106
|
+
code = 421;
|
|
152
107
|
}
|
|
153
108
|
HTTP.MisdirectedRequest = MisdirectedRequest;
|
|
154
109
|
class UnprocessableEntity extends ErrorCategory {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.name = "UnprocessableEntity";
|
|
158
|
-
this.code = 422;
|
|
159
|
-
}
|
|
110
|
+
name = "UnprocessableEntity";
|
|
111
|
+
code = 422;
|
|
160
112
|
}
|
|
161
113
|
HTTP.UnprocessableEntity = UnprocessableEntity;
|
|
162
114
|
class UpgradeRequired extends ErrorCategory {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.name = "UpgradeRequired";
|
|
166
|
-
this.code = 426;
|
|
167
|
-
}
|
|
115
|
+
name = "UpgradeRequired";
|
|
116
|
+
code = 426;
|
|
168
117
|
}
|
|
169
118
|
HTTP.UpgradeRequired = UpgradeRequired;
|
|
170
119
|
class PreconditionRequired extends ErrorCategory {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.name = "PreconditionRequired";
|
|
174
|
-
this.code = 428;
|
|
175
|
-
}
|
|
120
|
+
name = "PreconditionRequired";
|
|
121
|
+
code = 428;
|
|
176
122
|
}
|
|
177
123
|
HTTP.PreconditionRequired = PreconditionRequired;
|
|
178
124
|
class TooManyRequests extends ErrorCategory {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.name = "TooManyRequests";
|
|
182
|
-
this.code = 429;
|
|
183
|
-
}
|
|
125
|
+
name = "TooManyRequests";
|
|
126
|
+
code = 429;
|
|
184
127
|
}
|
|
185
128
|
HTTP.TooManyRequests = TooManyRequests;
|
|
186
129
|
class InternalServerError extends ErrorCategory {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.name = "InternalServerError";
|
|
190
|
-
this.code = 500;
|
|
191
|
-
}
|
|
130
|
+
name = "InternalServerError";
|
|
131
|
+
code = 500;
|
|
192
132
|
}
|
|
193
133
|
HTTP.InternalServerError = InternalServerError;
|
|
194
134
|
class NotImplemented extends ErrorCategory {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.name = "NotImplemented";
|
|
198
|
-
this.code = 501;
|
|
199
|
-
}
|
|
135
|
+
name = "NotImplemented";
|
|
136
|
+
code = 501;
|
|
200
137
|
}
|
|
201
138
|
HTTP.NotImplemented = NotImplemented;
|
|
202
139
|
})(HTTP || (HTTP = {}));
|
|
@@ -453,7 +390,7 @@ function lookupHttpStatusCategory(statusCode) {
|
|
|
453
390
|
case GeoServiceStatus.NoDatumConverter: return new OperationFailed();
|
|
454
391
|
case GeoServiceStatus.VerticalDatumConvertError: return new OperationFailed();
|
|
455
392
|
case GeoServiceStatus.CSMapError: return new InternalError();
|
|
456
|
-
case GeoServiceStatus.Pending: return new Pending();
|
|
393
|
+
case GeoServiceStatus.Pending: return new Pending(); // eslint-disable-line @typescript-eslint/no-deprecated
|
|
457
394
|
case RealityDataStatus.Success: return new Success();
|
|
458
395
|
case RealityDataStatus.InvalidData: return new InvalidData();
|
|
459
396
|
default: return new UnknownError();
|