@fluidframework/id-compressor 2.0.0-dev-rc.3.0.0.250606 → 2.0.0-dev-rc.3.0.0.254274
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/api-report/id-compressor.api.md +2 -1
- package/dist/appendOnlySortedMap.js +2 -2
- package/dist/appendOnlySortedMap.js.map +1 -1
- package/dist/finalSpace.d.ts.map +1 -1
- package/dist/finalSpace.js +2 -2
- package/dist/finalSpace.js.map +1 -1
- package/dist/id-compressor-alpha.d.ts +5 -1
- package/dist/id-compressor-untrimmed.d.ts +5 -1
- package/dist/idCompressor.d.ts.map +1 -1
- package/dist/idCompressor.js +22 -21
- package/dist/idCompressor.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sessionSpaceNormalizer.d.ts +2 -0
- package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
- package/dist/sessionSpaceNormalizer.js +44 -0
- package/dist/sessionSpaceNormalizer.js.map +1 -1
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +5 -5
- package/dist/sessions.js.map +1 -1
- package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -1
- package/dist/test/appendOnlySortedMap.spec.js.map +1 -1
- package/dist/test/idCompressor.perf.spec.js.map +1 -1
- package/dist/test/idCompressor.spec.js.map +1 -1
- package/dist/test/idCompressorTestUtilities.d.ts +1 -1
- package/dist/test/idCompressorTestUtilities.d.ts.map +1 -1
- package/dist/test/idCompressorTestUtilities.js +25 -1
- package/dist/test/idCompressorTestUtilities.js.map +1 -1
- package/dist/test/numericUuid.spec.js.map +1 -1
- package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -1
- package/dist/test/snapshots/summary.spec.js.map +1 -1
- package/dist/test/testCommon.d.ts +1 -1
- package/dist/test/testCommon.d.ts.map +1 -1
- package/dist/test/testCommon.js +4 -4
- package/dist/test/testCommon.js.map +1 -1
- package/dist/types/idCompressor.d.ts +1 -1
- package/dist/types/idCompressor.d.ts.map +1 -1
- package/dist/types/idCompressor.js.map +1 -1
- package/dist/types/persisted-types/0.0.1.d.ts +4 -0
- package/dist/types/persisted-types/0.0.1.d.ts.map +1 -1
- package/dist/types/persisted-types/0.0.1.js.map +1 -1
- package/dist/utilities.d.ts.map +1 -1
- package/dist/utilities.js +2 -2
- package/dist/utilities.js.map +1 -1
- package/lib/appendOnlySortedMap.js +1 -1
- package/lib/appendOnlySortedMap.js.map +1 -1
- package/lib/finalSpace.d.ts.map +1 -1
- package/lib/finalSpace.js +1 -1
- package/lib/finalSpace.js.map +1 -1
- package/lib/id-compressor-alpha.d.ts +5 -1
- package/lib/id-compressor-untrimmed.d.ts +5 -1
- package/lib/idCompressor.d.ts.map +1 -1
- package/lib/idCompressor.js +3 -2
- package/lib/idCompressor.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sessionSpaceNormalizer.d.ts +2 -0
- package/lib/sessionSpaceNormalizer.d.ts.map +1 -1
- package/lib/sessionSpaceNormalizer.js +44 -0
- package/lib/sessionSpaceNormalizer.js.map +1 -1
- package/lib/sessions.d.ts.map +1 -1
- package/lib/sessions.js +1 -1
- package/lib/sessions.js.map +1 -1
- package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -1
- package/lib/test/appendOnlySortedMap.spec.js.map +1 -1
- package/lib/test/idCompressor.perf.spec.js.map +1 -1
- package/lib/test/idCompressor.spec.js.map +1 -1
- package/lib/test/idCompressorTestUtilities.d.ts +1 -1
- package/lib/test/idCompressorTestUtilities.d.ts.map +1 -1
- package/lib/test/idCompressorTestUtilities.js +26 -2
- package/lib/test/idCompressorTestUtilities.js.map +1 -1
- package/lib/test/numericUuid.spec.js.map +1 -1
- package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -1
- package/lib/test/snapshots/summary.spec.js.map +1 -1
- package/lib/test/testCommon.d.ts +1 -1
- package/lib/test/testCommon.d.ts.map +1 -1
- package/lib/test/testCommon.js +1 -1
- package/lib/test/testCommon.js.map +1 -1
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types/idCompressor.d.ts +1 -1
- package/lib/types/idCompressor.d.ts.map +1 -1
- package/lib/types/idCompressor.js.map +1 -1
- package/lib/types/persisted-types/0.0.1.d.ts +4 -0
- package/lib/types/persisted-types/0.0.1.d.ts.map +1 -1
- package/lib/types/persisted-types/0.0.1.js.map +1 -1
- package/lib/utilities.d.ts.map +1 -1
- package/lib/utilities.js +1 -1
- package/lib/utilities.js.map +1 -1
- package/package.json +14 -36
- package/src/appendOnlySortedMap.ts +1 -1
- package/src/finalSpace.ts +2 -1
- package/src/idCompressor.ts +8 -2
- package/src/packageVersion.ts +1 -1
- package/src/sessionSpaceNormalizer.ts +63 -0
- package/src/sessions.ts +2 -1
- package/src/test/idCompressorTestUtilities.ts +31 -3
- package/src/test/testCommon.ts +3 -2
- package/src/types/idCompressor.ts +1 -1
- package/src/types/persisted-types/0.0.1.ts +5 -0
- package/src/utilities.ts +2 -1
- package/lib/test/appendOnlySortedMap.perf.spec.js +0 -49
- package/lib/test/appendOnlySortedMap.spec.js +0 -166
- package/lib/test/idCompressor.perf.spec.js +0 -281
- package/lib/test/idCompressor.spec.js +0 -953
- package/lib/test/numericUuid.spec.js +0 -74
- package/lib/test/sessionSpaceNormalizer.spec.js +0 -43
- package/lib/test/snapshots/summary.spec.js +0 -127
package/lib/utilities.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/* eslint-disable no-bitwise */
|
|
6
|
-
import { assert } from "@fluidframework/core-utils";
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { v4 } from "uuid";
|
|
8
8
|
const hexadecimalCharCodes = Array.from("09afAF").map((c) => c.charCodeAt(0));
|
|
9
9
|
function isHexadecimalC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E;IACrE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAgB,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAc,EAAE,CAAc;IAClE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAc,EAAE,CAAc;IAC7D,qEAAqE;IACrE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { v4 } from \"uuid\";\nimport { LocalCompressedId, NumericUuid } from \"./identifiers.js\";\nimport { SessionId, StableId } from \"./types/index.js\";\n\nconst hexadecimalCharCodes = Array.from(\"09afAF\").map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/**\n * Generate a random session ID\n * @alpha\n */\nexport function createSessionId(): SessionId {\n\treturn assertIsStableId(v4()) as SessionId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n * @internal\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassert(isStableId(stableId), 0x4a3 /* Expected a StableId */);\n\treturn stableId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsSessionId(stableId: string): SessionId {\n\tassertIsStableId(stableId);\n\treturn stableId as SessionId;\n}\n\n/**\n * Generate a random stable ID\n * @internal\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n * @internal\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== \"-\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== \"4\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== \"8\" && char !== \"9\" && char !== \"a\" && char !== \"b\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Compares bigints to form a strict partial ordering.\n */\nexport function compareBigints<T extends bigint>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\nexport function genCountFromLocalId(localId: LocalCompressedId): number {\n\treturn -localId;\n}\n\nexport function localIdFromGenCount(genCount: number): LocalCompressedId {\n\treturn -genCount as LocalCompressedId;\n}\n\n// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx\nconst versionMask = 0x4n << (19n * 4n); // Version 4\nconst variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)\nconst upperMask = 0xffffffffffffn << (20n * 4n);\n// Upper mask when version/variant bits are removed\nconst strippedUpperMask = upperMask >> 6n;\nconst middieBittiesMask = 0xfffn << (16n * 4n);\n// Middie mask when version/variant bits are removed\nconst strippedMiddieBittiesMask = middieBittiesMask >> 2n;\n// Note: leading character should be 3 to mask at 0011\n// The more-significant half of the N nibble is used to denote the variant (10xx)\nconst lowerMask = 0x3fffffffffffffffn;\n\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuidU128 = BigInt(`0x${stableId.replace(/-/g, \"\")}`);\n\tconst upperMasked = uuidU128 & upperMask;\n\tconst middieBittiesMasked = uuidU128 & middieBittiesMask;\n\tconst lowerMasked = uuidU128 & lowerMask;\n\n\tconst upperMaskedPlaced = upperMasked >> 6n;\n\tconst middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;\n\n\tconst id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;\n\treturn id as NumericUuid;\n}\n\nexport function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId {\n\t// bitwise reverse transform\n\tconst upperMasked = (numericUuid & strippedUpperMask) << 6n;\n\tconst middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;\n\tconst lowerMasked = numericUuid & lowerMask;\n\tconst uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;\n\t// Pad to 32 characters, inserting leading zeroes if needed\n\tconst uuidString = uuidU128.toString(16).padStart(32, \"0\");\n\treturn `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(\n\t\t12,\n\t\t16,\n\t)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}` as StableId;\n}\n\nexport function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (numericUuid + BigInt(offset)) as NumericUuid;\n}\n\nexport function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\treturn (a - b) as NumericUuid;\n}\n\nexport function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (a + b) as NumericUuid;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+BAA+B;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAK1B,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAO3E,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC/C,OAAO,CACN,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,gBAAgB,CAAC,EAAE,EAAE,CAAc,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAChD,MAAM,CAAC,UAAU,CAAC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AAI,UAAU,CAAC,SAAS,CAC1F,EAAE,EACF,EAAE,CACF,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,EAAc,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAAwB,EAAE,MAAc;IACzE,qEAAqE;IACrE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAgB,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAc,EAAE,CAAc;IAClE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAc,EAAE,CAAc;IAC7D,qEAAqE;IACrE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { v4 } from \"uuid\";\n\nimport { LocalCompressedId, NumericUuid } from \"./identifiers.js\";\nimport { SessionId, StableId } from \"./types/index.js\";\n\nconst hexadecimalCharCodes = Array.from(\"09afAF\").map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/**\n * Generate a random session ID\n * @alpha\n */\nexport function createSessionId(): SessionId {\n\treturn assertIsStableId(v4()) as SessionId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n * @internal\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassert(isStableId(stableId), 0x4a3 /* Expected a StableId */);\n\treturn stableId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsSessionId(stableId: string): SessionId {\n\tassertIsStableId(stableId);\n\treturn stableId as SessionId;\n}\n\n/**\n * Generate a random stable ID\n * @internal\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n * @internal\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== \"-\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== \"4\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== \"8\" && char !== \"9\" && char !== \"a\" && char !== \"b\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Compares bigints to form a strict partial ordering.\n */\nexport function compareBigints<T extends bigint>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\nexport function genCountFromLocalId(localId: LocalCompressedId): number {\n\treturn -localId;\n}\n\nexport function localIdFromGenCount(genCount: number): LocalCompressedId {\n\treturn -genCount as LocalCompressedId;\n}\n\n// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx\nconst versionMask = 0x4n << (19n * 4n); // Version 4\nconst variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)\nconst upperMask = 0xffffffffffffn << (20n * 4n);\n// Upper mask when version/variant bits are removed\nconst strippedUpperMask = upperMask >> 6n;\nconst middieBittiesMask = 0xfffn << (16n * 4n);\n// Middie mask when version/variant bits are removed\nconst strippedMiddieBittiesMask = middieBittiesMask >> 2n;\n// Note: leading character should be 3 to mask at 0011\n// The more-significant half of the N nibble is used to denote the variant (10xx)\nconst lowerMask = 0x3fffffffffffffffn;\n\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuidU128 = BigInt(`0x${stableId.replace(/-/g, \"\")}`);\n\tconst upperMasked = uuidU128 & upperMask;\n\tconst middieBittiesMasked = uuidU128 & middieBittiesMask;\n\tconst lowerMasked = uuidU128 & lowerMask;\n\n\tconst upperMaskedPlaced = upperMasked >> 6n;\n\tconst middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;\n\n\tconst id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;\n\treturn id as NumericUuid;\n}\n\nexport function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId {\n\t// bitwise reverse transform\n\tconst upperMasked = (numericUuid & strippedUpperMask) << 6n;\n\tconst middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;\n\tconst lowerMasked = numericUuid & lowerMask;\n\tconst uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;\n\t// Pad to 32 characters, inserting leading zeroes if needed\n\tconst uuidString = uuidU128.toString(16).padStart(32, \"0\");\n\treturn `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(\n\t\t12,\n\t\t16,\n\t)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}` as StableId;\n}\n\nexport function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (numericUuid + BigInt(offset)) as NumericUuid;\n}\n\nexport function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\treturn (a - b) as NumericUuid;\n}\n\nexport function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (a + b) as NumericUuid;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/id-compressor",
|
|
3
|
-
"version": "2.0.0-dev-rc.3.0.0.
|
|
3
|
+
"version": "2.0.0-dev-rc.3.0.0.254274",
|
|
4
4
|
"description": "ID compressor",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,16 +14,6 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"import": {
|
|
18
|
-
"types": "./lib/index.d.ts",
|
|
19
|
-
"default": "./lib/index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
|
-
"default": "./dist/index.js"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"./public": {
|
|
27
17
|
"import": {
|
|
28
18
|
"types": "./lib/id-compressor-public.d.ts",
|
|
29
19
|
"default": "./lib/index.js"
|
|
@@ -53,7 +43,7 @@
|
|
|
53
43
|
"default": "./dist/index.js"
|
|
54
44
|
}
|
|
55
45
|
},
|
|
56
|
-
"./test": {
|
|
46
|
+
"./internal/test-utils": {
|
|
57
47
|
"import": {
|
|
58
48
|
"types": "./lib/test/index.d.ts",
|
|
59
49
|
"default": "./lib/test/index.js"
|
|
@@ -62,31 +52,21 @@
|
|
|
62
52
|
"types": "./dist/test/index.d.ts",
|
|
63
53
|
"default": "./dist/test/index.js"
|
|
64
54
|
}
|
|
65
|
-
},
|
|
66
|
-
"./test/idCompressorTestUtilities": {
|
|
67
|
-
"import": {
|
|
68
|
-
"types": "./lib/test/idCompressorTestUtilities.d.ts",
|
|
69
|
-
"default": "./lib/test/idCompressorTestUtilities.js"
|
|
70
|
-
},
|
|
71
|
-
"require": {
|
|
72
|
-
"types": "./dist/test/idCompressorTestUtilities.d.ts",
|
|
73
|
-
"default": "./dist/test/idCompressorTestUtilities.js"
|
|
74
|
-
}
|
|
75
55
|
}
|
|
76
56
|
},
|
|
77
57
|
"main": "dist/index.js",
|
|
78
|
-
"types": "dist/
|
|
58
|
+
"types": "dist/id-compressor-public.d.ts",
|
|
79
59
|
"c8": {
|
|
80
60
|
"all": true,
|
|
81
61
|
"cache-dir": "nyc/.cache",
|
|
82
62
|
"exclude": [
|
|
83
63
|
"src/test/**/*.*ts",
|
|
84
|
-
"
|
|
64
|
+
"lib/test/**/*.*js"
|
|
85
65
|
],
|
|
86
66
|
"exclude-after-remap": false,
|
|
87
67
|
"include": [
|
|
88
68
|
"src/**/*.*ts",
|
|
89
|
-
"
|
|
69
|
+
"lib/**/*.*js"
|
|
90
70
|
],
|
|
91
71
|
"report-dir": "nyc/report",
|
|
92
72
|
"reporter": [
|
|
@@ -97,18 +77,18 @@
|
|
|
97
77
|
"temp-directory": "nyc/.nyc_output"
|
|
98
78
|
},
|
|
99
79
|
"dependencies": {
|
|
100
|
-
"@fluid-internal/client-utils": "2.0.0-dev-rc.3.0.0.
|
|
101
|
-
"@fluidframework/core-interfaces": "2.0.0-dev-rc.3.0.0.
|
|
102
|
-
"@fluidframework/core-utils": "2.0.0-dev-rc.3.0.0.
|
|
103
|
-
"@fluidframework/telemetry-utils": "2.0.0-dev-rc.3.0.0.
|
|
80
|
+
"@fluid-internal/client-utils": "2.0.0-dev-rc.3.0.0.254274",
|
|
81
|
+
"@fluidframework/core-interfaces": "2.0.0-dev-rc.3.0.0.254274",
|
|
82
|
+
"@fluidframework/core-utils": "2.0.0-dev-rc.3.0.0.254274",
|
|
83
|
+
"@fluidframework/telemetry-utils": "2.0.0-dev-rc.3.0.0.254274",
|
|
104
84
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
105
85
|
"uuid": "^9.0.0"
|
|
106
86
|
},
|
|
107
87
|
"devDependencies": {
|
|
108
|
-
"@arethetypeswrong/cli": "^0.
|
|
88
|
+
"@arethetypeswrong/cli": "^0.15.2",
|
|
109
89
|
"@biomejs/biome": "^1.6.2",
|
|
110
|
-
"@fluid-internal/mocha-test-setup": "2.0.0-dev-rc.3.0.0.
|
|
111
|
-
"@fluid-private/stochastic-test-utils": "2.0.0-dev-rc.3.0.0.
|
|
90
|
+
"@fluid-internal/mocha-test-setup": "2.0.0-dev-rc.3.0.0.254274",
|
|
91
|
+
"@fluid-private/stochastic-test-utils": "2.0.0-dev-rc.3.0.0.254274",
|
|
112
92
|
"@fluid-tools/benchmark": "^0.48.0",
|
|
113
93
|
"@fluid-tools/build-cli": "^0.34.0",
|
|
114
94
|
"@fluidframework/build-common": "^2.0.3",
|
|
@@ -160,7 +140,6 @@
|
|
|
160
140
|
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
|
|
161
141
|
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
162
142
|
"check:are-the-types-wrong": "attw --pack . --entrypoints .",
|
|
163
|
-
"check:biome": "biome check .",
|
|
164
143
|
"check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
|
|
165
144
|
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
|
|
166
145
|
"ci:build:docs": "api-extractor run",
|
|
@@ -168,12 +147,11 @@
|
|
|
168
147
|
"eslint": "eslint --format stylish src",
|
|
169
148
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
170
149
|
"format": "fluid-build --task format .",
|
|
171
|
-
"format:biome": "biome check --apply .",
|
|
172
150
|
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
173
151
|
"lint": "fluid-build . --task lint",
|
|
174
152
|
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
175
153
|
"test": "npm run test:mocha",
|
|
176
|
-
"test:benchmark:report": "mocha --timeout 999999 --perfMode --parentProcess --fgrep @Benchmark --reporter @fluid-tools/benchmark/dist/MochaReporter.js \"./
|
|
154
|
+
"test:benchmark:report": "mocha --timeout 999999 --perfMode --parentProcess --fgrep @Benchmark --reporter @fluid-tools/benchmark/dist/MochaReporter.js \"./lib/**/*.perf.spec.*js\"",
|
|
177
155
|
"test:coverage": "c8 npm test",
|
|
178
156
|
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
|
|
179
157
|
"test:mocha:cjs": "mocha --recursive \"dist/test/**/*.spec.*js\" --exit",
|
|
@@ -181,6 +159,6 @@
|
|
|
181
159
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
182
160
|
"test:snapshots:regen": "npm run test:mocha:esm -- --snapshot",
|
|
183
161
|
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
184
|
-
"tsc:watch": "tsc --watch"
|
|
162
|
+
"tsc:watch": "copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist && fluid-tsc commonjs --watch --project ./tsconfig.cjs.json"
|
|
185
163
|
}
|
|
186
164
|
}
|
package/src/finalSpace.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { assert } from "@fluidframework/core-utils";
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
|
+
|
|
7
8
|
import { FinalCompressedId } from "./identifiers.js";
|
|
8
9
|
import { IdCluster, clustersEqual, lastAllocatedFinal, lastFinalizedFinal } from "./sessions.js";
|
|
9
10
|
|
package/src/idCompressor.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import { bufferToString, stringToBuffer } from "@fluid-internal/client-utils";
|
|
7
7
|
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
8
|
-
import { assert } from "@fluidframework/core-utils";
|
|
9
|
-
import { ITelemetryLoggerExt
|
|
8
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
9
|
+
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
10
|
+
import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
|
|
11
|
+
|
|
10
12
|
import { FinalSpace } from "./finalSpace.js";
|
|
11
13
|
import { FinalCompressedId, LocalCompressedId, NumericUuid, isFinalId } from "./identifiers.js";
|
|
12
14
|
import {
|
|
@@ -215,6 +217,10 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
|
|
|
215
217
|
firstGenCount: this.nextRangeBaseGenCount,
|
|
216
218
|
count,
|
|
217
219
|
requestedClusterSize: this.nextRequestedClusterSize,
|
|
220
|
+
localIdRanges: this.normalizer.getRangesBetween(
|
|
221
|
+
this.nextRangeBaseGenCount,
|
|
222
|
+
this.localGenCount,
|
|
223
|
+
),
|
|
218
224
|
},
|
|
219
225
|
};
|
|
220
226
|
this.nextRangeBaseGenCount = this.localGenCount + 1;
|
package/src/packageVersion.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
7
|
import { AppendOnlySortedMap } from "./appendOnlySortedMap.js";
|
|
7
8
|
import { LocalCompressedId } from "./identifiers.js";
|
|
8
9
|
import { compareFiniteNumbers, genCountFromLocalId } from "./utilities.js";
|
|
@@ -48,6 +49,68 @@ export class SessionSpaceNormalizer {
|
|
|
48
49
|
return this.localIdRanges;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
public getRangesBetween(
|
|
53
|
+
firstGenCount: number,
|
|
54
|
+
lastGenCount: number,
|
|
55
|
+
): [genCount: number, count: number][] {
|
|
56
|
+
const ranges: [genCount: number, count: number][] = [];
|
|
57
|
+
// we need to find the first range that either contains firstGenCount or is after it,
|
|
58
|
+
// since this method must find ranges between firstGenCount and lastGenCount
|
|
59
|
+
let firstRange = this.localIdRanges.getPairOrNextLower(firstGenCount);
|
|
60
|
+
// if the first range does not contain the first ID, next higher range is between but non-containing
|
|
61
|
+
if (firstRange === undefined || !this.rangeContains(firstRange, firstGenCount)) {
|
|
62
|
+
firstRange = this.localIdRanges.getPairOrNextHigher(firstGenCount);
|
|
63
|
+
if (firstRange === undefined) {
|
|
64
|
+
return ranges;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const [genCount, count] of this.localIdRanges.getRange(firstRange[0], lastGenCount)) {
|
|
69
|
+
ranges.push([genCount, count]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (ranges.length === 0) {
|
|
73
|
+
return ranges;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// now we touch up the first and last ranges to ensure that if they contain the
|
|
77
|
+
// queried IDs they are trimmed to start/end with the queried IDs
|
|
78
|
+
const [baseGenCount, baseCount] = ranges[0];
|
|
79
|
+
if (this.rangeContains(ranges[0], firstGenCount)) {
|
|
80
|
+
ranges[0] = [firstGenCount, baseCount - (firstGenCount - baseGenCount)];
|
|
81
|
+
assert(
|
|
82
|
+
this.rangeContains(ranges[0], firstGenCount),
|
|
83
|
+
"Expected the touched up range to contain the queried ID",
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
assert(
|
|
87
|
+
baseGenCount > firstGenCount,
|
|
88
|
+
"Expected the first range to start after the queried ID",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const lastRangeIndex = ranges.length - 1;
|
|
93
|
+
const [limitGenCount, limitCount] = ranges[lastRangeIndex];
|
|
94
|
+
if (this.rangeContains(ranges[lastRangeIndex], lastGenCount)) {
|
|
95
|
+
ranges[lastRangeIndex] = [limitGenCount, lastGenCount - limitGenCount + 1];
|
|
96
|
+
assert(
|
|
97
|
+
this.rangeContains(ranges[lastRangeIndex], lastGenCount),
|
|
98
|
+
"Expected the touched up range to contain the queried ID",
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
assert(
|
|
102
|
+
limitGenCount + limitCount - 1 < lastGenCount,
|
|
103
|
+
"Expected the last range to end before the queried ID",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return ranges;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private rangeContains(range: readonly [number, number], genCount: number): boolean {
|
|
110
|
+
const [baseGenCount, count] = range;
|
|
111
|
+
return genCount >= baseGenCount && genCount < baseGenCount + count;
|
|
112
|
+
}
|
|
113
|
+
|
|
51
114
|
public addLocalRange(baseGenCount: number, count: number): void {
|
|
52
115
|
const last = this.localIdRanges.last();
|
|
53
116
|
if (last !== undefined) {
|
package/src/sessions.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { assert } from "@fluidframework/core-utils";
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { BTree } from "@tylerbu/sorted-btree-es6";
|
|
8
|
+
|
|
8
9
|
import { FinalCompressedId, LocalCompressedId, NumericUuid } from "./identifiers.js";
|
|
9
10
|
import { SessionId, StableId } from "./types/index.js";
|
|
10
11
|
import {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { strict as assert } from "assert";
|
|
7
|
+
|
|
7
8
|
import {
|
|
8
9
|
BaseFuzzTestState,
|
|
9
10
|
Generator,
|
|
@@ -16,6 +17,8 @@ import {
|
|
|
16
17
|
take,
|
|
17
18
|
} from "@fluid-private/stochastic-test-utils";
|
|
18
19
|
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
20
|
+
|
|
21
|
+
import { IdCompressor } from "../idCompressor.js";
|
|
19
22
|
import {
|
|
20
23
|
type IIdCompressor,
|
|
21
24
|
type IIdCompressorCore,
|
|
@@ -27,9 +30,9 @@ import {
|
|
|
27
30
|
SessionSpaceCompressedId,
|
|
28
31
|
StableId,
|
|
29
32
|
createIdCompressor,
|
|
30
|
-
} from "
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
+
} from "../index.js";
|
|
34
|
+
import { assertIsSessionId, createSessionId, localIdFromGenCount } from "../utilities.js";
|
|
35
|
+
|
|
33
36
|
import {
|
|
34
37
|
FinalCompressedId,
|
|
35
38
|
ReadonlyIdCompressor,
|
|
@@ -135,6 +138,7 @@ export function buildHugeCompressor(
|
|
|
135
138
|
firstGenCount: Math.floor(i / numSessions) * capacity + 1,
|
|
136
139
|
count: capacity,
|
|
137
140
|
requestedClusterSize: capacity,
|
|
141
|
+
localIdRanges: [], // remote session, can safely ignore in tests
|
|
138
142
|
},
|
|
139
143
|
});
|
|
140
144
|
}
|
|
@@ -338,6 +342,7 @@ export class IdCompressorTestNetwork {
|
|
|
338
342
|
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
339
343
|
"nextRequestedClusterSize"
|
|
340
344
|
],
|
|
345
|
+
localIdRanges: [], // remote session, can safely ignore in tests
|
|
341
346
|
},
|
|
342
347
|
};
|
|
343
348
|
const opSpaceIds: OpSpaceCompressedId[] = [];
|
|
@@ -422,6 +427,29 @@ export class IdCompressorTestNetwork {
|
|
|
422
427
|
(client) => [this.compressors.get(client), this.getSequencedIdLog(client)] as const,
|
|
423
428
|
);
|
|
424
429
|
|
|
430
|
+
// Ensure creation ranges for clients we track contain the correct local ID ranges
|
|
431
|
+
this.serverOperations.forEach(([range, opSpaceIds, clientFrom]) => {
|
|
432
|
+
const localIdsInCreationRange = new Set<SessionSpaceCompressedId>();
|
|
433
|
+
if (clientFrom !== OriginatingClient.Remote) {
|
|
434
|
+
const ids = range.ids;
|
|
435
|
+
if (ids !== undefined) {
|
|
436
|
+
const { firstGenCount, localIdRanges } = ids;
|
|
437
|
+
for (const [genCount, count] of localIdRanges) {
|
|
438
|
+
for (let g = genCount; g < genCount + count; g++) {
|
|
439
|
+
const local = localIdFromGenCount(g);
|
|
440
|
+
assert.strictEqual(opSpaceIds[g - firstGenCount], local);
|
|
441
|
+
localIdsInCreationRange.add(local);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
opSpaceIds.forEach((id) => {
|
|
446
|
+
if (isLocalId(id)) {
|
|
447
|
+
assert(localIdsInCreationRange.has(id), "Local ID not in creation range");
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
425
453
|
// First, ensure all clients each generated a unique ID for each of their own calls to generate.
|
|
426
454
|
for (const [compressor, ids] of sequencedLogs) {
|
|
427
455
|
const allUuids = new Set<StableId | string>();
|
package/src/test/testCommon.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { assert } from "@fluidframework/core-utils";
|
|
7
|
-
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
|
+
|
|
8
8
|
import { IdCompressor } from "../idCompressor.js";
|
|
9
|
+
import { OpSpaceCompressedId, SessionSpaceCompressedId, StableId } from "../index.js";
|
|
9
10
|
import {
|
|
10
11
|
numericUuidFromStableId,
|
|
11
12
|
offsetNumericUuid,
|
|
@@ -112,7 +112,7 @@ export interface IIdCompressorCore {
|
|
|
112
112
|
* @param ghostSessionId - The session id that minted ids generated within `ghostSessionCallback` should be attributed to.
|
|
113
113
|
* @param ghostSessionCallback - Callback which mints ids attributed to the ghost session.
|
|
114
114
|
*/
|
|
115
|
-
beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void);
|
|
115
|
+
beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): void;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
|
|
@@ -54,5 +54,10 @@ export interface IdCreationRange {
|
|
|
54
54
|
* will be equal to overflow + `requestedClusterSize`.
|
|
55
55
|
*/
|
|
56
56
|
readonly requestedClusterSize: number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The ranges of IDs that were allocated as local IDs in the range created by `sessionId.`
|
|
60
|
+
*/
|
|
61
|
+
readonly localIdRanges: [genCount: number, count: number][];
|
|
57
62
|
};
|
|
58
63
|
}
|
package/src/utilities.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/* eslint-disable no-bitwise */
|
|
7
|
-
import { assert } from "@fluidframework/core-utils";
|
|
7
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
8
8
|
import { v4 } from "uuid";
|
|
9
|
+
|
|
9
10
|
import { LocalCompressedId, NumericUuid } from "./identifiers.js";
|
|
10
11
|
import { SessionId, StableId } from "./types/index.js";
|
|
11
12
|
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { makeRandom } from "@fluid-private/stochastic-test-utils";
|
|
6
|
-
import { BenchmarkType, benchmark } from "@fluid-tools/benchmark";
|
|
7
|
-
import { AppendOnlySortedMap } from "../appendOnlySortedMap.js";
|
|
8
|
-
import { compareFiniteNumbers } from "../utilities.js";
|
|
9
|
-
function runAppendOnlyMapPerfTests(mapBuilder) {
|
|
10
|
-
const type = BenchmarkType.Measurement;
|
|
11
|
-
let map;
|
|
12
|
-
let rand;
|
|
13
|
-
const keyChoices = [];
|
|
14
|
-
let localChoice = 0;
|
|
15
|
-
const before = () => {
|
|
16
|
-
rand = makeRandom(42);
|
|
17
|
-
map = mapBuilder();
|
|
18
|
-
let curKey = 0;
|
|
19
|
-
for (let i = 0; i < 100000; i++) {
|
|
20
|
-
map.append(curKey, rand.integer(0, Number.MAX_SAFE_INTEGER));
|
|
21
|
-
curKey += rand.integer(1, 10);
|
|
22
|
-
}
|
|
23
|
-
const keys = [...map.keys()];
|
|
24
|
-
for (let i = 0; i < map.size; i++) {
|
|
25
|
-
keyChoices.push(keys[rand.integer(0, map.size - 1)]);
|
|
26
|
-
}
|
|
27
|
-
localChoice = 0;
|
|
28
|
-
};
|
|
29
|
-
benchmark({
|
|
30
|
-
type,
|
|
31
|
-
title: `lookup a key`,
|
|
32
|
-
before,
|
|
33
|
-
benchmarkFn: () => {
|
|
34
|
-
map.get(keyChoices[localChoice++ % keyChoices.length]);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
benchmark({
|
|
38
|
-
type,
|
|
39
|
-
title: `lookup a pair or lower`,
|
|
40
|
-
before,
|
|
41
|
-
benchmarkFn: () => {
|
|
42
|
-
map.getPairOrNextLower(keyChoices[localChoice++ % keyChoices.length]);
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
describe("AppendOnlySortedMap Perf", () => {
|
|
47
|
-
runAppendOnlyMapPerfTests(() => new AppendOnlySortedMap(compareFiniteNumbers));
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=appendOnlySortedMap.perf.spec.js.map
|