@itwin/core-bentley 5.1.3 → 5.1.5
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 +11 -1
- package/lib/cjs/AccessToken.js.map +1 -1
- package/lib/cjs/Assert.js.map +1 -1
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/BeSQLite.js.map +1 -1
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/BentleyLoggerCategory.js.map +1 -1
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/ClassUtils.js.map +1 -1
- package/lib/cjs/Compare.js.map +1 -1
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.js.map +1 -1
- package/lib/cjs/Disposable.js.map +1 -1
- package/lib/cjs/Id.js.map +1 -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.map +1 -1
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.js.map +1 -1
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedId64Iterable.js.map +1 -1
- package/lib/cjs/OrderedSet.js.map +1 -1
- package/lib/cjs/PriorityQueue.js.map +1 -1
- package/lib/cjs/ProcessDetector.js.map +1 -1
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/StringUtils.js.map +1 -1
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/UtilityTypes.js.map +1 -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.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.map +1 -1
- package/lib/esm/BeSQLite.js.map +1 -1
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/BentleyLoggerCategory.js.map +1 -1
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/ClassUtils.js.map +1 -1
- package/lib/esm/Compare.js.map +1 -1
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.js.map +1 -1
- package/lib/esm/Disposable.js.map +1 -1
- package/lib/esm/Id.js.map +1 -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.map +1 -1
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.js.map +1 -1
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedId64Iterable.js.map +1 -1
- package/lib/esm/OrderedSet.js.map +1 -1
- package/lib/esm/PriorityQueue.js.map +1 -1
- package/lib/esm/ProcessDetector.js.map +1 -1
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/StringUtils.js.map +1 -1
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/UtilityTypes.js.map +1 -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.js.map +1 -1
- package/lib/esm/partitionArray.js.map +1 -1
- package/package.json +2 -2
package/lib/cjs/Compare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Compare.js","sourceRoot":"","sources":["../../src/Compare.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;AA4BH,oDAOC;AAGD,wCAEC;AAGD,0CAEC;AAGD,wCAEC;AAGD,4DAOC;AAGD,8DAEC;AAGD,8DAEC;AAGD,gEAEC;AAKD,8DAOC;AAMD,gDAmBC;AAYD,kDAmBC;AAMD,sCAYC;AAzID;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,CAAS,EAAE,CAAS,EAAE,SAAS,GAAG,GAAG;IACxE,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS;QACnB,OAAO,CAAC,CAAC,CAAC;SACP,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS;QACxB,OAAO,CAAC,CAAC;;QAET,OAAO,CAAC,CAAC;AACb,CAAC;AAED,cAAc;AACd,SAAgB,cAAc,CAAC,CAAS,EAAE,CAAS;IACjD,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,cAAc;AACd,SAAgB,eAAe,CAAC,CAAU,EAAE,CAAU;IACpD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,cAAc;AACd,SAAgB,cAAc,CAAC,CAAS,EAAE,CAAS;IACjD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,cAAc;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+B;IAC5G,IAAI,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/**\n * A function that returns a numerical value indicating how two objects are ordered in relation to one another.\n * Such functions are used by various collection classes throughout the library.\n * Given values `lhs` and `rhs`, the function returns:\n * - Zero if lhs == rhs\n * - A negative number if lhs < rhs\n * - A positive number if lhs > rhs\n *\n * An OrderedComparator `must` implement [strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), which can be summarized by the following rules:\n * - `compare(x, x)` returns zero.\n * - If `compare(x, y)` returns zero, then so does `compare(y, x)` (i.e., `x == y` implies `y == x`).\n * - If `compare(x, y)` returns non-zero, then `compare(y, x)` returns a value with an opposite sign (i.e., `x < y` implies `y > x`).\n * - If `compare(x, y)` and `compare(y, z)` return non-zero values with the same sign, then `compare(x, z)` returns a value with the same sign (i.e., `x < y < z` implies `x < z`).\n *\n * @see SortedArray\n * @see Dictionary\n * @see IndexMap\n * @see PriorityQueue\n * @public\n */\nexport type OrderedComparator<T, U = T> = (lhs: T, rhs: U) => number;\n\n/**\n * An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance.\n * @public\n */\nexport function compareWithTolerance(a: number, b: number, tolerance = 0.1): number {\n if (a < b - tolerance)\n return -1;\n else if (a > b + tolerance)\n return 1;\n else\n return 0;\n}\n\n/** @public */\nexport function compareNumbers(a: number, b: number): number {\n return a - b;\n}\n\n/** @public */\nexport function compareBooleans(a: boolean, b: boolean): number {\n return a !== b ? (a < b ? -1 : 1) : 0;\n}\n\n/** @public */\nexport function compareStrings(a: string, b: string): number {\n return a === b ? 0 : (a < b ? -1 : 1);\n}\n\n/** @public */\nexport function comparePossiblyUndefined<T>(compareDefined: (lhs: T, rhs: T) => number, lhs?: T, rhs?: T): number {\n if (undefined === lhs)\n return undefined === rhs ? 0 : -1;\n else if (undefined === rhs)\n return 1;\n else\n return compareDefined(lhs, rhs);\n}\n\n/** @public */\nexport function compareStringsOrUndefined(lhs?: string, rhs?: string): number {\n return comparePossiblyUndefined(compareStrings, lhs, rhs);\n}\n\n/** @public */\nexport function compareNumbersOrUndefined(lhs?: number, rhs?: number): number {\n return comparePossiblyUndefined(compareNumbers, lhs, rhs);\n}\n\n/** @public */\nexport function compareBooleansOrUndefined(lhs?: boolean, rhs?: boolean): number {\n return comparePossiblyUndefined(compareBooleans, lhs, rhs);\n}\n\n/** Compare two possibly-undefined values for equality. If both are undefined, the comparison is performed by the supplied `areEqual` function.\n * @public\n */\nexport function areEqualPossiblyUndefined<T, U>(t: T | undefined, u: U | undefined, areEqual: (t: T, u: U) => boolean): boolean {\n if (undefined === t)\n return undefined === u;\n else if (undefined === u)\n return false;\n else\n return areEqual(t, u);\n}\n\n/**\n * Compare two simples types (number, string, boolean)\n * This essentially wraps the existing type-specific comparison functions\n * @beta */\nexport function compareSimpleTypes(lhs: number | string | boolean, rhs: number | string | boolean): number {\n let cmp = 0;\n\n // Make sure the types are the same\n cmp = compareStrings(typeof lhs, typeof rhs);\n if (cmp !== 0) {\n return cmp;\n }\n\n // Compare actual values\n switch (typeof lhs) {\n case \"number\":\n return compareNumbers(lhs, rhs as number);\n case \"string\":\n return compareStrings(lhs, rhs as string);\n case \"boolean\":\n return compareBooleans(lhs, rhs as boolean);\n }\n return cmp;\n}\n/**\n * An array of simple types (number, string, boolean)\n * @beta\n */\nexport type SimpleTypesArray = number[] | string[] | boolean[];\n\n/**\n * Compare two arrays of simple types (number, string, boolean)\n * @beta\n */\n\nexport function compareSimpleArrays (lhs?: SimpleTypesArray, rhs?: SimpleTypesArray ) {\n if (undefined === lhs)\n return undefined === rhs ? 0 : -1;\n else if (undefined === rhs)\n return 1;\n else if (lhs.length === 0 && rhs.length === 0) {\n return 0;\n } else if (lhs.length !== rhs.length) {\n return lhs.length - rhs.length;\n }\n\n let cmp = 0;\n for (let i = 0; i < lhs.length; i++) {\n cmp = compareSimpleTypes(lhs[i], rhs[i]);\n if (cmp !== 0) {\n break;\n }\n }\n return cmp;\n}\n\n/** Compare two arrays of the same type `T` using the specified `compare` function to compare each pair of array elements.\n * @returns 0 if the arrays have the same length and `compare` returns 0 for each pair of elements, or a non-zero value if the arrays differ in length or contents.\n * @public\n */\nexport function compareArrays<T>(lhs: ReadonlyArray<T>, rhs: ReadonlyArray<T>, compare: (a: T, b: T) => number): number {\n let diff = compareNumbers(lhs.length, rhs.length);\n if (!diff) {\n for (let i = 0; i < lhs.length; i++) {\n diff = compare(lhs[i], rhs[i]);\n if (diff) {\n break;\n }\n }\n }\n\n return diff;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Compare.js","sourceRoot":"","sources":["../../src/Compare.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;AA4BH,oDAOC;AAGD,wCAEC;AAGD,0CAEC;AAGD,wCAEC;AAGD,4DAOC;AAGD,8DAEC;AAGD,8DAEC;AAGD,gEAEC;AAKD,8DAOC;AAMD,gDAmBC;AAYD,kDAmBC;AAMD,sCAYC;AAzID;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,CAAS,EAAE,CAAS,EAAE,SAAS,GAAG,GAAG;IACx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AC;SAC/B,IAAI,SAAS,KAAK,GAAG;QACxB,OAAO,CAAC,CAAC;SACN,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,CAAC,CAAC;IACX,CAAC;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACd,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAI,GAAqB,EAAE,GAAqB,EAAE,OAA+B;IAC5G,IAAI,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","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 Utils\r\n */\r\n\r\n/**\r\n * A function that returns a numerical value indicating how two objects are ordered in relation to one another.\r\n * Such functions are used by various collection classes throughout the library.\r\n * Given values `lhs` and `rhs`, the function returns:\r\n * - Zero if lhs == rhs\r\n * - A negative number if lhs < rhs\r\n * - A positive number if lhs > rhs\r\n *\r\n * An OrderedComparator `must` implement [strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), which can be summarized by the following rules:\r\n * - `compare(x, x)` returns zero.\r\n * - If `compare(x, y)` returns zero, then so does `compare(y, x)` (i.e., `x == y` implies `y == x`).\r\n * - If `compare(x, y)` returns non-zero, then `compare(y, x)` returns a value with an opposite sign (i.e., `x < y` implies `y > x`).\r\n * - If `compare(x, y)` and `compare(y, z)` return non-zero values with the same sign, then `compare(x, z)` returns a value with the same sign (i.e., `x < y < z` implies `x < z`).\r\n *\r\n * @see SortedArray\r\n * @see Dictionary\r\n * @see IndexMap\r\n * @see PriorityQueue\r\n * @public\r\n */\r\nexport type OrderedComparator<T, U = T> = (lhs: T, rhs: U) => number;\r\n\r\n/**\r\n * An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance.\r\n * @public\r\n */\r\nexport function compareWithTolerance(a: number, b: number, tolerance = 0.1): number {\r\n if (a < b - tolerance)\r\n return -1;\r\n else if (a > b + tolerance)\r\n return 1;\r\n else\r\n return 0;\r\n}\r\n\r\n/** @public */\r\nexport function compareNumbers(a: number, b: number): number {\r\n return a - b;\r\n}\r\n\r\n/** @public */\r\nexport function compareBooleans(a: boolean, b: boolean): number {\r\n return a !== b ? (a < b ? -1 : 1) : 0;\r\n}\r\n\r\n/** @public */\r\nexport function compareStrings(a: string, b: string): number {\r\n return a === b ? 0 : (a < b ? -1 : 1);\r\n}\r\n\r\n/** @public */\r\nexport function comparePossiblyUndefined<T>(compareDefined: (lhs: T, rhs: T) => number, lhs?: T, rhs?: T): number {\r\n if (undefined === lhs)\r\n return undefined === rhs ? 0 : -1;\r\n else if (undefined === rhs)\r\n return 1;\r\n else\r\n return compareDefined(lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareStringsOrUndefined(lhs?: string, rhs?: string): number {\r\n return comparePossiblyUndefined(compareStrings, lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareNumbersOrUndefined(lhs?: number, rhs?: number): number {\r\n return comparePossiblyUndefined(compareNumbers, lhs, rhs);\r\n}\r\n\r\n/** @public */\r\nexport function compareBooleansOrUndefined(lhs?: boolean, rhs?: boolean): number {\r\n return comparePossiblyUndefined(compareBooleans, lhs, rhs);\r\n}\r\n\r\n/** Compare two possibly-undefined values for equality. If both are undefined, the comparison is performed by the supplied `areEqual` function.\r\n * @public\r\n */\r\nexport function areEqualPossiblyUndefined<T, U>(t: T | undefined, u: U | undefined, areEqual: (t: T, u: U) => boolean): boolean {\r\n if (undefined === t)\r\n return undefined === u;\r\n else if (undefined === u)\r\n return false;\r\n else\r\n return areEqual(t, u);\r\n}\r\n\r\n/**\r\n * Compare two simples types (number, string, boolean)\r\n * This essentially wraps the existing type-specific comparison functions\r\n * @beta */\r\nexport function compareSimpleTypes(lhs: number | string | boolean, rhs: number | string | boolean): number {\r\n let cmp = 0;\r\n\r\n // Make sure the types are the same\r\n cmp = compareStrings(typeof lhs, typeof rhs);\r\n if (cmp !== 0) {\r\n return cmp;\r\n }\r\n\r\n // Compare actual values\r\n switch (typeof lhs) {\r\n case \"number\":\r\n return compareNumbers(lhs, rhs as number);\r\n case \"string\":\r\n return compareStrings(lhs, rhs as string);\r\n case \"boolean\":\r\n return compareBooleans(lhs, rhs as boolean);\r\n }\r\n return cmp;\r\n}\r\n/**\r\n * An array of simple types (number, string, boolean)\r\n * @beta\r\n */\r\nexport type SimpleTypesArray = number[] | string[] | boolean[];\r\n\r\n/**\r\n * Compare two arrays of simple types (number, string, boolean)\r\n * @beta\r\n */\r\n\r\nexport function compareSimpleArrays (lhs?: SimpleTypesArray, rhs?: SimpleTypesArray ) {\r\n if (undefined === lhs)\r\n return undefined === rhs ? 0 : -1;\r\n else if (undefined === rhs)\r\n return 1;\r\n else if (lhs.length === 0 && rhs.length === 0) {\r\n return 0;\r\n } else if (lhs.length !== rhs.length) {\r\n return lhs.length - rhs.length;\r\n }\r\n\r\n let cmp = 0;\r\n for (let i = 0; i < lhs.length; i++) {\r\n cmp = compareSimpleTypes(lhs[i], rhs[i]);\r\n if (cmp !== 0) {\r\n break;\r\n }\r\n }\r\n return cmp;\r\n}\r\n\r\n/** Compare two arrays of the same type `T` using the specified `compare` function to compare each pair of array elements.\r\n * @returns 0 if the arrays have the same length and `compare` returns 0 for each pair of elements, or a non-zero value if the arrays differ in length or contents.\r\n * @public\r\n */\r\nexport function compareArrays<T>(lhs: ReadonlyArray<T>, rhs: ReadonlyArray<T>, compare: (a: T, b: T) => number): number {\r\n let diff = compareNumbers(lhs.length, rhs.length);\r\n if (!diff) {\r\n for (let i = 0; i < lhs.length; i++) {\r\n diff = compare(lhs[i], rhs[i]);\r\n if (diff) {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return diff;\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompressedId64Set.js","sourceRoot":"","sources":["../../src/CompressedId64Set.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAkC;AAClC,6BAA4D;AAC5D,+DAA4D;AAC5D,+CAA4C;AAK5C;;;;;;;;GAQG;AACH,IAAiB,iBAAiB,CAoUjC;AApUD,WAAiB,iBAAiB;IAChC,SAAS,UAAU,CAAC,EAAU;QAC5B,gBAAgB;QAChB,WAAW;QACX,WAAW;QACX,WAAW;QACX,WAAW;QAEX,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,I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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 Ids\n */\n\nimport { assert } from \"./Assert\";\nimport { Id64, Id64Array, Id64Set, Id64String } from \"./Id\";\nimport { OrderedId64Iterable } from \"./OrderedId64Iterable\";\nimport { SortedArray } from \"./SortedArray\";\n\n/** @public */\nexport type CompressedId64Set = string;\n\n/** A compact string representation of an [[Id64Set]]. Such a representation is useful when serializing potentially very large\n * sets of Ids.\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids represented by a compact string.\n * @see [[CompressedId64Set.compressSet]] and [[CompressedId64Set.compressArray]] to produce a compact string from a collection of Ids.\n * @see [[CompressedId64Set.decompressSet]] and [[CompressedId64Set.decompressArray]] to produce a collection of Ids from a compact string.\n * @see [[OrderedId64Iterable]] for a generic representation of an ordered set of Ids (compressed or otherwise).\n * @see [[MutableCompressedId64Set]] for a mutable version.\n * @public\n */\nexport namespace CompressedId64Set { // eslint-disable-line @typescript-eslint/no-redeclare\n function isHexDigit(ch: number): boolean {\n // ascii values:\n // '0' = 48\n // '9' = 57\n // 'a' = 65\n // 'f' = 70\n\n return (ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 70);\n }\n\n function compactRange(increment: Uint64, length: number): string {\n assert(length > 0);\n const inc = `+${increment.toString()}`;\n if (length <= 1)\n return inc;\n\n const len = length.toString(16).toUpperCase();\n return `${inc}*${len}`;\n }\n\n /** Given a set of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\n * @note Invalid Ids are ignored.\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\n * @see [[CompressedId64Set.compressArray]] to perform the same operation on an [[Id64Array]].\n * @see [[CompressedId64Set.decompressSet]] to perform the inverse operation.\n */\n export function compressSet(ids: Id64Set): CompressedId64Set {\n return sortAndCompress(ids);\n }\n\n /** Create a sorted array from `ids`, then return a compact string representation of those Ids.\n * @see [[CompressedId64Set.compressIds]] if `ids` is known to already be sorted.\n */\n export function sortAndCompress(ids: Iterable<Id64String>): CompressedId64Set {\n // `string` is an Iterable<string>. In that case assume caller passed a single Id64String.\n const arr = typeof ids === \"string\" ? [ids] : Array.from(ids);\n OrderedId64Iterable.sortArray(arr);\n return compressArray(arr);\n }\n\n /** Give a **numerically-ordered** array of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\n * Duplicate Ids are included only once in the string representation.\n * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the array is not properly sorted.\n * @note The array must be sorted according to the 64-bit numerical value of each Id.\n * @note Invalid Ids are ignored.\n * @see [[CompressedId64Set.decompressArray]] to perform the inverse operation.\n * @see [[OrderedId64Iterable.sortArray]] to ensure the Ids are properly sorted.\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\n */\n export function compressArray(ids: Id64Array): CompressedId64Set {\n return compressIds(ids);\n }\n\n /** Give a **numerically-ordered** collection of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\n * Duplicate Ids are included only once in the string representation.\n * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the collection is not properly sorted.\n * @note The collection must be sorted according to the 64-bit numerical value of each Id.\n * @note Invalid Ids are ignored.\n * @see [[CompressedId64Set.iterable]] to perform the inverse operation.\n * @see [[OrderedId64Iterable.sortArray]] or [[OrderedId64Iterable.compare]] to ensure the Ids are properly sorted.\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\n */\n export function compressIds(ids: OrderedId64Iterable): CompressedId64Set {\n if (\"string\" === typeof ids)\n return ids;\n\n let str = \"\";\n\n const prevId = new Uint64();\n const rangeIncrement = new Uint64();\n let rangeLen = 0;\n\n const curId = new Uint64();\n const curIncrement = new Uint64();\n for (const id of ids) {\n if (!Id64.isValidId64(id))\n continue; // ignore garbage and invalid Ids (\"0\")\n\n curId.setFromId(id);\n curIncrement.setFromDifference(curId, prevId);\n\n const cmp = prevId.compare(curId);\n if (0 === cmp)\n continue; // ignore duplicates\n else if (cmp > 0)\n throw new Error(\"CompressedId64Set.compressArray requires a sorted array as input\");\n\n prevId.copyFrom(curId);\n\n if (0 === rangeLen) {\n rangeIncrement.copyFrom(curIncrement);\n rangeLen = 1;\n } else if (curIncrement.equals(rangeIncrement)) {\n ++rangeLen;\n } else {\n str += compactRange(rangeIncrement, rangeLen);\n rangeIncrement.copyFrom(curIncrement);\n rangeLen = 1;\n }\n }\n\n if (0 < rangeLen)\n str += compactRange(rangeIncrement, rangeLen);\n\n return str;\n }\n\n /** This exists strictly for the purposes of compressed sets of 64-bit Ids, to avoid the overhead of BigInt for handling 64-bit integers. */\n class Uint64 implements Id64.Uint32Pair {\n private static readonly _base = 0x100000000;\n\n private static assertUint32(num: number): void {\n assert(num >= 0);\n assert(num < Uint64._base);\n assert(Math.floor(num) === num);\n }\n\n private assertConstraints(): void {\n Uint64.assertUint32(this.lower);\n Uint64.assertUint32(this.upper);\n }\n\n constructor(public lower = 0, public upper = 0) {\n this.assertConstraints();\n }\n\n public compare(rhs: Uint64): number {\n const diff = this.upper - rhs.upper;\n return 0 === diff ? this.lower - rhs.lower : diff;\n }\n\n public equals(rhs: Uint64): boolean { return 0 === this.compare(rhs); }\n public isLessThan(rhs: Uint64): boolean { return this.compare(rhs) < 0; }\n public isGreaterThan(rhs: Uint64): boolean { return this.compare(rhs) > 0; }\n\n public get isZero(): boolean { return 0 === this.lower && 0 === this.upper; }\n\n public setFromDifference(lhs: Uint64, rhs: Uint64): void {\n assert(!rhs.isGreaterThan(lhs));\n\n this.lower = lhs.lower - rhs.lower;\n this.upper = lhs.upper - rhs.upper;\n if (this.lower < 0) {\n this.lower += Uint64._base;\n this.upper -= 1;\n }\n }\n\n public add(rhs: Uint64): void {\n let lower = rhs.lower;\n let upper = rhs.upper;\n if (lower + this.lower >= Uint64._base) {\n lower -= Uint64._base;\n upper += 1;\n }\n\n this.lower += lower;\n this.upper += upper;\n this.assertConstraints();\n }\n\n public setFromId(id: Id64String): void {\n Id64.getUint32Pair(id, this);\n }\n\n public copyFrom(other: Uint64): void {\n this.lower = other.lower;\n this.upper = other.upper;\n }\n\n public toString(): string {\n if (0 === this.upper)\n return this.lower.toString(16).toUpperCase();\n\n const upper = this.upper.toString(16);\n const lower = this.lower.toString(16).padStart(8, \"0\");\n assert(lower.length === 8);\n return `${upper}${lower}`.toUpperCase();\n }\n\n public toId64String(): string {\n return Id64.fromUint32Pair(this.lower, this.upper);\n }\n }\n\n /** Supplies an iterator over the [[Id64String]]s in a [[CompressedId64Set]].\n * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.\n */\n export function* iterator(ids: CompressedId64Set): Iterator<Id64String> {\n if (0 === ids.length)\n return; // empty set.\n\n if (\"+\" !== ids[0])\n throw new Error(\"Invalid CompressedId64Set\");\n\n let curIndex = 1; // skip the leading '+'\n const curId = new Uint64();\n\n function parseUint32(): number {\n let value = 0;\n let nChars = 0;\n while (curIndex < ids.length && nChars < 8) {\n ++nChars;\n const ch = ids.charCodeAt(curIndex);\n if (!isHexDigit(ch))\n break; // not a hex digit in [0..9] or [A..F]\n\n value <<= 4;\n value |= (ch >= 65 ? ch - 65 + 10 : ch - 48); // ch - 'A' + 10 or ch - '0'\n value = value >>> 0; // restore unsignedness because silly javascript.\n ++curIndex;\n }\n\n return value;\n }\n\n function parseUint64(uint64: Uint64): void {\n let lower = 0;\n let upper = 0;\n\n // Read up to the first 8 digits.\n const startIndex = curIndex;\n const first = parseUint32();\n\n const nFirstDigits = curIndex - startIndex;\n assert(nFirstDigits <= 8);\n\n if (8 === nFirstDigits && curIndex + 1 < ids.length && isHexDigit(ids.charCodeAt(curIndex + 1))) {\n // We've got up to 8 more digits remaining\n const secondIndex = curIndex;\n const second = parseUint32();\n\n // Transfer excess digits from upper to lower.\n const nSecondDigits = curIndex - secondIndex;\n assert(nSecondDigits > 0 && nSecondDigits <= 8);\n\n const nDigitsToTransfer = 8 - nSecondDigits;\n upper = first >>> (4 * nDigitsToTransfer);\n const transfer = first - ((upper << (4 * nDigitsToTransfer)) >>> 0);\n lower = (second | ((transfer << (4 * nSecondDigits)) >>> 0)) >>> 0;\n } else {\n lower = first;\n }\n\n uint64.lower = lower;\n uint64.upper = upper;\n }\n\n const increment = new Uint64();\n while (curIndex < ids.length) {\n let multiplier = 1;\n parseUint64(increment);\n if (increment.isZero)\n throw new Error(\"Invalid CompressedId64Set\");\n\n if (curIndex < ids.length) {\n switch (ids[curIndex++]) {\n case \"*\":\n multiplier = parseUint32();\n if (0 === multiplier)\n throw new Error(\"Invalid CompressedId64Set\");\n\n if (curIndex !== ids.length && ids[curIndex++] !== \"+\")\n return;\n\n break;\n case \"+\":\n break;\n default:\n throw new Error(\"Invalid CompressedId64Set\");\n }\n }\n\n for (let i = 0; i < multiplier; i++) {\n curId.add(increment);\n yield curId.toId64String();\n }\n }\n }\n\n /** Supplies an iterable over the [[Id64String]]s in a [[CompressedId64Set]].\n * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.\n */\n export function iterable(ids: CompressedId64Set): OrderedId64Iterable {\n return {\n [Symbol.iterator]: () => iterator(ids),\n };\n }\n\n /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Set]].\n * @param compressedIds The compact string representation.\n * @param out If supplied, the Ids will be inserted into this set rather than allocating and returning a new set.\n * @returns The set containing the decompressed Ids.\n * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].\n * @see [[CompressedId64Set.compressSet]] to perform the inverse operation.\n * @see [[CompressedId64Set.decompressArray]] to decompress as an [[Id64Array]] instead.\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.\n */\n export function decompressSet(compressedIds: CompressedId64Set, out?: Id64Set): Id64Set {\n const set = out ?? new Set<string>();\n for (const id of iterable(compressedIds))\n set.add(id);\n\n return set;\n }\n\n /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Array]].\n * @param compressedIds The compact string representation.\n * @param out If supplied, the Ids will be appended to this array rather than allocating and returning a new array.\n * @returns The array containing the decompressed Ids.\n * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].\n * @note The Ids are decompressed and appended to the array in ascending order based on their 64-bit numerical values.\n * @see [[CompressedId64Set.compressArray]] to perform the inverse operation.\n * @see [[CompressedId64Set.decompressSet]] to decompress as an [[Id64Set]] instead.\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.\n */\n export function decompressArray(compressedIds: CompressedId64Set, out?: Id64Array): Id64Array {\n const arr = out ?? [];\n for (const id of iterable(compressedIds))\n arr.push(id);\n\n return arr;\n }\n}\n\n/** A [[SortedArray]] of unique [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer values of the Ids.\n * @see [[CompressedId64Set]] for an immutable compact string representation.\n * @public\n */\nexport class OrderedId64Array extends SortedArray<Id64String> {\n /** Construct a new, empty array. */\n public constructor() {\n super((lhs, rhs) => OrderedId64Iterable.compare(lhs, rhs));\n }\n\n /** An iterable that iterates over the Ids in sorted order. */\n public get ids(): OrderedId64Iterable { return this._array; }\n\n /** The underlying array of Ids. */\n public get array(): ReadonlyArray<Id64String> { return this._array; }\n}\n\n/** A mutable set of valid [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer value of the Ids.\n * Internally the set of Ids is maintained as a [[CompressedId64Set]] string representation.\n * Insertions and removals are buffered until the string representation needs to be recomputed. The string representation is recomputed by every public method except [[add]] and [[delete]] -\n * therefore, if multiple removals and/or insertions are required, it is most efficient to perform them all before invoking other methods.\n * @public\n */\nexport class MutableCompressedId64Set implements OrderedId64Iterable {\n private _ids: CompressedId64Set;\n private readonly _inserted = new OrderedId64Array();\n private readonly _deleted = new OrderedId64Array();\n\n /** Construct a new set, optionally initialized to contain the Ids represented by `ids`. */\n public constructor(ids?: CompressedId64Set) {\n this._ids = ids ?? \"\";\n }\n\n /** Obtain the compact string representation of the contents of this set. If any insertions or removals are pending, they will be applied and the string recomputed. */\n public get ids(): CompressedId64Set {\n this.updateIds();\n return this._ids;\n }\n\n /** Add the specified Id to the set.\n * @throws Error if `id` is not a valid [[Id64String]].\n */\n public add(id: Id64String): void {\n if (!Id64.isValidId64(id))\n throw new Error(\"MutableCompressedId64Set.add: invalid Id\");\n\n this._deleted.remove(id);\n this._inserted.insert(id);\n }\n\n /** Remove the specified Id from the set.\n * @throws Error if `id` is not a valid [[Id64String]].\n */\n public delete(id: Id64String): void {\n if (!Id64.isValidId64(id))\n throw new Error(\"MutableCompressedId64Set.delete: invalid Id\");\n\n this._inserted.remove(id);\n this._deleted.insert(id);\n }\n\n /** Remove all Ids from the set. */\n public clear(): void {\n this._ids = \"\";\n this._inserted.clear();\n this._deleted.clear();\n }\n\n /** Remove all Ids from the set, then add the specified Ids. */\n public reset(ids?: CompressedId64Set): void {\n this.clear();\n this._ids = ids ?? \"\";\n }\n\n /** Obtain an iterator over the Ids in this set. The Ids are returned in ascending order based on their unsigned 64-bit integer values. */\n public [Symbol.iterator]() {\n return CompressedId64Set.iterator(this.ids);\n }\n\n /** Compute a compact string representation of the union of this and another set of Ids - i.e., those Ids present in either this and/or the other set. */\n public computeUnion(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\n if (this.isEmpty)\n return CompressedId64Set.compressIds(ids);\n else if (OrderedId64Iterable.isEmptySet(ids) || this.equals(ids))\n return this.ids;\n\n return CompressedId64Set.compressIds(OrderedId64Iterable.union(this, ids));\n }\n\n /** Compute a compact string representation of the intersection of this and another set of Ids - i.e., those Ids present in both this and the other set. */\n public computeIntersection(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\n if (this.equals(ids))\n return this.ids;\n else if (this.isEmpty || OrderedId64Iterable.isEmptySet(ids))\n return \"\";\n\n return CompressedId64Set.compressIds(OrderedId64Iterable.intersection(this, ids));\n }\n\n /** Compute a compact string representation of the difference between this and another set - i.e., those Ids present in this but not in the other set. */\n public computeDifference(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\n if (this.isEmpty || this.equals(ids))\n return \"\";\n\n return CompressedId64Set.compressIds(OrderedId64Iterable.difference(this, ids));\n }\n\n /** Return true if this set contains no Ids. */\n public get isEmpty(): boolean {\n return OrderedId64Iterable.isEmptySet(this.ids);\n }\n\n /** Return true if the set of Ids represented by `other` is identical to those in this set.\n * @note This considers only the **distinct** Ids in `other` - duplicates are ignored.\n */\n public equals(other: CompressedId64Set | MutableCompressedId64Set | OrderedId64Iterable): boolean {\n if (other instanceof MutableCompressedId64Set) {\n if (other === this)\n return true;\n\n if (typeof other !== \"string\")\n other = other.ids;\n }\n\n if (typeof other === \"string\")\n return other === this.ids;\n\n this.updateIds();\n return OrderedId64Iterable.areEqualSets(this, other);\n }\n\n private get _isDirty(): boolean {\n return !this._inserted.isEmpty || !this._deleted.isEmpty;\n }\n\n private updateIds(): void {\n if (!this._isDirty)\n return;\n\n const difference = OrderedId64Iterable.difference(CompressedId64Set.iterable(this._ids), this._deleted.ids);\n const union = { [Symbol.iterator]: () => OrderedId64Iterable.unionIterator(difference, this._inserted.ids) };\n this._ids = CompressedId64Set.compressIds(union);\n\n this._inserted.clear();\n this._deleted.clear();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CompressedId64Set.js","sourceRoot":"","sources":["../../src/CompressedId64Set.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAkC;AAClC,6BAA4D;AAC5D,+DAA4D;AAC5D,+CAA4C;AAK5C;;;;;;;;GAQG;AACH,IAAiB,iBAAiB,CAoUjC;AApUD,WAAiB,iBAAiB;IAChC,SAAS,UAAU,CAAC,EAAU;QAC5B,gBAAgB;QAChB,WAAW;QACX,WAAW;QACX,WAAW;QACX,WAAW;QAEX,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,I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------------------------------\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 { Id64, Id64Array, Id64Set, Id64String } from \"./Id\";\r\nimport { OrderedId64Iterable } from \"./OrderedId64Iterable\";\r\nimport { SortedArray } from \"./SortedArray\";\r\n\r\n/** @public */\r\nexport type CompressedId64Set = string;\r\n\r\n/** A compact string representation of an [[Id64Set]]. Such a representation is useful when serializing potentially very large\r\n * sets of Ids.\r\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids represented by a compact string.\r\n * @see [[CompressedId64Set.compressSet]] and [[CompressedId64Set.compressArray]] to produce a compact string from a collection of Ids.\r\n * @see [[CompressedId64Set.decompressSet]] and [[CompressedId64Set.decompressArray]] to produce a collection of Ids from a compact string.\r\n * @see [[OrderedId64Iterable]] for a generic representation of an ordered set of Ids (compressed or otherwise).\r\n * @see [[MutableCompressedId64Set]] for a mutable version.\r\n * @public\r\n */\r\nexport namespace CompressedId64Set { // eslint-disable-line @typescript-eslint/no-redeclare\r\n function isHexDigit(ch: number): boolean {\r\n // ascii values:\r\n // '0' = 48\r\n // '9' = 57\r\n // 'a' = 65\r\n // 'f' = 70\r\n\r\n return (ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 70);\r\n }\r\n\r\n function compactRange(increment: Uint64, length: number): string {\r\n assert(length > 0);\r\n const inc = `+${increment.toString()}`;\r\n if (length <= 1)\r\n return inc;\r\n\r\n const len = length.toString(16).toUpperCase();\r\n return `${inc}*${len}`;\r\n }\r\n\r\n /** Given a set of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\r\n * @note Invalid Ids are ignored.\r\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\r\n * @see [[CompressedId64Set.compressArray]] to perform the same operation on an [[Id64Array]].\r\n * @see [[CompressedId64Set.decompressSet]] to perform the inverse operation.\r\n */\r\n export function compressSet(ids: Id64Set): CompressedId64Set {\r\n return sortAndCompress(ids);\r\n }\r\n\r\n /** Create a sorted array from `ids`, then return a compact string representation of those Ids.\r\n * @see [[CompressedId64Set.compressIds]] if `ids` is known to already be sorted.\r\n */\r\n export function sortAndCompress(ids: Iterable<Id64String>): CompressedId64Set {\r\n // `string` is an Iterable<string>. In that case assume caller passed a single Id64String.\r\n const arr = typeof ids === \"string\" ? [ids] : Array.from(ids);\r\n OrderedId64Iterable.sortArray(arr);\r\n return compressArray(arr);\r\n }\r\n\r\n /** Give a **numerically-ordered** array of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\r\n * Duplicate Ids are included only once in the string representation.\r\n * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the array is not properly sorted.\r\n * @note The array must be sorted according to the 64-bit numerical value of each Id.\r\n * @note Invalid Ids are ignored.\r\n * @see [[CompressedId64Set.decompressArray]] to perform the inverse operation.\r\n * @see [[OrderedId64Iterable.sortArray]] to ensure the Ids are properly sorted.\r\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\r\n */\r\n export function compressArray(ids: Id64Array): CompressedId64Set {\r\n return compressIds(ids);\r\n }\r\n\r\n /** Give a **numerically-ordered** collection of [[Id64String]]s, produce a compact string representation. Useful when serializing potentially large sets of Ids.\r\n * Duplicate Ids are included only once in the string representation.\r\n * @throws Error if two consecutive Ids `x` and `y` exist such that the numerical value of `x` is greater than that of `y` - i.e., the collection is not properly sorted.\r\n * @note The collection must be sorted according to the 64-bit numerical value of each Id.\r\n * @note Invalid Ids are ignored.\r\n * @see [[CompressedId64Set.iterable]] to perform the inverse operation.\r\n * @see [[OrderedId64Iterable.sortArray]] or [[OrderedId64Iterable.compare]] to ensure the Ids are properly sorted.\r\n * @see [[CompressedId64Set.sortAndCompress]] to compress any unordered collection of Ids.\r\n */\r\n export function compressIds(ids: OrderedId64Iterable): CompressedId64Set {\r\n if (\"string\" === typeof ids)\r\n return ids;\r\n\r\n let str = \"\";\r\n\r\n const prevId = new Uint64();\r\n const rangeIncrement = new Uint64();\r\n let rangeLen = 0;\r\n\r\n const curId = new Uint64();\r\n const curIncrement = new Uint64();\r\n for (const id of ids) {\r\n if (!Id64.isValidId64(id))\r\n continue; // ignore garbage and invalid Ids (\"0\")\r\n\r\n curId.setFromId(id);\r\n curIncrement.setFromDifference(curId, prevId);\r\n\r\n const cmp = prevId.compare(curId);\r\n if (0 === cmp)\r\n continue; // ignore duplicates\r\n else if (cmp > 0)\r\n throw new Error(\"CompressedId64Set.compressArray requires a sorted array as input\");\r\n\r\n prevId.copyFrom(curId);\r\n\r\n if (0 === rangeLen) {\r\n rangeIncrement.copyFrom(curIncrement);\r\n rangeLen = 1;\r\n } else if (curIncrement.equals(rangeIncrement)) {\r\n ++rangeLen;\r\n } else {\r\n str += compactRange(rangeIncrement, rangeLen);\r\n rangeIncrement.copyFrom(curIncrement);\r\n rangeLen = 1;\r\n }\r\n }\r\n\r\n if (0 < rangeLen)\r\n str += compactRange(rangeIncrement, rangeLen);\r\n\r\n return str;\r\n }\r\n\r\n /** This exists strictly for the purposes of compressed sets of 64-bit Ids, to avoid the overhead of BigInt for handling 64-bit integers. */\r\n class Uint64 implements Id64.Uint32Pair {\r\n private static readonly _base = 0x100000000;\r\n\r\n private static assertUint32(num: number): void {\r\n assert(num >= 0);\r\n assert(num < Uint64._base);\r\n assert(Math.floor(num) === num);\r\n }\r\n\r\n private assertConstraints(): void {\r\n Uint64.assertUint32(this.lower);\r\n Uint64.assertUint32(this.upper);\r\n }\r\n\r\n constructor(public lower = 0, public upper = 0) {\r\n this.assertConstraints();\r\n }\r\n\r\n public compare(rhs: Uint64): number {\r\n const diff = this.upper - rhs.upper;\r\n return 0 === diff ? this.lower - rhs.lower : diff;\r\n }\r\n\r\n public equals(rhs: Uint64): boolean { return 0 === this.compare(rhs); }\r\n public isLessThan(rhs: Uint64): boolean { return this.compare(rhs) < 0; }\r\n public isGreaterThan(rhs: Uint64): boolean { return this.compare(rhs) > 0; }\r\n\r\n public get isZero(): boolean { return 0 === this.lower && 0 === this.upper; }\r\n\r\n public setFromDifference(lhs: Uint64, rhs: Uint64): void {\r\n assert(!rhs.isGreaterThan(lhs));\r\n\r\n this.lower = lhs.lower - rhs.lower;\r\n this.upper = lhs.upper - rhs.upper;\r\n if (this.lower < 0) {\r\n this.lower += Uint64._base;\r\n this.upper -= 1;\r\n }\r\n }\r\n\r\n public add(rhs: Uint64): void {\r\n let lower = rhs.lower;\r\n let upper = rhs.upper;\r\n if (lower + this.lower >= Uint64._base) {\r\n lower -= Uint64._base;\r\n upper += 1;\r\n }\r\n\r\n this.lower += lower;\r\n this.upper += upper;\r\n this.assertConstraints();\r\n }\r\n\r\n public setFromId(id: Id64String): void {\r\n Id64.getUint32Pair(id, this);\r\n }\r\n\r\n public copyFrom(other: Uint64): void {\r\n this.lower = other.lower;\r\n this.upper = other.upper;\r\n }\r\n\r\n public toString(): string {\r\n if (0 === this.upper)\r\n return this.lower.toString(16).toUpperCase();\r\n\r\n const upper = this.upper.toString(16);\r\n const lower = this.lower.toString(16).padStart(8, \"0\");\r\n assert(lower.length === 8);\r\n return `${upper}${lower}`.toUpperCase();\r\n }\r\n\r\n public toId64String(): string {\r\n return Id64.fromUint32Pair(this.lower, this.upper);\r\n }\r\n }\r\n\r\n /** Supplies an iterator over the [[Id64String]]s in a [[CompressedId64Set]].\r\n * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.\r\n */\r\n export function* iterator(ids: CompressedId64Set): Iterator<Id64String> {\r\n if (0 === ids.length)\r\n return; // empty set.\r\n\r\n if (\"+\" !== ids[0])\r\n throw new Error(\"Invalid CompressedId64Set\");\r\n\r\n let curIndex = 1; // skip the leading '+'\r\n const curId = new Uint64();\r\n\r\n function parseUint32(): number {\r\n let value = 0;\r\n let nChars = 0;\r\n while (curIndex < ids.length && nChars < 8) {\r\n ++nChars;\r\n const ch = ids.charCodeAt(curIndex);\r\n if (!isHexDigit(ch))\r\n break; // not a hex digit in [0..9] or [A..F]\r\n\r\n value <<= 4;\r\n value |= (ch >= 65 ? ch - 65 + 10 : ch - 48); // ch - 'A' + 10 or ch - '0'\r\n value = value >>> 0; // restore unsignedness because silly javascript.\r\n ++curIndex;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n function parseUint64(uint64: Uint64): void {\r\n let lower = 0;\r\n let upper = 0;\r\n\r\n // Read up to the first 8 digits.\r\n const startIndex = curIndex;\r\n const first = parseUint32();\r\n\r\n const nFirstDigits = curIndex - startIndex;\r\n assert(nFirstDigits <= 8);\r\n\r\n if (8 === nFirstDigits && curIndex + 1 < ids.length && isHexDigit(ids.charCodeAt(curIndex + 1))) {\r\n // We've got up to 8 more digits remaining\r\n const secondIndex = curIndex;\r\n const second = parseUint32();\r\n\r\n // Transfer excess digits from upper to lower.\r\n const nSecondDigits = curIndex - secondIndex;\r\n assert(nSecondDigits > 0 && nSecondDigits <= 8);\r\n\r\n const nDigitsToTransfer = 8 - nSecondDigits;\r\n upper = first >>> (4 * nDigitsToTransfer);\r\n const transfer = first - ((upper << (4 * nDigitsToTransfer)) >>> 0);\r\n lower = (second | ((transfer << (4 * nSecondDigits)) >>> 0)) >>> 0;\r\n } else {\r\n lower = first;\r\n }\r\n\r\n uint64.lower = lower;\r\n uint64.upper = upper;\r\n }\r\n\r\n const increment = new Uint64();\r\n while (curIndex < ids.length) {\r\n let multiplier = 1;\r\n parseUint64(increment);\r\n if (increment.isZero)\r\n throw new Error(\"Invalid CompressedId64Set\");\r\n\r\n if (curIndex < ids.length) {\r\n switch (ids[curIndex++]) {\r\n case \"*\":\r\n multiplier = parseUint32();\r\n if (0 === multiplier)\r\n throw new Error(\"Invalid CompressedId64Set\");\r\n\r\n if (curIndex !== ids.length && ids[curIndex++] !== \"+\")\r\n return;\r\n\r\n break;\r\n case \"+\":\r\n break;\r\n default:\r\n throw new Error(\"Invalid CompressedId64Set\");\r\n }\r\n }\r\n\r\n for (let i = 0; i < multiplier; i++) {\r\n curId.add(increment);\r\n yield curId.toId64String();\r\n }\r\n }\r\n }\r\n\r\n /** Supplies an iterable over the [[Id64String]]s in a [[CompressedId64Set]].\r\n * The Ids are iterated in ascending order based on their unsigned 64-bit integer values.\r\n */\r\n export function iterable(ids: CompressedId64Set): OrderedId64Iterable {\r\n return {\r\n [Symbol.iterator]: () => iterator(ids),\r\n };\r\n }\r\n\r\n /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Set]].\r\n * @param compressedIds The compact string representation.\r\n * @param out If supplied, the Ids will be inserted into this set rather than allocating and returning a new set.\r\n * @returns The set containing the decompressed Ids.\r\n * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].\r\n * @see [[CompressedId64Set.compressSet]] to perform the inverse operation.\r\n * @see [[CompressedId64Set.decompressArray]] to decompress as an [[Id64Array]] instead.\r\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.\r\n */\r\n export function decompressSet(compressedIds: CompressedId64Set, out?: Id64Set): Id64Set {\r\n const set = out ?? new Set<string>();\r\n for (const id of iterable(compressedIds))\r\n set.add(id);\r\n\r\n return set;\r\n }\r\n\r\n /** Decompress the compact string representation of an [[Id64Set]] into an [[Id64Array]].\r\n * @param compressedIds The compact string representation.\r\n * @param out If supplied, the Ids will be appended to this array rather than allocating and returning a new array.\r\n * @returns The array containing the decompressed Ids.\r\n * @throws Error if `compressedIds` is not a well-formed [[CompressedId64Set]].\r\n * @note The Ids are decompressed and appended to the array in ascending order based on their 64-bit numerical values.\r\n * @see [[CompressedId64Set.compressArray]] to perform the inverse operation.\r\n * @see [[CompressedId64Set.decompressSet]] to decompress as an [[Id64Set]] instead.\r\n * @see [[CompressedId64Set.iterable]] to efficiently iterate the Ids.\r\n */\r\n export function decompressArray(compressedIds: CompressedId64Set, out?: Id64Array): Id64Array {\r\n const arr = out ?? [];\r\n for (const id of iterable(compressedIds))\r\n arr.push(id);\r\n\r\n return arr;\r\n }\r\n}\r\n\r\n/** A [[SortedArray]] of unique [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer values of the Ids.\r\n * @see [[CompressedId64Set]] for an immutable compact string representation.\r\n * @public\r\n */\r\nexport class OrderedId64Array extends SortedArray<Id64String> {\r\n /** Construct a new, empty array. */\r\n public constructor() {\r\n super((lhs, rhs) => OrderedId64Iterable.compare(lhs, rhs));\r\n }\r\n\r\n /** An iterable that iterates over the Ids in sorted order. */\r\n public get ids(): OrderedId64Iterable { return this._array; }\r\n\r\n /** The underlying array of Ids. */\r\n public get array(): ReadonlyArray<Id64String> { return this._array; }\r\n}\r\n\r\n/** A mutable set of valid [[Id64String]]s sorted in ascending order by the 64-bit unsigned integer value of the Ids.\r\n * Internally the set of Ids is maintained as a [[CompressedId64Set]] string representation.\r\n * Insertions and removals are buffered until the string representation needs to be recomputed. The string representation is recomputed by every public method except [[add]] and [[delete]] -\r\n * therefore, if multiple removals and/or insertions are required, it is most efficient to perform them all before invoking other methods.\r\n * @public\r\n */\r\nexport class MutableCompressedId64Set implements OrderedId64Iterable {\r\n private _ids: CompressedId64Set;\r\n private readonly _inserted = new OrderedId64Array();\r\n private readonly _deleted = new OrderedId64Array();\r\n\r\n /** Construct a new set, optionally initialized to contain the Ids represented by `ids`. */\r\n public constructor(ids?: CompressedId64Set) {\r\n this._ids = ids ?? \"\";\r\n }\r\n\r\n /** Obtain the compact string representation of the contents of this set. If any insertions or removals are pending, they will be applied and the string recomputed. */\r\n public get ids(): CompressedId64Set {\r\n this.updateIds();\r\n return this._ids;\r\n }\r\n\r\n /** Add the specified Id to the set.\r\n * @throws Error if `id` is not a valid [[Id64String]].\r\n */\r\n public add(id: Id64String): void {\r\n if (!Id64.isValidId64(id))\r\n throw new Error(\"MutableCompressedId64Set.add: invalid Id\");\r\n\r\n this._deleted.remove(id);\r\n this._inserted.insert(id);\r\n }\r\n\r\n /** Remove the specified Id from the set.\r\n * @throws Error if `id` is not a valid [[Id64String]].\r\n */\r\n public delete(id: Id64String): void {\r\n if (!Id64.isValidId64(id))\r\n throw new Error(\"MutableCompressedId64Set.delete: invalid Id\");\r\n\r\n this._inserted.remove(id);\r\n this._deleted.insert(id);\r\n }\r\n\r\n /** Remove all Ids from the set. */\r\n public clear(): void {\r\n this._ids = \"\";\r\n this._inserted.clear();\r\n this._deleted.clear();\r\n }\r\n\r\n /** Remove all Ids from the set, then add the specified Ids. */\r\n public reset(ids?: CompressedId64Set): void {\r\n this.clear();\r\n this._ids = ids ?? \"\";\r\n }\r\n\r\n /** Obtain an iterator over the Ids in this set. The Ids are returned in ascending order based on their unsigned 64-bit integer values. */\r\n public [Symbol.iterator]() {\r\n return CompressedId64Set.iterator(this.ids);\r\n }\r\n\r\n /** Compute a compact string representation of the union of this and another set of Ids - i.e., those Ids present in either this and/or the other set. */\r\n public computeUnion(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\r\n if (this.isEmpty)\r\n return CompressedId64Set.compressIds(ids);\r\n else if (OrderedId64Iterable.isEmptySet(ids) || this.equals(ids))\r\n return this.ids;\r\n\r\n return CompressedId64Set.compressIds(OrderedId64Iterable.union(this, ids));\r\n }\r\n\r\n /** Compute a compact string representation of the intersection of this and another set of Ids - i.e., those Ids present in both this and the other set. */\r\n public computeIntersection(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\r\n if (this.equals(ids))\r\n return this.ids;\r\n else if (this.isEmpty || OrderedId64Iterable.isEmptySet(ids))\r\n return \"\";\r\n\r\n return CompressedId64Set.compressIds(OrderedId64Iterable.intersection(this, ids));\r\n }\r\n\r\n /** Compute a compact string representation of the difference between this and another set - i.e., those Ids present in this but not in the other set. */\r\n public computeDifference(ids: OrderedId64Iterable | CompressedId64Set | MutableCompressedId64Set): CompressedId64Set {\r\n if (this.isEmpty || this.equals(ids))\r\n return \"\";\r\n\r\n return CompressedId64Set.compressIds(OrderedId64Iterable.difference(this, ids));\r\n }\r\n\r\n /** Return true if this set contains no Ids. */\r\n public get isEmpty(): boolean {\r\n return OrderedId64Iterable.isEmptySet(this.ids);\r\n }\r\n\r\n /** Return true if the set of Ids represented by `other` is identical to those in this set.\r\n * @note This considers only the **distinct** Ids in `other` - duplicates are ignored.\r\n */\r\n public equals(other: CompressedId64Set | MutableCompressedId64Set | OrderedId64Iterable): boolean {\r\n if (other instanceof MutableCompressedId64Set) {\r\n if (other === this)\r\n return true;\r\n\r\n if (typeof other !== \"string\")\r\n other = other.ids;\r\n }\r\n\r\n if (typeof other === \"string\")\r\n return other === this.ids;\r\n\r\n this.updateIds();\r\n return OrderedId64Iterable.areEqualSets(this, other);\r\n }\r\n\r\n private get _isDirty(): boolean {\r\n return !this._inserted.isEmpty || !this._deleted.isEmpty;\r\n }\r\n\r\n private updateIds(): void {\r\n if (!this._isDirty)\r\n return;\r\n\r\n const difference = OrderedId64Iterable.difference(CompressedId64Set.iterable(this._ids), this._deleted.ids);\r\n const union = { [Symbol.iterator]: () => OrderedId64Iterable.unionIterator(difference, this._inserted.ids) };\r\n this._ids = CompressedId64Set.compressIds(union);\r\n\r\n this._inserted.clear();\r\n this._deleted.clear();\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dictionary.js","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,+CAAwE;AAExE,MAAM,kBAAkB;IACd,KAAK,CAAM;IACX,OAAO,CAAM;IACb,SAAS,GAAG,CAAC,CAAC,CAAC;IAEvB,YAAmB,IAAS,EAAE,MAAW;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,IAAI;QACT,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1C,0JAA0J;YAC1J,O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,CAAC,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,MAAM,KAAK,GAAgC,EAAE,CAAC;QAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,aAAa;QAClB,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAgC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAM,IAAuC,OAAO,IAAA,wBAAU,EAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H;AA/KD,gCA+KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Collections\n */\n\nimport { OrderedComparator } from \"./Compare\";\nimport { CloneFunction, lowerBound, shallowClone } from \"./SortedArray\";\n\nclass DictionaryIterator<K, V> implements Iterator<DictionaryEntry<K, V>> {\n private _keys: K[];\n private _values: V[];\n private _curIndex = -1;\n\n public constructor(keys: K[], values: V[]) {\n this._keys = keys;\n this._values = values;\n }\n\n public next(): IteratorResult<DictionaryEntry<K, V>> {\n if (++this._curIndex >= this._keys.length) {\n // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.\n return { done: true } as any as IteratorResult<DictionaryEntry<K, V>>;\n } else {\n return {\n value: {\n key: this._keys[this._curIndex],\n value: this._values[this._curIndex],\n },\n done: false,\n };\n }\n }\n}\n\n/**\n * Represents an entry in a [[Dictionary]].\n * @public\n */\nexport interface DictionaryEntry<K, V> {\n /** The key used for lookup in the Dictionary. */\n key: K;\n /** The value associated with the key in the Dictionary. */\n value: V;\n}\n\n/**\n * Maintains a mapping of keys to values.\n * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).\n * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:\n * - If lhs is equal to rhs, returns 0\n * - If lhs is less than rhs, returns a negative value\n * - If lhs is greater than rhs, returns a positive value\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\n *\n * Modifying a key in a way that affects the comparison function will produce unpredictable results, the\n * most likely of which is that keys will cease to map to the values with which they were initially inserted.\n * @public\n */\nexport class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {\n protected _keys: K[] = [];\n protected readonly _compareKeys: OrderedComparator<K>;\n protected readonly _cloneKey: CloneFunction<K>;\n protected _values: V[] = [];\n protected readonly _cloneValue: CloneFunction<V>;\n\n /**\n * Construct a new Dictionary<K, V>.\n * @param compareKeys The function used to compare keys within the dictionary.\n * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.\n * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.\n */\n public constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone) {\n this._compareKeys = compareKeys;\n this._cloneKey = cloneKey;\n this._cloneValue = cloneValue;\n }\n\n /** The number of entries in the dictionary. */\n public get size(): number { return this._keys.length; }\n\n /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */\n public [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> {\n return new DictionaryIterator<K, V>(this._keys, this._values);\n }\n\n /** Provides iteration over the keys in this Dictionary, in sorted order. */\n public keys(): Iterable<K> {\n function * iterator(dict: Dictionary<K, V>) {\n for (const entry of dict)\n yield entry.key;\n }\n\n return {\n [Symbol.iterator]: () => iterator(this),\n };\n }\n\n /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */\n public values(): Iterable<V> {\n function * iterator(dict: Dictionary<K, V>) {\n for (const entry of dict)\n yield entry.value;\n }\n\n return {\n [Symbol.iterator]: () => iterator(this),\n };\n }\n\n /** Removes all entries from this dictionary */\n public clear(): void {\n this._keys = [];\n this._values = [];\n }\n\n /**\n * Looks up a value by its key.\n * @param key The key to search for\n * @returns the value associated with the key, or undefined if the key is not present in the dictionary.\n */\n public get(key: K): V | undefined {\n const bound = this.lowerBound(key);\n return bound.equal ? this._values[bound.index] : undefined;\n }\n\n /**\n * Determines if an entry exists for the specified key\n * @param key The key to search for\n * @returns true if an entry exists in this dictionary corresponding to the specified key.\n */\n public has(key: K): boolean {\n return this.lowerBound(key).equal;\n }\n\n /**\n * Deletes a value using its key.\n * @param key The key to delete\n * @returns true if the key was found and deleted.\n */\n public delete(key: K): boolean {\n const bound = this.lowerBound(key);\n if (bound.equal) {\n this._values.splice(bound.index, 1);\n this._keys.splice(bound.index, 1);\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.\n * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.\n * @param key The key to associate with the value\n * @param value The value to associate with the key\n * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.\n */\n public insert(key: K, value: V): boolean {\n const result = this.findOrInsert(key, value);\n return result.inserted;\n }\n\n /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.\n * @param key The key to search for.\n * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.\n * @returns The found or inserted value and a flag indicating whether the new value was inserted.\n */\n public findOrInsert(key: K, value: V): { value: V, inserted: boolean } {\n const bound = this.lowerBound(key);\n if (bound.equal)\n return { value: this._values[bound.index], inserted: false };\n\n value = this._cloneValue(value);\n this._keys.splice(bound.index, 0, this._cloneKey(key));\n this._values.splice(bound.index, 0, this._cloneValue(value));\n return { value, inserted: true };\n }\n\n /**\n * Sets the value associated with the specified key in the dictionary.\n * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.\n * In either case, the value will be cloned using the function supplied to the dictionary's constructor.\n */\n public set(key: K, value: V): void {\n value = this._cloneValue(value);\n const bound = this.lowerBound(key);\n if (bound.equal) {\n this._values[bound.index] = value;\n } else {\n this._keys.splice(bound.index, 0, this._cloneKey(key));\n this._values.splice(bound.index, 0, value);\n }\n }\n\n /**\n * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.\n * @returns An array of { key, value } pairs sorted by key.\n */\n public extractPairs(): Array<{ key: K, value: V }> {\n const pairs: Array<{ key: K, value: V }> = [];\n for (let i = 0; i < this.size; i++)\n pairs.push({ key: this._keys[i], value: this._values[i] });\n\n this.clear();\n return pairs;\n }\n\n /**\n * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.\n * The array of keys is sorted according to the comparison criterion.\n * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.\n * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.\n */\n public extractArrays(): { keys: K[], values: V[] } {\n const result = { keys: this._keys, values: this._values };\n this.clear();\n return result;\n }\n\n /** Apply a function to each (key, value) pair in the dictionary, in sorted order.\n * @param func The function to be applied.\n */\n public forEach(func: (key: K, value: V) => void): void {\n for (let i = 0; i < this.size; i++)\n func(this._keys[i], this._values[i]);\n }\n\n /**\n * Computes the position at which the specified key should be inserted to maintain sorted order.\n * @param key The key whose position is to be computed.\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent key already exists at that index.\n */\n protected lowerBound(key: K): { index: number, equal: boolean } { return lowerBound(key, this._keys, this._compareKeys); }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Dictionary.js","sourceRoot":"","sources":["../../src/Dictionary.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,+CAAwE;AAExE,MAAM,kBAAkB;IACd,KAAK,CAAM;IACX,OAAO,CAAM;IACb,SAAS,GAAG,CAAC,CAAC,CAAC;IAEvB,YAAmB,IAAS,EAAE,MAAW;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEM,IAAI;QACT,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1C,0JAA0J;YAC1J,OAAO,EAAE,IAAI,EAAE,IAAI,EAAkD,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,KAAK,EAAE;oBACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;iBACpC;gBACD,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAaD;;;;;;;;;;;;;GAaG;AACH,MAAa,UA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CAAC,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,aAAa;QAClB,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAgC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAM,IAAuC,OAAO,IAAA,wBAAU,EAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H;AA/KD,gCA+KC","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\nimport { CloneFunction, lowerBound, shallowClone } from \"./SortedArray\";\r\n\r\nclass DictionaryIterator<K, V> implements Iterator<DictionaryEntry<K, V>> {\r\n private _keys: K[];\r\n private _values: V[];\r\n private _curIndex = -1;\r\n\r\n public constructor(keys: K[], values: V[]) {\r\n this._keys = keys;\r\n this._values = values;\r\n }\r\n\r\n public next(): IteratorResult<DictionaryEntry<K, V>> {\r\n if (++this._curIndex >= this._keys.length) {\r\n // The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below.\r\n return { done: true } as any as IteratorResult<DictionaryEntry<K, V>>;\r\n } else {\r\n return {\r\n value: {\r\n key: this._keys[this._curIndex],\r\n value: this._values[this._curIndex],\r\n },\r\n done: false,\r\n };\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents an entry in a [[Dictionary]].\r\n * @public\r\n */\r\nexport interface DictionaryEntry<K, V> {\r\n /** The key used for lookup in the Dictionary. */\r\n key: K;\r\n /** The value associated with the key in the Dictionary. */\r\n value: V;\r\n}\r\n\r\n/**\r\n * Maintains a mapping of keys to values.\r\n * Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type).\r\n * The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K:\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 a key in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that keys will cease to map to the values with which they were initially inserted.\r\n * @public\r\n */\r\nexport class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> {\r\n protected _keys: K[] = [];\r\n protected readonly _compareKeys: OrderedComparator<K>;\r\n protected readonly _cloneKey: CloneFunction<K>;\r\n protected _values: V[] = [];\r\n protected readonly _cloneValue: CloneFunction<V>;\r\n\r\n /**\r\n * Construct a new Dictionary<K, V>.\r\n * @param compareKeys The function used to compare keys within the dictionary.\r\n * @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input.\r\n * @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input.\r\n */\r\n public constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone) {\r\n this._compareKeys = compareKeys;\r\n this._cloneKey = cloneKey;\r\n this._cloneValue = cloneValue;\r\n }\r\n\r\n /** The number of entries in the dictionary. */\r\n public get size(): number { return this._keys.length; }\r\n\r\n /** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */\r\n public [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> {\r\n return new DictionaryIterator<K, V>(this._keys, this._values);\r\n }\r\n\r\n /** Provides iteration over the keys in this Dictionary, in sorted order. */\r\n public keys(): Iterable<K> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.key;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Provides iteration over the values in this Dictionary, in sorted order by the corresponding keys. */\r\n public values(): Iterable<V> {\r\n function * iterator(dict: Dictionary<K, V>) {\r\n for (const entry of dict)\r\n yield entry.value;\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this),\r\n };\r\n }\r\n\r\n /** Removes all entries from this dictionary */\r\n public clear(): void {\r\n this._keys = [];\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Looks up a value by its key.\r\n * @param key The key to search for\r\n * @returns the value associated with the key, or undefined if the key is not present in the dictionary.\r\n */\r\n public get(key: K): V | undefined {\r\n const bound = this.lowerBound(key);\r\n return bound.equal ? this._values[bound.index] : undefined;\r\n }\r\n\r\n /**\r\n * Determines if an entry exists for the specified key\r\n * @param key The key to search for\r\n * @returns true if an entry exists in this dictionary corresponding to the specified key.\r\n */\r\n public has(key: K): boolean {\r\n return this.lowerBound(key).equal;\r\n }\r\n\r\n /**\r\n * Deletes a value using its key.\r\n * @param key The key to delete\r\n * @returns true if the key was found and deleted.\r\n */\r\n public delete(key: K): boolean {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values.splice(bound.index, 1);\r\n this._keys.splice(bound.index, 1);\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified.\r\n * If the new entry is in fact inserted, both the key and value will be cloned using the functions supplied to the dictionary's constructor.\r\n * @param key The key to associate with the value\r\n * @param value The value to associate with the key\r\n * @returns true if the new entry was inserted, false if an entry with an equivalent key already exists.\r\n */\r\n public insert(key: K, value: V): boolean {\r\n const result = this.findOrInsert(key, value);\r\n return result.inserted;\r\n }\r\n\r\n /** Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.\r\n * @param key The key to search for.\r\n * @param value The value to associate with `key` if `key` does not yet exist in the dictionary.\r\n * @returns The found or inserted value and a flag indicating whether the new value was inserted.\r\n */\r\n public findOrInsert(key: K, value: V): { value: V, inserted: boolean } {\r\n const bound = this.lowerBound(key);\r\n if (bound.equal)\r\n return { value: this._values[bound.index], inserted: false };\r\n\r\n value = this._cloneValue(value);\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, this._cloneValue(value));\r\n return { value, inserted: true };\r\n }\r\n\r\n /**\r\n * Sets the value associated with the specified key in the dictionary.\r\n * If no such key already exists, this is equivalent to insert(key, value); otherwise, the existing value associated with the key is replaced.\r\n * In either case, the value will be cloned using the function supplied to the dictionary's constructor.\r\n */\r\n public set(key: K, value: V): void {\r\n value = this._cloneValue(value);\r\n const bound = this.lowerBound(key);\r\n if (bound.equal) {\r\n this._values[bound.index] = value;\r\n } else {\r\n this._keys.splice(bound.index, 0, this._cloneKey(key));\r\n this._values.splice(bound.index, 0, value);\r\n }\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary.\r\n * @returns An array of { key, value } pairs sorted by key.\r\n */\r\n public extractPairs(): Array<{ key: K, value: V }> {\r\n const pairs: Array<{ key: K, value: V }> = [];\r\n for (let i = 0; i < this.size; i++)\r\n pairs.push({ key: this._keys[i], value: this._values[i] });\r\n\r\n this.clear();\r\n return pairs;\r\n }\r\n\r\n /**\r\n * Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary.\r\n * The array of keys is sorted according to the comparison criterion.\r\n * The position of each value in the array of values corresponds the the position of the corresponding key in the array of keys.\r\n * @returns a pair of { keys, values } arrays in which key[i] corresponds to value[i] in this dictionary and the keys are in sorted order.\r\n */\r\n public extractArrays(): { keys: K[], values: V[] } {\r\n const result = { keys: this._keys, values: this._values };\r\n this.clear();\r\n return result;\r\n }\r\n\r\n /** Apply a function to each (key, value) pair in the dictionary, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (key: K, value: V) => void): void {\r\n for (let i = 0; i < this.size; i++)\r\n func(this._keys[i], this._values[i]);\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified key should be inserted to maintain sorted order.\r\n * @param key The key 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 key already exists at that index.\r\n */\r\n protected lowerBound(key: K): { index: number, equal: boolean } { return lowerBound(key, this._keys, this._compareKeys); }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAkCH,sCAEC;AAMD,oCAEC;AA0BD,0BAQC;AAaD,oCAaC;AASD,sBAkBC;AAjID,qDAAqD;AACpD,MAAc,CAAC,OAAO,KAAK,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACpD,MAAc,CAAC,YAAY,KAAK,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAyB/D;;;;GAIG;AACH,SAAgB,aAAa,CAAC,GAAY;IACxC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,YAAY,MAAM,CAAC,IAAI,CAAC,CAAE,GAAmB,CAAC,OAAO,IAAI,CAAC,OAAQ,GAAmB,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;AACpI,CAAC;AAED;;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CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,GAAG;YACZ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY;YACxC,UAAU,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AAnCD,wCAmCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n(Symbol as any).dispose ??= Symbol(\"Symbol.dispose\");\n(Symbol as any).asyncDispose ??= Symbol(\"Symbol.asyncDispose\");\n\n/** Interface adopted by a type which has deterministic cleanup logic.\n * For example:\n * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.\n * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.\n *\n * A similar concept exists in languages like C++ (implemented as \"destructors\") and C# (\"IDisposable\").\n * However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately.\n * Failure to do so may result in memory leaks or leaking of other resources.\n *\n * IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.\n *\n * Implementations of IDisposable tend to be more \"low-level\" types. The disposal of such types is often handled on your behalf.\n * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\n * @public\n */\nexport interface IDisposable {\n /** Disposes of any resources owned by this object.\n * @note The object is generally considered unusable after it has been disposed of.\n */\n dispose(): void;\n}\n\n/**\n * A type guard that checks whether the given argument implements `IDisposable` interface\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use isDisposable instead.\n * @public\n */\nexport function isIDisposable(obj: unknown): obj is IDisposable {\n return !!obj && (obj instanceof Object) && !!(obj as IDisposable).dispose && (typeof (obj as IDisposable).dispose === \"function\");\n}\n\n/**\n * A type guard that checks whether the given argument implements `Disposable` interface\n * @public\n */\nexport function isDisposable(obj: unknown): obj is Disposable {\n return !!obj && (obj instanceof Object) && !!(obj as Disposable)[Symbol.dispose] && (typeof (obj as Disposable)[Symbol.dispose] === \"function\");\n}\n\n/** Convenience function for disposing of a disposable object that may be undefined.\n * This is primarily used to simplify implementations of [[IDisposable.dispose]].\n * As a simple example:\n * ```ts\n * class Disposable implements IDisposable {\n * public member1?: DisposableType1;\n * public member2?: DisposableType2;\n *\n * public dispose() {\n * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.\n * this.member2 = dispose(this.member2); // Likewise for member2.\n * }\n * }\n * ```\n * @param disposable The object to be disposed of.\n * @returns undefined\n * @public\n */\nexport function dispose(disposable?: Disposable): undefined;\n/**\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\n * @public\n */\nexport function dispose(disposable?: IDisposable): undefined; // eslint-disable-line @typescript-eslint/unified-signatures\nexport function dispose(disposable?: Disposable | IDisposable): undefined {\n if (undefined !== disposable) {\n if (Symbol.dispose in disposable)\n disposable[Symbol.dispose]();\n else\n disposable.dispose();\n }\n return undefined;\n}\n\n/** Disposes of and empties a list of disposable objects.\n * @param list The list of disposable objects.\n * @returns undefined\n * @public\n */\nexport function disposeArray(list?: Disposable[]): undefined;\n/**\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\n * @public\n */\nexport function disposeArray(list?: IDisposable[]): undefined; // eslint-disable-line @typescript-eslint/unified-signatures\nexport function disposeArray(list?: Disposable[] | IDisposable[]): undefined {\n if (undefined === list)\n return undefined;\n\n for (const entry of list) {\n if (Symbol.dispose in entry)\n entry[Symbol.dispose]();\n else\n entry.dispose();\n }\n\n list.length = 0;\n return undefined;\n}\n\n/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'\n * is called on the resource no matter if the func returns or throws. If func returns, the return value\n * of this function is equal to return value of func. If func throws, this function also throws (after\n * disposing the resource).\n * @public\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `using` declarations instead.\n */\nexport function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult {\n if (!Array.isArray(resources))\n return using([resources], func);\n\n const doDispose = () => resources.forEach((disposable) => disposable.dispose());\n let shouldDisposeImmediately = true;\n\n try {\n const result = func(...resources);\n if (result instanceof Promise) {\n shouldDisposeImmediately = false;\n result.then(doDispose, doDispose);\n }\n return result;\n } finally {\n if (shouldDisposeImmediately)\n doDispose();\n }\n}\n\n/** A definition of function which may be called to dispose an object\n * @public\n */\nexport type DisposeFunc = () => void;\n\nclass FuncDisposable implements IDisposable {\n private _disposeFunc: () => void;\n constructor(disposeFunc: () => void) { this._disposeFunc = disposeFunc; }\n public dispose() { this._disposeFunc(); }\n}\n\n/** A disposable container of disposable objects.\n * @public\n */\nexport class DisposableList implements IDisposable {\n private _disposables: IDisposable[];\n\n /** Creates a disposable list. */\n constructor(disposables: Array<IDisposable | DisposeFunc> = []) {\n this._disposables = [];\n disposables.forEach((disposable) => {\n this.add(disposable);\n });\n }\n\n private isDisposable(x: IDisposable | DisposeFunc): x is IDisposable {\n return (x as IDisposable).dispose !== undefined;\n }\n\n /** Register an object for disposal. */\n public add(disposable: IDisposable | DisposeFunc) {\n if (this.isDisposable(disposable))\n this._disposables.push(disposable);\n else\n this._disposables.push(new FuncDisposable(disposable));\n }\n\n /** Unregister disposable object. */\n public remove(disposable: IDisposable): void {\n const idx = this._disposables.indexOf(disposable);\n if (-1 !== idx)\n this._disposables.splice(idx, 1);\n }\n\n /** Disposes all registered objects. */\n public dispose(): void {\n for (const disposable of this._disposables)\n disposable.dispose();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"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jC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,CAA4B;QAC/C,OAAQ,CAAiB,CAAC,OAAO,KAAK,SAAS,CAAC;IAClD,CAAC;IAED,uCAAuC;IAChC,GAAG,CAAC,UAAqC;QAC9C,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;;YAEnC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,oCAAoC;IAC7B,MAAM,CAAC,UAAuB;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,GAAG;YACZ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY;YACxC,UAAU,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AAnCD,wCAmCC","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 Utils\r\n */\r\n\r\n/* eslint-disable @typescript-eslint/no-deprecated */\r\n(Symbol as any).dispose ??= Symbol(\"Symbol.dispose\");\r\n(Symbol as any).asyncDispose ??= Symbol(\"Symbol.asyncDispose\");\r\n\r\n/** Interface adopted by a type which has deterministic cleanup logic.\r\n * For example:\r\n * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.\r\n * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.\r\n *\r\n * A similar concept exists in languages like C++ (implemented as \"destructors\") and C# (\"IDisposable\").\r\n * However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately.\r\n * Failure to do so may result in memory leaks or leaking of other resources.\r\n *\r\n * IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.\r\n *\r\n * Implementations of IDisposable tend to be more \"low-level\" types. The disposal of such types is often handled on your behalf.\r\n * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\r\n * @public\r\n */\r\nexport interface IDisposable {\r\n /** Disposes of any resources owned by this object.\r\n * @note The object is generally considered unusable after it has been disposed of.\r\n */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * A type guard that checks whether the given argument implements `IDisposable` interface\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use isDisposable instead.\r\n * @public\r\n */\r\nexport function isIDisposable(obj: unknown): obj is IDisposable {\r\n return !!obj && (obj instanceof Object) && !!(obj as IDisposable).dispose && (typeof (obj as IDisposable).dispose === \"function\");\r\n}\r\n\r\n/**\r\n * A type guard that checks whether the given argument implements `Disposable` interface\r\n * @public\r\n */\r\nexport function isDisposable(obj: unknown): obj is Disposable {\r\n return !!obj && (obj instanceof Object) && !!(obj as Disposable)[Symbol.dispose] && (typeof (obj as Disposable)[Symbol.dispose] === \"function\");\r\n}\r\n\r\n/** Convenience function for disposing of a disposable object that may be undefined.\r\n * This is primarily used to simplify implementations of [[IDisposable.dispose]].\r\n * As a simple example:\r\n * ```ts\r\n * class Disposable implements IDisposable {\r\n * public member1?: DisposableType1;\r\n * public member2?: DisposableType2;\r\n *\r\n * public dispose() {\r\n * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.\r\n * this.member2 = dispose(this.member2); // Likewise for member2.\r\n * }\r\n * }\r\n * ```\r\n * @param disposable The object to be disposed of.\r\n * @returns undefined\r\n * @public\r\n */\r\nexport function dispose(disposable?: Disposable): undefined;\r\n/**\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\r\n * @public\r\n */\r\nexport function dispose(disposable?: IDisposable): undefined; // eslint-disable-line @typescript-eslint/unified-signatures\r\nexport function dispose(disposable?: Disposable | IDisposable): undefined {\r\n if (undefined !== disposable) {\r\n if (Symbol.dispose in disposable)\r\n disposable[Symbol.dispose]();\r\n else\r\n disposable.dispose();\r\n }\r\n return undefined;\r\n}\r\n\r\n/** Disposes of and empties a list of disposable objects.\r\n * @param list The list of disposable objects.\r\n * @returns undefined\r\n * @public\r\n */\r\nexport function disposeArray(list?: Disposable[]): undefined;\r\n/**\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use builtin Disposable type instead.\r\n * @public\r\n */\r\nexport function disposeArray(list?: IDisposable[]): undefined; // eslint-disable-line @typescript-eslint/unified-signatures\r\nexport function disposeArray(list?: Disposable[] | IDisposable[]): undefined {\r\n if (undefined === list)\r\n return undefined;\r\n\r\n for (const entry of list) {\r\n if (Symbol.dispose in entry)\r\n entry[Symbol.dispose]();\r\n else\r\n entry.dispose();\r\n }\r\n\r\n list.length = 0;\r\n return undefined;\r\n}\r\n\r\n/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'\r\n * is called on the resource no matter if the func returns or throws. If func returns, the return value\r\n * of this function is equal to return value of func. If func throws, this function also throws (after\r\n * disposing the resource).\r\n * @public\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `using` declarations instead.\r\n */\r\nexport function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult {\r\n if (!Array.isArray(resources))\r\n return using([resources], func);\r\n\r\n const doDispose = () => resources.forEach((disposable) => disposable.dispose());\r\n let shouldDisposeImmediately = true;\r\n\r\n try {\r\n const result = func(...resources);\r\n if (result instanceof Promise) {\r\n shouldDisposeImmediately = false;\r\n result.then(doDispose, doDispose);\r\n }\r\n return result;\r\n } finally {\r\n if (shouldDisposeImmediately)\r\n doDispose();\r\n }\r\n}\r\n\r\n/** A definition of function which may be called to dispose an object\r\n * @public\r\n */\r\nexport type DisposeFunc = () => void;\r\n\r\nclass FuncDisposable implements IDisposable {\r\n private _disposeFunc: () => void;\r\n constructor(disposeFunc: () => void) { this._disposeFunc = disposeFunc; }\r\n public dispose() { this._disposeFunc(); }\r\n}\r\n\r\n/** A disposable container of disposable objects.\r\n * @public\r\n */\r\nexport class DisposableList implements IDisposable {\r\n private _disposables: IDisposable[];\r\n\r\n /** Creates a disposable list. */\r\n constructor(disposables: Array<IDisposable | DisposeFunc> = []) {\r\n this._disposables = [];\r\n disposables.forEach((disposable) => {\r\n this.add(disposable);\r\n });\r\n }\r\n\r\n private isDisposable(x: IDisposable | DisposeFunc): x is IDisposable {\r\n return (x as IDisposable).dispose !== undefined;\r\n }\r\n\r\n /** Register an object for disposal. */\r\n public add(disposable: IDisposable | DisposeFunc) {\r\n if (this.isDisposable(disposable))\r\n this._disposables.push(disposable);\r\n else\r\n this._disposables.push(new FuncDisposable(disposable));\r\n }\r\n\r\n /** Unregister disposable object. */\r\n public remove(disposable: IDisposable): void {\r\n const idx = this._disposables.indexOf(disposable);\r\n if (-1 !== idx)\r\n this._disposables.splice(idx, 1);\r\n }\r\n\r\n /** Disposes all registered objects. */\r\n public dispose(): void {\r\n for (const disposable of this._disposables)\r\n disposable.dispose();\r\n }\r\n}\r\n"]}
|
package/lib/cjs/Id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Id.js","sourceRoot":"","sources":["../../src/Id.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AA4BH,SAAS,KAAK,CAAC,GAAW;IACxB,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC5B,OAAO,M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B;QACzC,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAE9C,gDAAgD;QAChD,IAAI,MAAM,CAAC,UAAU,CAAC;YACpB,OAAO,UAAU,CAAC;QAEpB,gHAAgH;QAChH,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,sEAAsE,CAAC;QAC7F,IAAI,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,OAAO,WAAW,CAAC,OAAO,CAAC,aAAa,EACtC,CAAC,MAAc,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAE,CAC7E,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC;QAED,8DAA8D;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;IAlBe,cAAS,YAkBxB,CAAA;AACH,CAAC,EAvDgB,IAAI,oBAAJ,IAAI,QAuDpB","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\n/** A string containing a well-formed string representation of an [Id64]($core-bentley).\n * See [Working with Ids]($docs/learning/common/Id64.md).\n * @public\n */\nexport type Id64String = string;\n\n/** A string containing a well-formed string representation of a [Guid]($core-bentley).\n * @public\n */\nexport type GuidString = string;\n\n/** A set of [[Id64String]]s.\n * @public\n */\nexport type Id64Set = Set<Id64String>;\n\n/** An array of [[Id64String]]s.\n * @public\n */\nexport type Id64Array = Id64String[];\n\n/** Used as an argument to a function that can accept one or more [[Id64String]]s.\n * @public\n */\nexport type Id64Arg = Id64String | Id64Set | Id64Array;\n\nfunction toHex(str: string): number {\n const v = parseInt(str, 16);\n return Number.isNaN(v) ? 0 : v;\n}\n\nfunction isLowerCaseNonZeroHexDigit(str: string, index: number) {\n return isLowerCaseHexDigit(str, index, false);\n}\n\nfunction isLowerCaseHexDigit(str: string, index: number, allowZero: boolean = true): boolean {\n const charCode = str.charCodeAt(index);\n const minDecimalDigit = allowZero ? 0x30 : 0x31; // '0' or '1'...\n return (charCode >= minDecimalDigit && charCode <= 0x39) || (charCode >= 0x61 && charCode <= 0x66); // '0'-'9, 'a' -'f'\n}\n\nfunction isValidHexString(id: string, startIndex: number, len: number) {\n if (len === 0)\n return false;\n\n // No leading zeroes...\n if (!isLowerCaseNonZeroHexDigit(id, startIndex))\n return false;\n\n // ...followed by len-1 lowercase hexadecimal digits.\n for (let i = 1; i < len; i++)\n if (!isLowerCaseHexDigit(id, startIndex + i))\n return false;\n\n return true;\n}\n\n/**\n * The Id64 namespace provides facilities for working with 64-bit identifiers. These Ids are stored as 64-bit integers inside an [[IModelDb]], but must be represented\n * as strings in JavaScript because JavaScript does not intrinsically support 64-bit integers.\n *\n * The [[Id64String]] type alias is used to indicate function arguments, return types, and variables which are known to contain a well-formed representation of a 64-bit Id.\n *\n * See [Working with Ids]($docs/learning/common/Id64.md) for a detailed description and code examples.\n * @public\n */\nexport namespace Id64 {\n /** Extract the \"local\" Id portion of an Id64String, contained in the lower 40 bits of the 64-bit value. */\n export function getLocalId(id: Id64String): number {\n if (isInvalid(id))\n return 0;\n\n const len = id.length;\n const start = (len > 12) ? (len - 10) : 2;\n return toHex(id.slice(start));\n }\n\n /** Extract the briefcase Id portion of an Id64String, contained in the upper 24 bits of the 64-bit value. */\n export function getBriefcaseId(id: Id64String): number {\n if (isInvalid(id))\n return 0;\n\n const len = id.length;\n return (len <= 12) ? 0 : toHex(id.slice(2, len - 10));\n }\n\n /** Create an Id64String from its JSON representation.\n * @param prop The JSON representation of an Id.\n * @returns A well-formed Id string.\n * @note if the input is undefined, the result is \"0\", indicating an invalid Id.\n * @note if the input is not undefined, the result is the same as that of [[Id64.fromString]].\n */\n export function fromJSON(prop?: string): Id64String {\n return typeof prop === \"string\" ? Id64.fromString(prop) : Id64.invalid;\n }\n\n /** Given a string value, attempt to normalize it into a well-formed Id string.\n * If the input is already a well-formed Id string, it is returned unmodified.\n * Otherwise, the input is trimmed of leading and trailing whitespace, converted to lowercase, and an attempt is made to parse it as a 64-bit hexadecimal integer.\n * If parsing succeeds the normalized result is returned; otherwise the result is \"0\", indicating an invalid Id.\n *\n * For a description of \"well-formed\", see [Working with Ids]($docs/learning/common/Id64.md).\n */\n export function fromString(val: string): Id64String {\n // NB: in case this is called from JavaScript, we must check the run-time type...\n if (typeof val !== \"string\")\n return invalid;\n\n // Skip the common case in which the input is already a well-formed Id string\n if (Id64.isId64(val))\n return val;\n\n // Attempt to normalize the input into a well-formed Id string\n val = val.toLowerCase().trim();\n const len = val.length;\n if (len < 2 || val[0] !== \"0\" || val[1] !== \"x\")\n return invalid;\n\n let low = 0;\n let high = 0;\n let start = 2;\n if (len > 12) {\n start = (len - 10);\n high = toHex(val.slice(2, start));\n }\n\n low = toHex(val.slice(start));\n return fromLocalAndBriefcaseIds(low, high);\n }\n\n // Used when constructing local ID portion of Id64String. Performance optimization.\n const _localIdPrefixByLocalIdLength = [\n \"0000000000\",\n \"000000000\",\n \"00000000\",\n \"0000000\",\n \"000000\",\n \"00000\",\n \"0000\",\n \"000\",\n \"00\",\n \"0\",\n \"\",\n ];\n\n /** Produce an Id string from a local and briefcase Id.\n * @param localId The non-zero local Id as an unsigned 40-bit integer.\n * @param briefcaseId The briefcase Id as an unsigned 24-bit integer.\n * @returns an Id64String containing the hexadecimal string representation of the unsigned 64-bit integer which would result from the\n * operation `localId | (briefcaseId << 40)`, or an invalid Id \"0\" if the inputs are invalid.\n */\n export function fromLocalAndBriefcaseIds(localId: number, briefcaseId: number): Id64String {\n // NB: Yes, we must check the run-time type...\n if (typeof localId !== \"number\" || typeof briefcaseId !== \"number\")\n return invalid;\n\n localId = Math.floor(localId);\n if (0 === localId)\n return invalid;\n\n briefcaseId = Math.floor(briefcaseId);\n const lowStr = localId.toString(16);\n return `0x${(briefcaseId === 0) ? lowStr : (briefcaseId.toString(16) + (_localIdPrefixByLocalIdLength[lowStr.length] + lowStr))}`;\n }\n\n // Used as a buffer when converting a pair of 32-bit integers to an Id64String. Significant performance optimization.\n const scratchCharCodes = [\n 0x30, // \"0\"\n 0x78, // \"x\"\n 0x30, // \"0\"\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n 0x30,\n ];\n\n // Convert 4-bit unsigned integer to char code representing lower-case hexadecimal digit.\n function uint4ToCharCode(uint4: number): number {\n return uint4 + (uint4 < 10 ? 0x30 : 0x57);\n }\n\n // Convert char code representing lower-case hexadecimal digit to 4-bit unsigned integer.\n function charCodeToUint4(char: number): number {\n return char - (char >= 0x57 ? 0x57 : 0x30);\n }\n\n // Convert a substring to a uint32. This is twice as fast as using Number.parseInt().\n function substringToUint32(id: Id64String, start: number, end: number): number {\n let uint32 = 0;\n for (let i = start; i < end; i++) {\n const uint4 = charCodeToUint4(id.charCodeAt(i));\n const shift = (end - i - 1) << 2;\n const mask = uint4 << shift;\n uint32 = (uint32 | mask) >>> 0; // >>> 0 to force unsigned because javascript\n }\n\n return uint32;\n }\n\n /** Create an Id64String from a pair of unsigned 32-bit integers.\n * @param lowBytes The lower 4 bytes of the Id\n * @param highBytes The upper 4 bytes of the Id\n * @returns an Id64String containing the hexadecimal string representation of the unsigned 64-bit integer which would result from the\n * operation `lowBytes | (highBytes << 32)`.\n * @see [[Id64.fromUint32PairObject]] if you have a [[Id64.Uint32Pair]] object.\n */\n export function fromUint32Pair(lowBytes: number, highBytes: number): Id64String {\n const localIdLow = lowBytes >>> 0;\n const localIdHigh = (highBytes & 0x000000ff) * (0xffffffff + 1); // aka (highBytes & 0xff) << 32\n const localId = localIdLow + localIdHigh; // aka localIdLow | localIdHigh\n if (0 === localId)\n return invalid;\n\n // Need to omit or preserve leading zeroes...\n const buffer = scratchCharCodes;\n let index = 2;\n for (let i = 7; i >= 0; i--) {\n const shift = i << 2;\n const mask = 0xf << shift;\n const uint4 = (highBytes & mask) >>> shift;\n if (index > 2 || 0 !== uint4)\n buffer[index++] = uint4ToCharCode(uint4);\n }\n\n for (let i = 7; i >= 0; i--) {\n const shift = i << 2;\n const mask = 0xf << shift;\n const uint4 = (lowBytes & mask) >>> shift;\n if (index > 2 || 0 !== uint4)\n buffer[index++] = uint4ToCharCode(uint4);\n }\n\n if (buffer.length !== index)\n buffer.length = index;\n\n return String.fromCharCode(...scratchCharCodes);\n }\n\n /** Create an Id64String from a [[Id64.Uint32Pair]].\n * @see [[Id64.fromUint32Pair]].\n */\n export function fromUint32PairObject(pair: Uint32Pair): Id64String {\n return fromUint32Pair(pair.lower, pair.upper);\n }\n\n /** Returns true if the inputs represent two halves of a valid 64-bit Id.\n * @see [[Id64.Uint32Pair]].\n */\n export function isValidUint32Pair(lowBytes: number, highBytes: number): boolean {\n // Detect local ID of zero\n return 0 !== lowBytes || 0 !== (highBytes & 0x000000ff);\n }\n\n /** Represents an [[Id64]] as a pair of unsigned 32-bit integers. Because Javascript lacks efficient support for 64-bit integers,\n * this representation can be useful in performance-sensitive code like the render loop.\n * @see [[Id64.getUint32Pair]] to convert an [[Id64String]] to a Uint32Pair.\n * @see [[Id64.fromUint32Pair]] to convert a Uint32Pair to an [[Id64String]].\n * @see [[Id64.Uint32Set]] and [[Id64.Uint32Map]] for collections based on Uint32Pairs.\n */\n export interface Uint32Pair {\n /** The lower 4 bytes of the 64-bit integer. */\n lower: number;\n /** The upper 4 bytes of the 64-bit integer. */\n upper: number;\n }\n\n /** Convert an Id64String to a 64-bit unsigned integer represented as a pair of unsigned 32-bit integers.\n * @param id The well-formed string representation of a 64-bit Id.\n * @param out Used as the return value if supplied; otherwise a new object is returned.\n * @returns An object containing the parsed lower and upper 32-bit integers comprising the 64-bit Id.\n */\n export function getUint32Pair(id: Id64String, out?: Uint32Pair): Uint32Pair {\n if (!out)\n out = { lower: 0, upper: 0 };\n\n out.lower = getLowerUint32(id);\n out.upper = getUpperUint32(id);\n return out;\n }\n\n /** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. */\n export function getLowerUint32(id: Id64String): number {\n if (isInvalid(id))\n return 0;\n\n const end = id.length;\n const start = end > 10 ? end - 8 : 2;\n return substringToUint32(id, start, end);\n }\n\n /** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. */\n export function getUpperUint32(id: Id64String): number {\n const len = id.length;\n if (len <= 10 || isInvalid(id))\n return 0;\n\n return substringToUint32(id, 2, len - 8);\n }\n\n /** Convert an [[Id64Arg]] into an [[Id64Set]].\n *\n * This method can be used by functions that accept an Id64Arg to conveniently process the value(s). For example:\n * ```ts\n * public addCategories(arg: Id64Arg) { Id64.toIdSet(arg).forEach((id) => this.categories.add(id)); }\n * ```\n *\n * Alternatively, to avoid allocating a new Id64Set, use [[Id64.iterable]].\n *\n * @param arg The Ids to convert to an Id64Set.\n * @param makeCopy If true, and the input is already an Id64Set, returns a deep copy of the input.\n * @returns An Id64Set containing the set of [[Id64String]]s represented by the Id64Arg.\n */\n export function toIdSet(arg: Id64Arg, makeCopy: boolean = false): Id64Set {\n if (arg instanceof Set)\n return makeCopy ? new Set<string>(arg) : arg;\n\n const ids = new Set<Id64String>();\n if (typeof arg === \"string\")\n ids.add(arg);\n else if (Array.isArray(arg)) {\n arg.forEach((id: Id64String) => {\n if (typeof id === \"string\")\n ids.add(id);\n });\n }\n\n return ids;\n }\n\n /** Obtain iterator over the specified Ids.\n * @see [[Id64.iterable]].\n */\n export function* iterator(ids: Id64Arg): Iterator<Id64String> {\n if (typeof ids === \"string\") {\n yield ids;\n } else {\n for (const id of ids)\n yield id;\n }\n }\n\n /** Obtain an iterable over the specified Ids. Example usage:\n * ```ts\n * const ids = [\"0x123\", \"0xfed\"];\n * for (const id of Id64.iterable(ids))\n * console.log(id);\n * ```\n */\n export function iterable(ids: Id64Arg): Iterable<Id64String> {\n return {\n [Symbol.iterator]: () => iterator(ids),\n };\n }\n\n /** Return the first [[Id64String]] of an [[Id64Arg]]. */\n export function getFirst(arg: Id64Arg): Id64String {\n return typeof arg === \"string\" ? arg : (Array.isArray(arg) ? arg[0] : arg.values().next().value) ?? Id64.invalid;\n }\n\n /** Return the number of [[Id64String]]s represented by an [[Id64Arg]]. */\n export function sizeOf(arg: Id64Arg): number {\n return typeof arg === \"string\" ? 1 : (Array.isArray(arg) ? arg.length : arg.size);\n }\n\n /** Returns true if the [[Id64Arg]] contains the specified Id. */\n export function has(arg: Id64Arg, id: Id64String): boolean {\n if (typeof arg === \"string\")\n return arg === id;\n if (Array.isArray(arg))\n return -1 !== arg.indexOf(id);\n\n return arg.has(id);\n }\n\n /** The string representation of an invalid Id. */\n export const invalid = \"0\";\n\n /** Determine if the supplied id string represents a transient Id.\n * @param id A well-formed Id string.\n * @returns true if the Id represents a transient Id.\n * @note This method assumes the input is a well-formed Id string.\n * @see [[Id64.isTransientId64]]\n * @see [[TransientIdSequence]]\n */\n export function isTransient(id: Id64String): boolean {\n // A transient Id is of the format \"0xffffffxxxxxxxxxx\" where the leading 6 digits indicate an invalid briefcase Id.\n return 18 === id.length && id.startsWith(\"0xffffff\");\n }\n\n /** Determine if the input is a well-formed [[Id64String]] and represents a transient Id.\n * @see [[Id64.isTransient]]\n * @see [[Id64.isId64]]\n * @see [[TransientIdSequence]]\n */\n export function isTransientId64(id: string): boolean {\n return isValidId64(id) && isTransient(id);\n }\n\n /** Determine if the input is a well-formed [[Id64String]].\n *\n * For a description of \"well-formed\", see [Working with Ids]($docs/learning/common/Id64.md).\n * @see [[Id64.isValidId64]]\n */\n export function isId64(id: string): boolean {\n const len = id.length;\n if (0 === len || 18 < len)\n return false;\n\n if (\"0\" !== id[0])\n return false;\n\n // Well-formed invalid Id: \"0\"\n if (1 === len)\n return true;\n\n // Valid Ids begin with \"0x\" followed by at least one lower-case hexadecimal digit.\n if (2 === len || \"x\" !== id[1])\n return false;\n\n // If briefcase Id is present, it occupies at least one digit, followed by 10 digits for local Id\n let localIdStart = 2;\n if (len > 12) {\n localIdStart = len - 10;\n\n // Verify briefcase Id\n if (!isValidHexString(id, 2, localIdStart - 2))\n return false;\n\n // Skip leading zeroes in local Id\n for (let i = localIdStart; i < len; i++) {\n if (0x30 !== id.charCodeAt(i)) // '0'\n break;\n else\n localIdStart++;\n }\n\n if (localIdStart >= len)\n return false;\n }\n\n return isValidHexString(id, localIdStart, len - localIdStart);\n }\n\n /** Returns true if the input is not equal to the representation of an invalid Id.\n * @note This method assumes the input is a well-formed Id string.\n * @see [[Id64.isInvalid]]\n * @see [[Id64.isValidId64]]\n */\n export function isValid(id: Id64String): boolean {\n return Id64.invalid !== id;\n }\n\n /** Returns true if the input is a well-formed [[Id64String]] representing a valid Id.\n * @see [[Id64.isValid]]\n * @see [[Id64.isId64]]\n */\n export function isValidId64(id: string): boolean {\n return Id64.invalid !== id && Id64.isId64(id);\n }\n\n /** Returns true if the input is a well-formed [[Id64String]] representing an invalid Id.\n * @see [[Id64.isValid]]\n */\n export function isInvalid(id: Id64String): boolean {\n return Id64.invalid === id;\n }\n\n /** A specialized replacement for Set<Id64String> optimized for performance-critical code which represents large sets of [[Id64]]s as pairs of\n * 32-bit integers.\n * The internal representation is a Map<number, Set<number>> where the Map key is the upper 4 bytes of the IDs and the Set elements are the lower 4 bytes of the IDs.\n * Because the upper 4 bytes store the 24-bit briefcase ID plus the upper 8 bits of the local ID, there will be a very small distribution of unique Map keys.\n * To further optimize this data type, the following assumptions are made regarding the { lower, upper } inputs, and no validation is performed to confirm them:\n * - The inputs are unsigned 32-bit integers;\n * - The inputs represent a valid Id64String (e.g., local ID is not zero).\n * @see [[Id64.Uint32Map]] for a similarly-optimized replacement for Map<Id64String, T>\n * @public\n */\n export class Uint32Set {\n protected readonly _map = new Map<number, Set<number>>();\n\n /** Construct a new Uint32Set.\n * @param ids If supplied, all of the specified Ids will be added to the new set.\n */\n public constructor(ids?: Id64Arg) {\n if (undefined !== ids)\n this.addIds(ids);\n }\n\n /** Return true if `this` and `other` contain the same set of Ids. */\n public equals(other: Uint32Set): boolean {\n if (this === other) {\n return true;\n }\n\n if (this.size !== other.size) {\n return false;\n }\n\n for (const [key, thisValue] of this._map) {\n const otherValue = other._map.get(key);\n if (!otherValue || thisValue.size !== otherValue.size) {\n return false;\n }\n\n for (const value of thisValue) {\n if (!otherValue.has(value)) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n /** Remove all contents of this set. */\n public clear(): void {\n this._map.clear();\n }\n\n /** Add an Id to the set. */\n public addId(id: Id64String): void {\n this.add(Id64.getLowerUint32(id), Id64.getUpperUint32(id));\n }\n\n /** Add any number of Ids to the set. */\n public addIds(ids: Id64Arg): void {\n for (const id of Id64.iterable(ids))\n this.addId(id);\n }\n\n /** Returns true if the set contains the specified Id. */\n public hasId(id: Id64String): boolean { return this.has(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); }\n\n /** Add an Id to the set. */\n public add(low: number, high: number): void {\n let set = this._map.get(high);\n if (undefined === set) {\n set = new Set<number>();\n this._map.set(high, set);\n }\n\n set.add(low);\n }\n\n /** Remove an Id from the set. */\n public deleteId(id: Id64String): void {\n this.delete(Id64.getLowerUint32(id), Id64.getUpperUint32(id));\n }\n\n /** Remove any number of Ids from the set. */\n public deleteIds(ids: Id64Arg): void {\n for (const id of Id64.iterable(ids))\n this.deleteId(id);\n }\n\n /** Remove an Id from the set. */\n public delete(low: number, high: number): void {\n const set = this._map.get(high);\n if (undefined !== set) {\n set.delete(low);\n if (set.size === 0)\n this._map.delete(high);\n }\n }\n\n /** Returns true if the set contains the specified Id. */\n public has(low: number, high: number): boolean {\n const set = this._map.get(high);\n return undefined !== set && set.has(low);\n }\n\n /** Returns true if the set contains the Id specified by `pair`. */\n public hasPair(pair: Uint32Pair): boolean {\n return this.has(pair.lower, pair.upper);\n }\n\n /** Returns true if the set contains no Ids. */\n public get isEmpty(): boolean { return 0 === this._map.size; }\n\n /** Returns the number of Ids contained in the set. */\n public get size(): number {\n let size = 0;\n for (const entry of this._map)\n size += entry[1].size;\n\n return size;\n }\n\n /** Populates and returns an array of all Ids contained in the set. */\n public toId64Array(): Id64Array {\n const ids: Id64Array = [];\n for (const entry of this._map)\n for (const low of entry[1])\n ids.push(Id64.fromUint32Pair(low, entry[0]));\n\n return ids;\n }\n\n /** Populates and returns a set of all Ids contained in the set. */\n public toId64Set(): Id64Set {\n const ids = new Set<string>();\n for (const entry of this._map)\n for (const low of entry[1])\n ids.add(Id64.fromUint32Pair(low, entry[0]));\n\n return ids;\n }\n\n /** Execute a function against each Id in this set. */\n public forEach(func: (lo: number, hi: number) => void): void {\n for (const entry of this._map)\n for (const lo of entry[1])\n func(lo, entry[0]);\n }\n }\n\n /** A specialized replacement for Map<Id64String, T> optimized for performance-critical code.\n * @see [[Id64.Uint32Set]] for implementation details.\n * @public\n */\n export class Uint32Map<T> {\n protected readonly _map = new Map<number, Map<number, T>>();\n\n /** Remove all entries from the map. */\n public clear(): void { this._map.clear(); }\n /** Find an entry in the map by Id. */\n public getById(id: Id64String): T | undefined { return this.get(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); }\n /** Set an entry in the map by Id. */\n public setById(id: Id64String, value: T): void { this.set(Id64.getLowerUint32(id), Id64.getUpperUint32(id), value); }\n\n /** Set an entry in the map by Id components. */\n public set(low: number, high: number, value: T): void {\n let map = this._map.get(high);\n if (undefined === map) {\n map = new Map<number, T>();\n this._map.set(high, map);\n }\n\n map.set(low, value);\n }\n\n /** Get an entry from the map by Id components. */\n public get(low: number, high: number): T | undefined {\n const map = this._map.get(high);\n return undefined !== map ? map.get(low) : undefined;\n }\n\n /** Returns true if the map contains no entries. */\n public get isEmpty(): boolean { return 0 === this._map.size; }\n /** Returns the number of entries in the map. */\n public get size(): number {\n let size = 0;\n for (const entry of this._map)\n size += entry[1].size;\n\n return size;\n }\n\n /** Execute a function against each entry in this map. */\n public forEach(func: (lo: number, hi: number, value: T) => void): void {\n for (const outerEntry of this._map)\n for (const innerEntry of outerEntry[1])\n func(innerEntry[0], outerEntry[0], innerEntry[1]);\n }\n }\n}\n\n/** JSON representation of a [[TransientIdSequence]], primarily useful for transferring sequences to and from a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\n * It stores two \"local\" 40-bit Ids describing the range of [Id64String]($docs/learning/common/Id64.md)s generated by the sequence.\n * @public\n */\nexport interface TransientIdSequenceProps {\n /** The starting local Id. The sequence begins at `initialLocalId + 1`. */\n initialLocalId: number;\n /** The maximum local Id generated by the sequence thus far. It is never less than [[initialLocalId]]. If it is equal to [[initialLocalId]], then the sequence has\n * not yet generated any Ids.\n * The next local Id generated by the sequence will be `currentLocalId + 1`.\n */\n currentLocalId: number;\n}\n\nfunction validateLocalId(num: number): void {\n if (num < 0 || Math.round(num) !== num) {\n throw new Error(\"Local Id must be a non-negative integer\");\n }\n}\n\n/** A function returned by [[TransientIdSequence.merge]] that remaps the local Id portion of an [Id64String]($docs/learning/common/Id64.md) generated by\n * the source sequence to the corresponding local Id in the target sequence.\n * It returns `sourceLocalId` if the input did not originate from the source sequence.\n* @public\n*/\nexport type RemapTransientLocalId = (sourceLocalId: number) => number;\n\n/**\n * Generates unique [[Id64String]] values in sequence, which are guaranteed not to conflict with Ids associated with persistent elements or models.\n * This is useful for associating stable, non-persistent identifiers with things like [Decorator]($frontend)s.\n * A TransientIdSequence can generate a maximum of (2^40)-2 unique Ids.\n * @public\n */\nexport class TransientIdSequence {\n /** The starting local Id provided to the constructor. The sequence begins at `initialLocalId + 1`. */\n public readonly initialLocalId: number;\n private _localId: number;\n\n /** Constructor.\n * @param initialLocalId The starting local Id. The local Id of the first [[Id64String]] generated by [[getNext]] will be `initialLocalId + 1`.\n */\n public constructor(initialLocalId = 0) {\n validateLocalId(initialLocalId);\n this.initialLocalId = initialLocalId;\n this._localId = initialLocalId;\n }\n\n /** The maximum local Id generated by the sequence thus far. It is never less than [[initialLocalId]]. If it is equal to [[initialLocalId]], then the sequence has\n * not yet generated any Ids.\n * Each call to [[getNext]] increments this by 1 and uses it as the local Id of the generated [[Id64String]].\n */\n public get currentLocalId(): number {\n return this._localId;\n }\n\n /** Generate and return the next transient Id64String in the sequence. */\n public getNext(): Id64String {\n return Id64.fromLocalAndBriefcaseIds(++this._localId, 0xffffff);\n }\n\n /** Preview the transient Id64String that will be returned by the next call to [[getNext]].\n * This is primarily useful for tests.\n */\n public peekNext(): Id64String {\n return Id64.fromLocalAndBriefcaseIds(this._localId + 1, 0xffffff);\n }\n\n /** Convert this sequence to its JSON representation. */\n public toJSON(): TransientIdSequenceProps {\n return {\n initialLocalId: this.initialLocalId,\n currentLocalId: this.currentLocalId,\n };\n }\n\n /** Create a sequence from its JSON representation. */\n public static fromJSON(props: TransientIdSequenceProps): TransientIdSequence {\n validateLocalId(props.currentLocalId);\n const sequence = new TransientIdSequence(props.initialLocalId);\n sequence._localId = props.currentLocalId;\n return sequence;\n }\n\n /** Obtain the JSON representation of a new sequence that diverges from this sequence, with its [[initialLocalId]] set to this sequence's [[currentLocalId]].\n * The two sequences can generate Ids independently. Later, you can [[merge]] the sequences, resolving conflicts where the two sequences generated identical Ids.\n * This is chiefly useful when generating transient Ids on a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\n */\n public fork(): TransientIdSequenceProps {\n return {\n initialLocalId: this.currentLocalId,\n currentLocalId: this.currentLocalId,\n };\n }\n\n /** Integrate the Ids generated by a [[fork]] of this sequence. All of the Ids generated by `source` will be remapped to Ids at the end of this sequence.\n * This is chiefly useful when generating transient Ids on a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\n * @param source The JSON representation of the [[fork]]ed sequence to be merged with this one.\n * @returns a function that permits you to remap the local Ids generated by `source` into the corresponding local Ids assigned by this sequence.\n * @throws Error if `source` is not a fork of this sequence or is malformed (e.g., contains negative and/or non-integer local Ids).\n */\n public merge(source: TransientIdSequenceProps): (sourceLocalId: number) => number {\n const { initialLocalId, currentLocalId } = source;\n\n validateLocalId(initialLocalId);\n validateLocalId(currentLocalId);\n\n if (initialLocalId > this.currentLocalId) {\n throw new Error(\"Transient Id sequences do not intersect\");\n }\n\n if (initialLocalId > currentLocalId) {\n throw new Error(\"Current local Id cannot be less than initial local Id\");\n }\n\n const delta = this.currentLocalId - initialLocalId;\n this._localId += currentLocalId - initialLocalId;\n\n return (sourceLocalId: number) => {\n if (sourceLocalId > initialLocalId && sourceLocalId <= currentLocalId) {\n return sourceLocalId + delta;\n }\n\n return sourceLocalId;\n };\n }\n}\n\n/**\n * The Guid namespace provides facilities for working with GUID strings using the \"8-4-4-4-12\" pattern.\n *\n * The [[GuidString]] type alias is used to indicate function arguments, return types, and variables which are known to\n * be in the GUID format.\n * @public\n */\nexport namespace Guid {\n const uuidPattern = new RegExp(\"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\");\n\n /** Represents the empty Guid 00000000-0000-0000-0000-000000000000 */\n export const empty: GuidString = \"00000000-0000-0000-0000-000000000000\";\n\n /** Determine whether the input string is \"guid-like\". That is, it follows the 8-4-4-4-12 pattern. This does not enforce\n * that the string is actually in valid UUID format.\n */\n export function isGuid(value: string): boolean {\n return uuidPattern.test(value);\n }\n\n /** Determine whether the input string is a valid V4 Guid string */\n export function isV4Guid(value: string): boolean {\n return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(value);\n }\n\n /** Create a new V4 Guid value */\n export function createValue(): GuidString {\n // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n const v = c === \"x\" ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n }\n\n /**\n * Normalize a Guid string if possible. Normalization consists of:\n * - Convert all characters to lower case\n * - Trim any leading or trailing whitespace\n * - Convert to the standard Guid format \"8-4-4-4-12\", repositioning the '-' characters as necessary, presuming there are exactly 32 hexadecimal digits.\n * @param value Input value that represents a Guid\n * @returns Normalized representation of the Guid string. If the normalization fails, return the *original* value unmodified (Note: it is *not* a valid Guid)\n */\n export function normalize(value: GuidString): GuidString {\n const lowerValue = value.toLowerCase().trim();\n\n // Return if it's already formatted to be a Guid\n if (isGuid(lowerValue))\n return lowerValue;\n\n // Remove any existing \"-\" characters and position them properly, if there remains exactly 32 hexadecimal digits\n const noDashValue = lowerValue.replace(/-/g, \"\");\n const noDashPattern = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;\n if (noDashPattern.test(noDashValue)) {\n return noDashValue.replace(noDashPattern,\n (_match: string, p1: string, p2: string, p3: string, p4: string, p5: string) =>\n `${p1}-${p2}-${p3}-${p4}-${p5}`);\n }\n\n // Return unmodified string - (note: it is *not* a valid Guid)\n return value;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Id.js","sourceRoot":"","sources":["../../src/Id.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AA4BH,SAAS,KAAK,CAAC,GAAW;IACxB,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,0BAA0B,CAAC,GAAW,EAAE,KAAa;IAC5D,OAAO,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW,EAAE,KAAa,EAAE,YAAqB,IAAI;IAChF,MAAM,QAAQ,GAAG,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CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,OAAO,WAAW,CAAC,OAAO,CAAC,aAAa,EACtC,CAAC,MAAc,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAE,CAC7E,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC;QAED,8DAA8D;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;IAlBe,cAAS,YAkBxB,CAAA;AACH,CAAC,EAvDgB,IAAI,oBAAJ,IAAI,QAuDpB","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\n/** A string containing a well-formed string representation of an [Id64]($core-bentley).\r\n * See [Working with Ids]($docs/learning/common/Id64.md).\r\n * @public\r\n */\r\nexport type Id64String = string;\r\n\r\n/** A string containing a well-formed string representation of a [Guid]($core-bentley).\r\n * @public\r\n */\r\nexport type GuidString = string;\r\n\r\n/** A set of [[Id64String]]s.\r\n * @public\r\n */\r\nexport type Id64Set = Set<Id64String>;\r\n\r\n/** An array of [[Id64String]]s.\r\n * @public\r\n */\r\nexport type Id64Array = Id64String[];\r\n\r\n/** Used as an argument to a function that can accept one or more [[Id64String]]s.\r\n * @public\r\n */\r\nexport type Id64Arg = Id64String | Id64Set | Id64Array;\r\n\r\nfunction toHex(str: string): number {\r\n const v = parseInt(str, 16);\r\n return Number.isNaN(v) ? 0 : v;\r\n}\r\n\r\nfunction isLowerCaseNonZeroHexDigit(str: string, index: number) {\r\n return isLowerCaseHexDigit(str, index, false);\r\n}\r\n\r\nfunction isLowerCaseHexDigit(str: string, index: number, allowZero: boolean = true): boolean {\r\n const charCode = str.charCodeAt(index);\r\n const minDecimalDigit = allowZero ? 0x30 : 0x31; // '0' or '1'...\r\n return (charCode >= minDecimalDigit && charCode <= 0x39) || (charCode >= 0x61 && charCode <= 0x66); // '0'-'9, 'a' -'f'\r\n}\r\n\r\nfunction isValidHexString(id: string, startIndex: number, len: number) {\r\n if (len === 0)\r\n return false;\r\n\r\n // No leading zeroes...\r\n if (!isLowerCaseNonZeroHexDigit(id, startIndex))\r\n return false;\r\n\r\n // ...followed by len-1 lowercase hexadecimal digits.\r\n for (let i = 1; i < len; i++)\r\n if (!isLowerCaseHexDigit(id, startIndex + i))\r\n return false;\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * The Id64 namespace provides facilities for working with 64-bit identifiers. These Ids are stored as 64-bit integers inside an [[IModelDb]], but must be represented\r\n * as strings in JavaScript because JavaScript does not intrinsically support 64-bit integers.\r\n *\r\n * The [[Id64String]] type alias is used to indicate function arguments, return types, and variables which are known to contain a well-formed representation of a 64-bit Id.\r\n *\r\n * See [Working with Ids]($docs/learning/common/Id64.md) for a detailed description and code examples.\r\n * @public\r\n */\r\nexport namespace Id64 {\r\n /** Extract the \"local\" Id portion of an Id64String, contained in the lower 40 bits of the 64-bit value. */\r\n export function getLocalId(id: Id64String): number {\r\n if (isInvalid(id))\r\n return 0;\r\n\r\n const len = id.length;\r\n const start = (len > 12) ? (len - 10) : 2;\r\n return toHex(id.slice(start));\r\n }\r\n\r\n /** Extract the briefcase Id portion of an Id64String, contained in the upper 24 bits of the 64-bit value. */\r\n export function getBriefcaseId(id: Id64String): number {\r\n if (isInvalid(id))\r\n return 0;\r\n\r\n const len = id.length;\r\n return (len <= 12) ? 0 : toHex(id.slice(2, len - 10));\r\n }\r\n\r\n /** Create an Id64String from its JSON representation.\r\n * @param prop The JSON representation of an Id.\r\n * @returns A well-formed Id string.\r\n * @note if the input is undefined, the result is \"0\", indicating an invalid Id.\r\n * @note if the input is not undefined, the result is the same as that of [[Id64.fromString]].\r\n */\r\n export function fromJSON(prop?: string): Id64String {\r\n return typeof prop === \"string\" ? Id64.fromString(prop) : Id64.invalid;\r\n }\r\n\r\n /** Given a string value, attempt to normalize it into a well-formed Id string.\r\n * If the input is already a well-formed Id string, it is returned unmodified.\r\n * Otherwise, the input is trimmed of leading and trailing whitespace, converted to lowercase, and an attempt is made to parse it as a 64-bit hexadecimal integer.\r\n * If parsing succeeds the normalized result is returned; otherwise the result is \"0\", indicating an invalid Id.\r\n *\r\n * For a description of \"well-formed\", see [Working with Ids]($docs/learning/common/Id64.md).\r\n */\r\n export function fromString(val: string): Id64String {\r\n // NB: in case this is called from JavaScript, we must check the run-time type...\r\n if (typeof val !== \"string\")\r\n return invalid;\r\n\r\n // Skip the common case in which the input is already a well-formed Id string\r\n if (Id64.isId64(val))\r\n return val;\r\n\r\n // Attempt to normalize the input into a well-formed Id string\r\n val = val.toLowerCase().trim();\r\n const len = val.length;\r\n if (len < 2 || val[0] !== \"0\" || val[1] !== \"x\")\r\n return invalid;\r\n\r\n let low = 0;\r\n let high = 0;\r\n let start = 2;\r\n if (len > 12) {\r\n start = (len - 10);\r\n high = toHex(val.slice(2, start));\r\n }\r\n\r\n low = toHex(val.slice(start));\r\n return fromLocalAndBriefcaseIds(low, high);\r\n }\r\n\r\n // Used when constructing local ID portion of Id64String. Performance optimization.\r\n const _localIdPrefixByLocalIdLength = [\r\n \"0000000000\",\r\n \"000000000\",\r\n \"00000000\",\r\n \"0000000\",\r\n \"000000\",\r\n \"00000\",\r\n \"0000\",\r\n \"000\",\r\n \"00\",\r\n \"0\",\r\n \"\",\r\n ];\r\n\r\n /** Produce an Id string from a local and briefcase Id.\r\n * @param localId The non-zero local Id as an unsigned 40-bit integer.\r\n * @param briefcaseId The briefcase Id as an unsigned 24-bit integer.\r\n * @returns an Id64String containing the hexadecimal string representation of the unsigned 64-bit integer which would result from the\r\n * operation `localId | (briefcaseId << 40)`, or an invalid Id \"0\" if the inputs are invalid.\r\n */\r\n export function fromLocalAndBriefcaseIds(localId: number, briefcaseId: number): Id64String {\r\n // NB: Yes, we must check the run-time type...\r\n if (typeof localId !== \"number\" || typeof briefcaseId !== \"number\")\r\n return invalid;\r\n\r\n localId = Math.floor(localId);\r\n if (0 === localId)\r\n return invalid;\r\n\r\n briefcaseId = Math.floor(briefcaseId);\r\n const lowStr = localId.toString(16);\r\n return `0x${(briefcaseId === 0) ? lowStr : (briefcaseId.toString(16) + (_localIdPrefixByLocalIdLength[lowStr.length] + lowStr))}`;\r\n }\r\n\r\n // Used as a buffer when converting a pair of 32-bit integers to an Id64String. Significant performance optimization.\r\n const scratchCharCodes = [\r\n 0x30, // \"0\"\r\n 0x78, // \"x\"\r\n 0x30, // \"0\"\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n 0x30,\r\n ];\r\n\r\n // Convert 4-bit unsigned integer to char code representing lower-case hexadecimal digit.\r\n function uint4ToCharCode(uint4: number): number {\r\n return uint4 + (uint4 < 10 ? 0x30 : 0x57);\r\n }\r\n\r\n // Convert char code representing lower-case hexadecimal digit to 4-bit unsigned integer.\r\n function charCodeToUint4(char: number): number {\r\n return char - (char >= 0x57 ? 0x57 : 0x30);\r\n }\r\n\r\n // Convert a substring to a uint32. This is twice as fast as using Number.parseInt().\r\n function substringToUint32(id: Id64String, start: number, end: number): number {\r\n let uint32 = 0;\r\n for (let i = start; i < end; i++) {\r\n const uint4 = charCodeToUint4(id.charCodeAt(i));\r\n const shift = (end - i - 1) << 2;\r\n const mask = uint4 << shift;\r\n uint32 = (uint32 | mask) >>> 0; // >>> 0 to force unsigned because javascript\r\n }\r\n\r\n return uint32;\r\n }\r\n\r\n /** Create an Id64String from a pair of unsigned 32-bit integers.\r\n * @param lowBytes The lower 4 bytes of the Id\r\n * @param highBytes The upper 4 bytes of the Id\r\n * @returns an Id64String containing the hexadecimal string representation of the unsigned 64-bit integer which would result from the\r\n * operation `lowBytes | (highBytes << 32)`.\r\n * @see [[Id64.fromUint32PairObject]] if you have a [[Id64.Uint32Pair]] object.\r\n */\r\n export function fromUint32Pair(lowBytes: number, highBytes: number): Id64String {\r\n const localIdLow = lowBytes >>> 0;\r\n const localIdHigh = (highBytes & 0x000000ff) * (0xffffffff + 1); // aka (highBytes & 0xff) << 32\r\n const localId = localIdLow + localIdHigh; // aka localIdLow | localIdHigh\r\n if (0 === localId)\r\n return invalid;\r\n\r\n // Need to omit or preserve leading zeroes...\r\n const buffer = scratchCharCodes;\r\n let index = 2;\r\n for (let i = 7; i >= 0; i--) {\r\n const shift = i << 2;\r\n const mask = 0xf << shift;\r\n const uint4 = (highBytes & mask) >>> shift;\r\n if (index > 2 || 0 !== uint4)\r\n buffer[index++] = uint4ToCharCode(uint4);\r\n }\r\n\r\n for (let i = 7; i >= 0; i--) {\r\n const shift = i << 2;\r\n const mask = 0xf << shift;\r\n const uint4 = (lowBytes & mask) >>> shift;\r\n if (index > 2 || 0 !== uint4)\r\n buffer[index++] = uint4ToCharCode(uint4);\r\n }\r\n\r\n if (buffer.length !== index)\r\n buffer.length = index;\r\n\r\n return String.fromCharCode(...scratchCharCodes);\r\n }\r\n\r\n /** Create an Id64String from a [[Id64.Uint32Pair]].\r\n * @see [[Id64.fromUint32Pair]].\r\n */\r\n export function fromUint32PairObject(pair: Uint32Pair): Id64String {\r\n return fromUint32Pair(pair.lower, pair.upper);\r\n }\r\n\r\n /** Returns true if the inputs represent two halves of a valid 64-bit Id.\r\n * @see [[Id64.Uint32Pair]].\r\n */\r\n export function isValidUint32Pair(lowBytes: number, highBytes: number): boolean {\r\n // Detect local ID of zero\r\n return 0 !== lowBytes || 0 !== (highBytes & 0x000000ff);\r\n }\r\n\r\n /** Represents an [[Id64]] as a pair of unsigned 32-bit integers. Because Javascript lacks efficient support for 64-bit integers,\r\n * this representation can be useful in performance-sensitive code like the render loop.\r\n * @see [[Id64.getUint32Pair]] to convert an [[Id64String]] to a Uint32Pair.\r\n * @see [[Id64.fromUint32Pair]] to convert a Uint32Pair to an [[Id64String]].\r\n * @see [[Id64.Uint32Set]] and [[Id64.Uint32Map]] for collections based on Uint32Pairs.\r\n */\r\n export interface Uint32Pair {\r\n /** The lower 4 bytes of the 64-bit integer. */\r\n lower: number;\r\n /** The upper 4 bytes of the 64-bit integer. */\r\n upper: number;\r\n }\r\n\r\n /** Convert an Id64String to a 64-bit unsigned integer represented as a pair of unsigned 32-bit integers.\r\n * @param id The well-formed string representation of a 64-bit Id.\r\n * @param out Used as the return value if supplied; otherwise a new object is returned.\r\n * @returns An object containing the parsed lower and upper 32-bit integers comprising the 64-bit Id.\r\n */\r\n export function getUint32Pair(id: Id64String, out?: Uint32Pair): Uint32Pair {\r\n if (!out)\r\n out = { lower: 0, upper: 0 };\r\n\r\n out.lower = getLowerUint32(id);\r\n out.upper = getUpperUint32(id);\r\n return out;\r\n }\r\n\r\n /** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. */\r\n export function getLowerUint32(id: Id64String): number {\r\n if (isInvalid(id))\r\n return 0;\r\n\r\n const end = id.length;\r\n const start = end > 10 ? end - 8 : 2;\r\n return substringToUint32(id, start, end);\r\n }\r\n\r\n /** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. */\r\n export function getUpperUint32(id: Id64String): number {\r\n const len = id.length;\r\n if (len <= 10 || isInvalid(id))\r\n return 0;\r\n\r\n return substringToUint32(id, 2, len - 8);\r\n }\r\n\r\n /** Convert an [[Id64Arg]] into an [[Id64Set]].\r\n *\r\n * This method can be used by functions that accept an Id64Arg to conveniently process the value(s). For example:\r\n * ```ts\r\n * public addCategories(arg: Id64Arg) { Id64.toIdSet(arg).forEach((id) => this.categories.add(id)); }\r\n * ```\r\n *\r\n * Alternatively, to avoid allocating a new Id64Set, use [[Id64.iterable]].\r\n *\r\n * @param arg The Ids to convert to an Id64Set.\r\n * @param makeCopy If true, and the input is already an Id64Set, returns a deep copy of the input.\r\n * @returns An Id64Set containing the set of [[Id64String]]s represented by the Id64Arg.\r\n */\r\n export function toIdSet(arg: Id64Arg, makeCopy: boolean = false): Id64Set {\r\n if (arg instanceof Set)\r\n return makeCopy ? new Set<string>(arg) : arg;\r\n\r\n const ids = new Set<Id64String>();\r\n if (typeof arg === \"string\")\r\n ids.add(arg);\r\n else if (Array.isArray(arg)) {\r\n arg.forEach((id: Id64String) => {\r\n if (typeof id === \"string\")\r\n ids.add(id);\r\n });\r\n }\r\n\r\n return ids;\r\n }\r\n\r\n /** Obtain iterator over the specified Ids.\r\n * @see [[Id64.iterable]].\r\n */\r\n export function* iterator(ids: Id64Arg): Iterator<Id64String> {\r\n if (typeof ids === \"string\") {\r\n yield ids;\r\n } else {\r\n for (const id of ids)\r\n yield id;\r\n }\r\n }\r\n\r\n /** Obtain an iterable over the specified Ids. Example usage:\r\n * ```ts\r\n * const ids = [\"0x123\", \"0xfed\"];\r\n * for (const id of Id64.iterable(ids))\r\n * console.log(id);\r\n * ```\r\n */\r\n export function iterable(ids: Id64Arg): Iterable<Id64String> {\r\n return {\r\n [Symbol.iterator]: () => iterator(ids),\r\n };\r\n }\r\n\r\n /** Return the first [[Id64String]] of an [[Id64Arg]]. */\r\n export function getFirst(arg: Id64Arg): Id64String {\r\n return typeof arg === \"string\" ? arg : (Array.isArray(arg) ? arg[0] : arg.values().next().value) ?? Id64.invalid;\r\n }\r\n\r\n /** Return the number of [[Id64String]]s represented by an [[Id64Arg]]. */\r\n export function sizeOf(arg: Id64Arg): number {\r\n return typeof arg === \"string\" ? 1 : (Array.isArray(arg) ? arg.length : arg.size);\r\n }\r\n\r\n /** Returns true if the [[Id64Arg]] contains the specified Id. */\r\n export function has(arg: Id64Arg, id: Id64String): boolean {\r\n if (typeof arg === \"string\")\r\n return arg === id;\r\n if (Array.isArray(arg))\r\n return -1 !== arg.indexOf(id);\r\n\r\n return arg.has(id);\r\n }\r\n\r\n /** The string representation of an invalid Id. */\r\n export const invalid = \"0\";\r\n\r\n /** Determine if the supplied id string represents a transient Id.\r\n * @param id A well-formed Id string.\r\n * @returns true if the Id represents a transient Id.\r\n * @note This method assumes the input is a well-formed Id string.\r\n * @see [[Id64.isTransientId64]]\r\n * @see [[TransientIdSequence]]\r\n */\r\n export function isTransient(id: Id64String): boolean {\r\n // A transient Id is of the format \"0xffffffxxxxxxxxxx\" where the leading 6 digits indicate an invalid briefcase Id.\r\n return 18 === id.length && id.startsWith(\"0xffffff\");\r\n }\r\n\r\n /** Determine if the input is a well-formed [[Id64String]] and represents a transient Id.\r\n * @see [[Id64.isTransient]]\r\n * @see [[Id64.isId64]]\r\n * @see [[TransientIdSequence]]\r\n */\r\n export function isTransientId64(id: string): boolean {\r\n return isValidId64(id) && isTransient(id);\r\n }\r\n\r\n /** Determine if the input is a well-formed [[Id64String]].\r\n *\r\n * For a description of \"well-formed\", see [Working with Ids]($docs/learning/common/Id64.md).\r\n * @see [[Id64.isValidId64]]\r\n */\r\n export function isId64(id: string): boolean {\r\n const len = id.length;\r\n if (0 === len || 18 < len)\r\n return false;\r\n\r\n if (\"0\" !== id[0])\r\n return false;\r\n\r\n // Well-formed invalid Id: \"0\"\r\n if (1 === len)\r\n return true;\r\n\r\n // Valid Ids begin with \"0x\" followed by at least one lower-case hexadecimal digit.\r\n if (2 === len || \"x\" !== id[1])\r\n return false;\r\n\r\n // If briefcase Id is present, it occupies at least one digit, followed by 10 digits for local Id\r\n let localIdStart = 2;\r\n if (len > 12) {\r\n localIdStart = len - 10;\r\n\r\n // Verify briefcase Id\r\n if (!isValidHexString(id, 2, localIdStart - 2))\r\n return false;\r\n\r\n // Skip leading zeroes in local Id\r\n for (let i = localIdStart; i < len; i++) {\r\n if (0x30 !== id.charCodeAt(i)) // '0'\r\n break;\r\n else\r\n localIdStart++;\r\n }\r\n\r\n if (localIdStart >= len)\r\n return false;\r\n }\r\n\r\n return isValidHexString(id, localIdStart, len - localIdStart);\r\n }\r\n\r\n /** Returns true if the input is not equal to the representation of an invalid Id.\r\n * @note This method assumes the input is a well-formed Id string.\r\n * @see [[Id64.isInvalid]]\r\n * @see [[Id64.isValidId64]]\r\n */\r\n export function isValid(id: Id64String): boolean {\r\n return Id64.invalid !== id;\r\n }\r\n\r\n /** Returns true if the input is a well-formed [[Id64String]] representing a valid Id.\r\n * @see [[Id64.isValid]]\r\n * @see [[Id64.isId64]]\r\n */\r\n export function isValidId64(id: string): boolean {\r\n return Id64.invalid !== id && Id64.isId64(id);\r\n }\r\n\r\n /** Returns true if the input is a well-formed [[Id64String]] representing an invalid Id.\r\n * @see [[Id64.isValid]]\r\n */\r\n export function isInvalid(id: Id64String): boolean {\r\n return Id64.invalid === id;\r\n }\r\n\r\n /** A specialized replacement for Set<Id64String> optimized for performance-critical code which represents large sets of [[Id64]]s as pairs of\r\n * 32-bit integers.\r\n * The internal representation is a Map<number, Set<number>> where the Map key is the upper 4 bytes of the IDs and the Set elements are the lower 4 bytes of the IDs.\r\n * Because the upper 4 bytes store the 24-bit briefcase ID plus the upper 8 bits of the local ID, there will be a very small distribution of unique Map keys.\r\n * To further optimize this data type, the following assumptions are made regarding the { lower, upper } inputs, and no validation is performed to confirm them:\r\n * - The inputs are unsigned 32-bit integers;\r\n * - The inputs represent a valid Id64String (e.g., local ID is not zero).\r\n * @see [[Id64.Uint32Map]] for a similarly-optimized replacement for Map<Id64String, T>\r\n * @public\r\n */\r\n export class Uint32Set {\r\n protected readonly _map = new Map<number, Set<number>>();\r\n\r\n /** Construct a new Uint32Set.\r\n * @param ids If supplied, all of the specified Ids will be added to the new set.\r\n */\r\n public constructor(ids?: Id64Arg) {\r\n if (undefined !== ids)\r\n this.addIds(ids);\r\n }\r\n\r\n /** Return true if `this` and `other` contain the same set of Ids. */\r\n public equals(other: Uint32Set): boolean {\r\n if (this === other) {\r\n return true;\r\n }\r\n\r\n if (this.size !== other.size) {\r\n return false;\r\n }\r\n\r\n for (const [key, thisValue] of this._map) {\r\n const otherValue = other._map.get(key);\r\n if (!otherValue || thisValue.size !== otherValue.size) {\r\n return false;\r\n }\r\n\r\n for (const value of thisValue) {\r\n if (!otherValue.has(value)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /** Remove all contents of this set. */\r\n public clear(): void {\r\n this._map.clear();\r\n }\r\n\r\n /** Add an Id to the set. */\r\n public addId(id: Id64String): void {\r\n this.add(Id64.getLowerUint32(id), Id64.getUpperUint32(id));\r\n }\r\n\r\n /** Add any number of Ids to the set. */\r\n public addIds(ids: Id64Arg): void {\r\n for (const id of Id64.iterable(ids))\r\n this.addId(id);\r\n }\r\n\r\n /** Returns true if the set contains the specified Id. */\r\n public hasId(id: Id64String): boolean { return this.has(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); }\r\n\r\n /** Add an Id to the set. */\r\n public add(low: number, high: number): void {\r\n let set = this._map.get(high);\r\n if (undefined === set) {\r\n set = new Set<number>();\r\n this._map.set(high, set);\r\n }\r\n\r\n set.add(low);\r\n }\r\n\r\n /** Remove an Id from the set. */\r\n public deleteId(id: Id64String): void {\r\n this.delete(Id64.getLowerUint32(id), Id64.getUpperUint32(id));\r\n }\r\n\r\n /** Remove any number of Ids from the set. */\r\n public deleteIds(ids: Id64Arg): void {\r\n for (const id of Id64.iterable(ids))\r\n this.deleteId(id);\r\n }\r\n\r\n /** Remove an Id from the set. */\r\n public delete(low: number, high: number): void {\r\n const set = this._map.get(high);\r\n if (undefined !== set) {\r\n set.delete(low);\r\n if (set.size === 0)\r\n this._map.delete(high);\r\n }\r\n }\r\n\r\n /** Returns true if the set contains the specified Id. */\r\n public has(low: number, high: number): boolean {\r\n const set = this._map.get(high);\r\n return undefined !== set && set.has(low);\r\n }\r\n\r\n /** Returns true if the set contains the Id specified by `pair`. */\r\n public hasPair(pair: Uint32Pair): boolean {\r\n return this.has(pair.lower, pair.upper);\r\n }\r\n\r\n /** Returns true if the set contains no Ids. */\r\n public get isEmpty(): boolean { return 0 === this._map.size; }\r\n\r\n /** Returns the number of Ids contained in the set. */\r\n public get size(): number {\r\n let size = 0;\r\n for (const entry of this._map)\r\n size += entry[1].size;\r\n\r\n return size;\r\n }\r\n\r\n /** Populates and returns an array of all Ids contained in the set. */\r\n public toId64Array(): Id64Array {\r\n const ids: Id64Array = [];\r\n for (const entry of this._map)\r\n for (const low of entry[1])\r\n ids.push(Id64.fromUint32Pair(low, entry[0]));\r\n\r\n return ids;\r\n }\r\n\r\n /** Populates and returns a set of all Ids contained in the set. */\r\n public toId64Set(): Id64Set {\r\n const ids = new Set<string>();\r\n for (const entry of this._map)\r\n for (const low of entry[1])\r\n ids.add(Id64.fromUint32Pair(low, entry[0]));\r\n\r\n return ids;\r\n }\r\n\r\n /** Execute a function against each Id in this set. */\r\n public forEach(func: (lo: number, hi: number) => void): void {\r\n for (const entry of this._map)\r\n for (const lo of entry[1])\r\n func(lo, entry[0]);\r\n }\r\n }\r\n\r\n /** A specialized replacement for Map<Id64String, T> optimized for performance-critical code.\r\n * @see [[Id64.Uint32Set]] for implementation details.\r\n * @public\r\n */\r\n export class Uint32Map<T> {\r\n protected readonly _map = new Map<number, Map<number, T>>();\r\n\r\n /** Remove all entries from the map. */\r\n public clear(): void { this._map.clear(); }\r\n /** Find an entry in the map by Id. */\r\n public getById(id: Id64String): T | undefined { return this.get(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); }\r\n /** Set an entry in the map by Id. */\r\n public setById(id: Id64String, value: T): void { this.set(Id64.getLowerUint32(id), Id64.getUpperUint32(id), value); }\r\n\r\n /** Set an entry in the map by Id components. */\r\n public set(low: number, high: number, value: T): void {\r\n let map = this._map.get(high);\r\n if (undefined === map) {\r\n map = new Map<number, T>();\r\n this._map.set(high, map);\r\n }\r\n\r\n map.set(low, value);\r\n }\r\n\r\n /** Get an entry from the map by Id components. */\r\n public get(low: number, high: number): T | undefined {\r\n const map = this._map.get(high);\r\n return undefined !== map ? map.get(low) : undefined;\r\n }\r\n\r\n /** Returns true if the map contains no entries. */\r\n public get isEmpty(): boolean { return 0 === this._map.size; }\r\n /** Returns the number of entries in the map. */\r\n public get size(): number {\r\n let size = 0;\r\n for (const entry of this._map)\r\n size += entry[1].size;\r\n\r\n return size;\r\n }\r\n\r\n /** Execute a function against each entry in this map. */\r\n public forEach(func: (lo: number, hi: number, value: T) => void): void {\r\n for (const outerEntry of this._map)\r\n for (const innerEntry of outerEntry[1])\r\n func(innerEntry[0], outerEntry[0], innerEntry[1]);\r\n }\r\n }\r\n}\r\n\r\n/** JSON representation of a [[TransientIdSequence]], primarily useful for transferring sequences to and from a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\r\n * It stores two \"local\" 40-bit Ids describing the range of [Id64String]($docs/learning/common/Id64.md)s generated by the sequence.\r\n * @public\r\n */\r\nexport interface TransientIdSequenceProps {\r\n /** The starting local Id. The sequence begins at `initialLocalId + 1`. */\r\n initialLocalId: number;\r\n /** The maximum local Id generated by the sequence thus far. It is never less than [[initialLocalId]]. If it is equal to [[initialLocalId]], then the sequence has\r\n * not yet generated any Ids.\r\n * The next local Id generated by the sequence will be `currentLocalId + 1`.\r\n */\r\n currentLocalId: number;\r\n}\r\n\r\nfunction validateLocalId(num: number): void {\r\n if (num < 0 || Math.round(num) !== num) {\r\n throw new Error(\"Local Id must be a non-negative integer\");\r\n }\r\n}\r\n\r\n/** A function returned by [[TransientIdSequence.merge]] that remaps the local Id portion of an [Id64String]($docs/learning/common/Id64.md) generated by\r\n * the source sequence to the corresponding local Id in the target sequence.\r\n * It returns `sourceLocalId` if the input did not originate from the source sequence.\r\n* @public\r\n*/\r\nexport type RemapTransientLocalId = (sourceLocalId: number) => number;\r\n\r\n/**\r\n * Generates unique [[Id64String]] values in sequence, which are guaranteed not to conflict with Ids associated with persistent elements or models.\r\n * This is useful for associating stable, non-persistent identifiers with things like [Decorator]($frontend)s.\r\n * A TransientIdSequence can generate a maximum of (2^40)-2 unique Ids.\r\n * @public\r\n */\r\nexport class TransientIdSequence {\r\n /** The starting local Id provided to the constructor. The sequence begins at `initialLocalId + 1`. */\r\n public readonly initialLocalId: number;\r\n private _localId: number;\r\n\r\n /** Constructor.\r\n * @param initialLocalId The starting local Id. The local Id of the first [[Id64String]] generated by [[getNext]] will be `initialLocalId + 1`.\r\n */\r\n public constructor(initialLocalId = 0) {\r\n validateLocalId(initialLocalId);\r\n this.initialLocalId = initialLocalId;\r\n this._localId = initialLocalId;\r\n }\r\n\r\n /** The maximum local Id generated by the sequence thus far. It is never less than [[initialLocalId]]. If it is equal to [[initialLocalId]], then the sequence has\r\n * not yet generated any Ids.\r\n * Each call to [[getNext]] increments this by 1 and uses it as the local Id of the generated [[Id64String]].\r\n */\r\n public get currentLocalId(): number {\r\n return this._localId;\r\n }\r\n\r\n /** Generate and return the next transient Id64String in the sequence. */\r\n public getNext(): Id64String {\r\n return Id64.fromLocalAndBriefcaseIds(++this._localId, 0xffffff);\r\n }\r\n\r\n /** Preview the transient Id64String that will be returned by the next call to [[getNext]].\r\n * This is primarily useful for tests.\r\n */\r\n public peekNext(): Id64String {\r\n return Id64.fromLocalAndBriefcaseIds(this._localId + 1, 0xffffff);\r\n }\r\n\r\n /** Convert this sequence to its JSON representation. */\r\n public toJSON(): TransientIdSequenceProps {\r\n return {\r\n initialLocalId: this.initialLocalId,\r\n currentLocalId: this.currentLocalId,\r\n };\r\n }\r\n\r\n /** Create a sequence from its JSON representation. */\r\n public static fromJSON(props: TransientIdSequenceProps): TransientIdSequence {\r\n validateLocalId(props.currentLocalId);\r\n const sequence = new TransientIdSequence(props.initialLocalId);\r\n sequence._localId = props.currentLocalId;\r\n return sequence;\r\n }\r\n\r\n /** Obtain the JSON representation of a new sequence that diverges from this sequence, with its [[initialLocalId]] set to this sequence's [[currentLocalId]].\r\n * The two sequences can generate Ids independently. Later, you can [[merge]] the sequences, resolving conflicts where the two sequences generated identical Ids.\r\n * This is chiefly useful when generating transient Ids on a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\r\n */\r\n public fork(): TransientIdSequenceProps {\r\n return {\r\n initialLocalId: this.currentLocalId,\r\n currentLocalId: this.currentLocalId,\r\n };\r\n }\r\n\r\n /** Integrate the Ids generated by a [[fork]] of this sequence. All of the Ids generated by `source` will be remapped to Ids at the end of this sequence.\r\n * This is chiefly useful when generating transient Ids on a [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker).\r\n * @param source The JSON representation of the [[fork]]ed sequence to be merged with this one.\r\n * @returns a function that permits you to remap the local Ids generated by `source` into the corresponding local Ids assigned by this sequence.\r\n * @throws Error if `source` is not a fork of this sequence or is malformed (e.g., contains negative and/or non-integer local Ids).\r\n */\r\n public merge(source: TransientIdSequenceProps): (sourceLocalId: number) => number {\r\n const { initialLocalId, currentLocalId } = source;\r\n\r\n validateLocalId(initialLocalId);\r\n validateLocalId(currentLocalId);\r\n\r\n if (initialLocalId > this.currentLocalId) {\r\n throw new Error(\"Transient Id sequences do not intersect\");\r\n }\r\n\r\n if (initialLocalId > currentLocalId) {\r\n throw new Error(\"Current local Id cannot be less than initial local Id\");\r\n }\r\n\r\n const delta = this.currentLocalId - initialLocalId;\r\n this._localId += currentLocalId - initialLocalId;\r\n\r\n return (sourceLocalId: number) => {\r\n if (sourceLocalId > initialLocalId && sourceLocalId <= currentLocalId) {\r\n return sourceLocalId + delta;\r\n }\r\n\r\n return sourceLocalId;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * The Guid namespace provides facilities for working with GUID strings using the \"8-4-4-4-12\" pattern.\r\n *\r\n * The [[GuidString]] type alias is used to indicate function arguments, return types, and variables which are known to\r\n * be in the GUID format.\r\n * @public\r\n */\r\nexport namespace Guid {\r\n const uuidPattern = new RegExp(\"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\");\r\n\r\n /** Represents the empty Guid 00000000-0000-0000-0000-000000000000 */\r\n export const empty: GuidString = \"00000000-0000-0000-0000-000000000000\";\r\n\r\n /** Determine whether the input string is \"guid-like\". That is, it follows the 8-4-4-4-12 pattern. This does not enforce\r\n * that the string is actually in valid UUID format.\r\n */\r\n export function isGuid(value: string): boolean {\r\n return uuidPattern.test(value);\r\n }\r\n\r\n /** Determine whether the input string is a valid V4 Guid string */\r\n export function isV4Guid(value: string): boolean {\r\n return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(value);\r\n }\r\n\r\n /** Create a new V4 Guid value */\r\n export function createValue(): GuidString {\r\n // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript\r\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\r\n const r = Math.random() * 16 | 0;\r\n const v = c === \"x\" ? r : (r & 0x3 | 0x8);\r\n return v.toString(16);\r\n });\r\n }\r\n\r\n /**\r\n * Normalize a Guid string if possible. Normalization consists of:\r\n * - Convert all characters to lower case\r\n * - Trim any leading or trailing whitespace\r\n * - Convert to the standard Guid format \"8-4-4-4-12\", repositioning the '-' characters as necessary, presuming there are exactly 32 hexadecimal digits.\r\n * @param value Input value that represents a Guid\r\n * @returns Normalized representation of the Guid string. If the normalization fails, return the *original* value unmodified (Note: it is *not* a valid Guid)\r\n */\r\n export function normalize(value: GuidString): GuidString {\r\n const lowerValue = value.toLowerCase().trim();\r\n\r\n // Return if it's already formatted to be a Guid\r\n if (isGuid(lowerValue))\r\n return lowerValue;\r\n\r\n // Remove any existing \"-\" characters and position them properly, if there remains exactly 32 hexadecimal digits\r\n const noDashValue = lowerValue.replace(/-/g, \"\");\r\n const noDashPattern = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;\r\n if (noDashPattern.test(noDashValue)) {\r\n return noDashValue.replace(noDashPattern,\r\n (_match: string, p1: string, p2: string, p3: string, p4: string, p5: string) =>\r\n `${p1}-${p2}-${p3}-${p4}-${p5}`);\r\n }\r\n\r\n // Return unmodified string - (note: it is *not* a valid Guid)\r\n return value;\r\n }\r\n}\r\n"]}
|