@fluidframework/container-runtime 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.1
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 +18 -0
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +9 -1
- package/api-report/container-runtime.api.md +124 -107
- package/dist/blobManager.d.ts +4 -4
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js.map +1 -1
- package/dist/container-runtime-alpha.d.ts +1473 -0
- package/dist/container-runtime-beta.d.ts +300 -0
- package/dist/container-runtime-public.d.ts +300 -0
- package/dist/container-runtime-untrimmed.d.ts +1836 -0
- package/dist/containerRuntime.d.ts +30 -30
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +62 -40
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreRegistry.d.ts +1 -1
- package/dist/dataStoreRegistry.js +1 -1
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts +10 -15
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +77 -40
- package/dist/dataStores.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +41 -13
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +215 -78
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcConfigs.d.ts.map +1 -1
- package/dist/gc/gcConfigs.js +34 -37
- package/dist/gc/gcConfigs.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +121 -46
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js +26 -18
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcHelpers.d.ts +18 -25
- package/dist/gc/gcHelpers.d.ts.map +1 -1
- package/dist/gc/gcHelpers.js +29 -45
- package/dist/gc/gcHelpers.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts +0 -5
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +14 -42
- package/dist/gc/gcTelemetry.js.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.js +43 -19
- package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/dist/gc/index.d.ts +1 -1
- package/dist/gc/index.d.ts.map +1 -1
- package/dist/gc/index.js +4 -5
- package/dist/gc/index.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/dist/messageTypes.d.ts +15 -7
- package/dist/messageTypes.d.ts.map +1 -1
- package/dist/messageTypes.js +6 -1
- package/dist/messageTypes.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts +1 -1
- package/dist/opLifecycle/definitions.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/pendingStateManager.d.ts +1 -0
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +1 -0
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/summary/orderedClientElection.d.ts +1 -1
- package/dist/summary/orderedClientElection.js.map +1 -1
- package/dist/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/dist/summary/runWhileConnectedCoordinator.js +1 -1
- package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/summary/summarizer.d.ts +1 -1
- package/dist/summary/summarizer.js +1 -1
- package/dist/summary/summarizer.js.map +1 -1
- package/dist/summary/summarizerTypes.d.ts +30 -30
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/dist/summary/summaryCollection.d.ts +10 -10
- package/dist/summary/summaryCollection.js +1 -1
- package/dist/summary/summaryCollection.js.map +1 -1
- package/dist/summary/summaryFormat.d.ts +3 -3
- package/dist/summary/summaryFormat.js.map +1 -1
- package/lib/blobManager.d.ts +4 -4
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js.map +1 -1
- package/lib/container-runtime-alpha.d.ts +1473 -0
- package/lib/container-runtime-beta.d.ts +300 -0
- package/lib/container-runtime-public.d.ts +300 -0
- package/lib/container-runtime-untrimmed.d.ts +1836 -0
- package/lib/containerRuntime.d.ts +30 -30
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +64 -42
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreRegistry.d.ts +1 -1
- package/lib/dataStoreRegistry.js +1 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts +10 -15
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +80 -43
- package/lib/dataStores.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +41 -13
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +217 -80
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcConfigs.d.ts.map +1 -1
- package/lib/gc/gcConfigs.js +37 -40
- package/lib/gc/gcConfigs.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +121 -46
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js +25 -17
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcHelpers.d.ts +18 -25
- package/lib/gc/gcHelpers.d.ts.map +1 -1
- package/lib/gc/gcHelpers.js +27 -43
- package/lib/gc/gcHelpers.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts +0 -5
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +15 -43
- package/lib/gc/gcTelemetry.js.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.js +43 -19
- package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/lib/gc/index.d.ts +1 -1
- package/lib/gc/index.d.ts.map +1 -1
- package/lib/gc/index.js +1 -1
- package/lib/gc/index.js.map +1 -1
- package/lib/index.d.ts +14 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -1
- package/lib/index.js.map +1 -1
- package/lib/messageTypes.d.ts +15 -7
- package/lib/messageTypes.d.ts.map +1 -1
- package/lib/messageTypes.js +6 -1
- package/lib/messageTypes.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts +1 -1
- package/lib/opLifecycle/definitions.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/pendingStateManager.d.ts +1 -0
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +1 -0
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/summary/orderedClientElection.d.ts +1 -1
- package/lib/summary/orderedClientElection.js.map +1 -1
- package/lib/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/lib/summary/runWhileConnectedCoordinator.js +1 -1
- package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/summary/summarizer.d.ts +1 -1
- package/lib/summary/summarizer.js +1 -1
- package/lib/summary/summarizer.js.map +1 -1
- package/lib/summary/summarizerTypes.d.ts +30 -30
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/lib/summary/summaryCollection.d.ts +10 -10
- package/lib/summary/summaryCollection.js +1 -1
- package/lib/summary/summaryCollection.js.map +1 -1
- package/lib/summary/summaryFormat.d.ts +3 -3
- package/lib/summary/summaryFormat.js.map +1 -1
- package/package.json +42 -19
- package/src/blobManager.ts +5 -5
- package/src/containerRuntime.ts +86 -56
- package/src/dataStoreRegistry.ts +1 -1
- package/src/dataStores.ts +140 -69
- package/src/gc/garbageCollection.md +14 -15
- package/src/gc/garbageCollection.ts +256 -96
- package/src/gc/gcConfigs.ts +50 -52
- package/src/gc/gcDefinitions.ts +137 -52
- package/src/gc/gcHelpers.ts +31 -52
- package/src/gc/gcTelemetry.ts +16 -57
- package/src/gc/gcUnreferencedStateTracker.ts +61 -22
- package/src/gc/index.ts +6 -4
- package/src/index.ts +19 -1
- package/src/messageTypes.ts +19 -4
- package/src/opLifecycle/definitions.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +1 -0
- package/src/summary/orderedClientElection.ts +1 -1
- package/src/summary/runWhileConnectedCoordinator.ts +2 -2
- package/src/summary/summarizer.ts +1 -1
- package/src/summary/summarizerTypes.ts +30 -30
- package/src/summary/summaryCollection.ts +10 -10
- package/src/summary/summaryFormat.ts +3 -3
- package/dist/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/dist/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/dist/id-compressor/appendOnlySortedMap.js +0 -318
- package/dist/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/dist/id-compressor/finalSpace.d.ts +0 -29
- package/dist/id-compressor/finalSpace.d.ts.map +0 -1
- package/dist/id-compressor/finalSpace.js +0 -62
- package/dist/id-compressor/finalSpace.js.map +0 -1
- package/dist/id-compressor/idCompressor.d.ts +0 -54
- package/dist/id-compressor/idCompressor.d.ts.map +0 -1
- package/dist/id-compressor/idCompressor.js +0 -495
- package/dist/id-compressor/idCompressor.js.map +0 -1
- package/dist/id-compressor/identifiers.d.ts +0 -32
- package/dist/id-compressor/identifiers.d.ts.map +0 -1
- package/dist/id-compressor/identifiers.js +0 -15
- package/dist/id-compressor/identifiers.js.map +0 -1
- package/dist/id-compressor/index.d.ts +0 -13
- package/dist/id-compressor/index.d.ts.map +0 -1
- package/dist/id-compressor/index.js +0 -32
- package/dist/id-compressor/index.js.map +0 -1
- package/dist/id-compressor/persistanceUtilities.d.ts +0 -22
- package/dist/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/dist/id-compressor/persistanceUtilities.js +0 -43
- package/dist/id-compressor/persistanceUtilities.js.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.js +0 -80
- package/dist/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/dist/id-compressor/sessions.d.ts +0 -115
- package/dist/id-compressor/sessions.d.ts.map +0 -1
- package/dist/id-compressor/sessions.js +0 -305
- package/dist/id-compressor/sessions.js.map +0 -1
- package/dist/id-compressor/utilities.d.ts +0 -52
- package/dist/id-compressor/utilities.d.ts.map +0 -1
- package/dist/id-compressor/utilities.js +0 -169
- package/dist/id-compressor/utilities.js.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/lib/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.js +0 -314
- package/lib/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/lib/id-compressor/finalSpace.d.ts +0 -29
- package/lib/id-compressor/finalSpace.d.ts.map +0 -1
- package/lib/id-compressor/finalSpace.js +0 -58
- package/lib/id-compressor/finalSpace.js.map +0 -1
- package/lib/id-compressor/idCompressor.d.ts +0 -54
- package/lib/id-compressor/idCompressor.d.ts.map +0 -1
- package/lib/id-compressor/idCompressor.js +0 -491
- package/lib/id-compressor/idCompressor.js.map +0 -1
- package/lib/id-compressor/identifiers.d.ts +0 -32
- package/lib/id-compressor/identifiers.d.ts.map +0 -1
- package/lib/id-compressor/identifiers.js +0 -11
- package/lib/id-compressor/identifiers.js.map +0 -1
- package/lib/id-compressor/index.d.ts +0 -13
- package/lib/id-compressor/index.d.ts.map +0 -1
- package/lib/id-compressor/index.js +0 -13
- package/lib/id-compressor/index.js.map +0 -1
- package/lib/id-compressor/persistanceUtilities.d.ts +0 -22
- package/lib/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/lib/id-compressor/persistanceUtilities.js +0 -34
- package/lib/id-compressor/persistanceUtilities.js.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.js +0 -76
- package/lib/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/lib/id-compressor/sessions.d.ts +0 -115
- package/lib/id-compressor/sessions.d.ts.map +0 -1
- package/lib/id-compressor/sessions.js +0 -290
- package/lib/id-compressor/sessions.js.map +0 -1
- package/lib/id-compressor/utilities.d.ts +0 -52
- package/lib/id-compressor/utilities.d.ts.map +0 -1
- package/lib/id-compressor/utilities.js +0 -151
- package/lib/id-compressor/utilities.js.map +0 -1
- package/src/id-compressor/README.md +0 -3
- package/src/id-compressor/appendOnlySortedMap.ts +0 -366
- package/src/id-compressor/finalSpace.ts +0 -67
- package/src/id-compressor/idCompressor.ts +0 -630
- package/src/id-compressor/identifiers.ts +0 -42
- package/src/id-compressor/index.ts +0 -26
- package/src/id-compressor/persistanceUtilities.ts +0 -58
- package/src/id-compressor/sessionSpaceNormalizer.ts +0 -83
- package/src/id-compressor/sessions.ts +0 -405
- package/src/id-compressor/utilities.ts +0 -190
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../src/id-compressor/sessions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,GACjB,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAOpB,YAAmB,QAAyD;QAN5E,6HAA6H;QAC7H,4DAA4D;QAC3C,cAAS,GAAG,IAAI,KAAK,CAAuB,SAAS,EAAE,cAAc,CAAC,CAAC;QACxF,sGA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OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from \"sorted-btree\";\nimport { SessionId, StableId } from \"@fluidframework/runtime-definitions\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tcompareBigints,\n\tlocalIdFromGenCount,\n\tgenCountFromLocalId,\n\tnumericUuidFromStableId,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n\toffsetNumericUuid,\n} from \"./utilities\";\nimport { FinalCompressedId, LocalCompressedId, NumericUuid } from \"./identifiers\";\n\n/**\n * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).\n * This collection of all sessions comprises a distributed document's IDs.\n */\nexport class Sessions {\n\t// A range-queryable store of all sessions. A btree is used as it solves the predecessor problem for any given UUID, allowing\n\t// us to quickly find the session that may have produced it.\n\tprivate readonly uuidSpace = new BTree<NumericUuid, Session>(undefined, compareBigints);\n\t// A fast lookup table from session ID to the session object, used to avoid accessing the slower btree\n\tprivate readonly sessionCache = new Map<SessionId, Session>();\n\n\tpublic constructor(sessions?: [sessionBase: NumericUuid, session: Session][]) {\n\t\tif (sessions !== undefined) {\n\t\t\t// bulk load path\n\t\t\tfor (const [numeric, session] of sessions) {\n\t\t\t\tthis.sessionCache.set(stableIdFromNumericUuid(numeric) as SessionId, session);\n\t\t\t}\n\t\t\tthis.uuidSpace = new BTree(sessions, compareBigints);\n\t\t\tif (\n\t\t\t\tthis.sessionCache.size !== sessions.length ||\n\t\t\t\tsessions.length !== this.uuidSpace.size\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Cannot resume existing session.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic sessions(): IterableIterator<Session> {\n\t\treturn this.sessionCache.values();\n\t}\n\n\tpublic getOrCreate(sessionId: SessionId): Session {\n\t\tconst existing = this.sessionCache.get(sessionId);\n\t\tif (existing !== undefined) {\n\t\t\treturn existing;\n\t\t}\n\t\tconst session = new Session(sessionId);\n\t\tassert(\n\t\t\tthis.uuidSpace.set(session.sessionUuid, session),\n\t\t\t0x760 /* Duplicate session in map. */,\n\t\t);\n\t\tthis.sessionCache.set(sessionId, session);\n\t\treturn session;\n\t}\n\n\tpublic get(sessionId: SessionId): Session | undefined {\n\t\treturn this.sessionCache.get(sessionId);\n\t}\n\n\tpublic getContainingCluster(\n\t\tquery: StableId,\n\t): [cluster: IdCluster, alignedLocal: LocalCompressedId] | undefined {\n\t\tconst numericStable = numericUuidFromStableId(query);\n\t\tconst possibleMatch = this.uuidSpace.getPairOrNextLower(numericStable);\n\t\tif (possibleMatch === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [_, session] = possibleMatch;\n\t\tconst numericDelta = subtractNumericUuids(numericStable, session.sessionUuid);\n\t\tif (numericDelta > Number.MAX_SAFE_INTEGER) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst alignedLocal = localIdFromGenCount(Number(numericDelta) + 1);\n\t\tconst containingCluster = session.getClusterByLocal(alignedLocal, true);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [containingCluster, alignedLocal];\n\t}\n\n\tpublic clusterCollides(cluster: IdCluster): boolean {\n\t\tconst { session: owningSession, baseLocalId, capacity } = cluster;\n\t\tconst clusterBaseNumeric = offsetNumericUuid(\n\t\t\towningSession.sessionUuid,\n\t\t\tgenCountFromLocalId(baseLocalId) - 1,\n\t\t);\n\t\tconst clusterMaxNumeric = offsetNumericUuid(clusterBaseNumeric, capacity - 1);\n\t\tlet closestMatch: [NumericUuid, Session] | undefined =\n\t\t\tthis.uuidSpace.getPairOrNextLower(clusterMaxNumeric);\n\t\t// Find the first session that is not the owner of this new cluster.\n\t\t// Once we have that, check to see if its cluster chain overlaps with the new cluster.\n\t\t// Consider the following diagram of UUID space:\n\t\t// Cluster chain A: |----------------------|\n\t\t// Cluster chain B: |----------|\n\t\t// Cluster chain C: |-------|\n\t\t// While it is true that when adding a cluster to chain C, we would find\n\t\t// the next lower session (which is B) and erroneously determine we do not collide\n\t\t// with any other session, but this situation is impossible to get into as B would\n\t\t// have detected that it collided with A (or the other way around, depending on ordering).\n\t\twhile (closestMatch !== undefined && closestMatch[1] === owningSession) {\n\t\t\tclosestMatch = this.uuidSpace.nextLowerPair(closestMatch[0]);\n\t\t}\n\t\tif (closestMatch === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [_, session] = closestMatch;\n\t\tassert(session !== owningSession, 0x761 /* Failed to attempt to detect collisions. */);\n\t\tconst lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// If the closest session is empty (the local session), then it is guaranteed (probabilistically) that there are no\n\t\t\t// non-empty sessions that have a cluster chain that starts prior to the empty session and collides with the cluster\n\t\t\t// we are checking, so we can return false.\n\t\t\treturn false;\n\t\t}\n\t\tconst lastAllocatedNumeric = offsetNumericUuid(\n\t\t\tsession.sessionUuid,\n\t\t\tgenCountFromLocalId(lastAllocatedLocal(lastCluster)) - 1,\n\t\t);\n\t\treturn lastAllocatedNumeric >= clusterBaseNumeric;\n\t}\n\n\tpublic equals(other: Sessions, includeLocalState: boolean): boolean {\n\t\tconst checkIsSubset = (sessionsA: Sessions, sessionsB: Sessions) => {\n\t\t\tconst first = sessionsA.sessions().next();\n\t\t\tconst firstSessionThis = first.done ? undefined : first.value;\n\t\t\tfor (const [stableId, session] of sessionsA.sessionCache.entries()) {\n\t\t\t\tconst otherSession = sessionsB.sessionCache.get(stableId);\n\t\t\t\tif (otherSession === undefined) {\n\t\t\t\t\tif (!session.isEmpty() || includeLocalState) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsession === firstSessionThis,\n\t\t\t\t\t\t0x762 /* The only non-empty session must be the local session. */,\n\t\t\t\t\t);\n\t\t\t\t} else if (!session.equals(otherSession)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\treturn checkIsSubset(this, other) && checkIsSubset(other, this);\n\t}\n}\n\n/**\n * The IDs created by a specific session, stored as a cluster chain to allow for fast conversions.\n */\nexport class Session {\n\t// All clusters created by this session, in creation order (thus sorted by base final and local ID).\n\tprivate readonly clusterChain: IdCluster[] = [];\n\t// The numeric form of the SessionId\n\tpublic readonly sessionUuid: NumericUuid;\n\n\tpublic constructor(sessionId: SessionId | NumericUuid) {\n\t\tthis.sessionUuid =\n\t\t\ttypeof sessionId === \"string\" ? numericUuidFromStableId(sessionId) : sessionId;\n\t}\n\n\t/**\n\t * Adds a new empty cluster to the cluster chain of this session.\n\t */\n\tpublic addNewCluster(\n\t\tbaseFinalId: FinalCompressedId,\n\t\tcapacity: number,\n\t\tcount: number,\n\t): IdCluster {\n\t\tconst lastCluster = this.getLastCluster();\n\t\tconst newCluster: IdCluster = {\n\t\t\tsession: this,\n\t\t\tbaseFinalId,\n\t\t\tbaseLocalId: (lastCluster === undefined\n\t\t\t\t? -1\n\t\t\t\t: lastAllocatedLocal(lastCluster) - 1) as LocalCompressedId,\n\t\t\tcapacity,\n\t\t\tcount,\n\t\t};\n\t\tthis.clusterChain.push(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.clusterChain.length === 0;\n\t}\n\n\t/**\n\t * Returns the last cluster in this session's cluster chain, if any.\n\t */\n\tpublic getLastCluster(): IdCluster | undefined {\n\t\treturn this.clusterChain[this.clusterChain.length - 1];\n\t}\n\n\t/**\n\t * Converts the local ID from this session to a final ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic tryConvertToFinal(\n\t\tsearchLocal: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): FinalCompressedId | undefined {\n\t\tconst containingCluster = this.getClusterByLocal(searchLocal, includeAllocated);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getAlignedFinal(containingCluster, searchLocal);\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied local ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic getClusterByLocal(\n\t\tlocalId: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): IdCluster | undefined {\n\t\tconst lastValidLocal: (cluster: IdCluster) => LocalCompressedId = includeAllocated\n\t\t\t? lastAllocatedLocal\n\t\t\t: lastFinalizedLocal;\n\t\tconst matchedCluster = Session.binarySearch(\n\t\t\tlocalId,\n\t\t\tthis.clusterChain,\n\t\t\t(local, cluster): number => {\n\t\t\t\tconst lastLocal = lastValidLocal(cluster);\n\t\t\t\tif (local < lastLocal) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (local > cluster.baseLocalId) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t\treturn matchedCluster;\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied final ID, if possible.\n\t */\n\tpublic getClusterByAllocatedFinal(final: FinalCompressedId): IdCluster | undefined {\n\t\treturn Session.getContainingCluster(final, this.clusterChain);\n\t}\n\n\t/**\n\t * Returns the cluster from the supplied cluster chain containing the supplied final ID, if possible.\n\t * `clusterChain` must be sorted by final/local base ID.\n\t */\n\tpublic static getContainingCluster(\n\t\tfinalId: FinalCompressedId,\n\t\tclusterChain: readonly IdCluster[],\n\t): IdCluster | undefined {\n\t\treturn Session.binarySearch(finalId, clusterChain, (final, cluster) => {\n\t\t\tconst lastFinal = lastAllocatedFinal(cluster);\n\t\t\tif (final < cluster.baseFinalId) {\n\t\t\t\treturn -1;\n\t\t\t} else if (final > lastFinal) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tstatic binarySearch<S, T>(\n\t\tsearch: S,\n\t\tarr: readonly T[],\n\t\tcomparator: (a: S, b: T) => number,\n\t): T | undefined {\n\t\tlet left = 0;\n\t\tlet right = arr.length - 1;\n\t\twhile (left <= right) {\n\t\t\tconst mid = Math.floor((left + right) / 2);\n\t\t\tconst c = comparator(search, arr[mid]);\n\t\t\tif (c === 0) {\n\t\t\t\treturn arr[mid]; // Found the target, return its index.\n\t\t\t} else if (c > 0) {\n\t\t\t\tleft = mid + 1; // Continue search on right half.\n\t\t\t} else {\n\t\t\t\tright = mid - 1; // Continue search on left half.\n\t\t\t}\n\t\t}\n\t\treturn undefined; // If we reach here, target is not in array.\n\t}\n\n\tpublic equals(other: Session): boolean {\n\t\tfor (let i = 0; i < this.clusterChain.length; i++) {\n\t\t\tif (!clustersEqual(this.clusterChain[i], other.clusterChain[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn this.sessionUuid === other.sessionUuid;\n\t}\n}\n\n/**\n * A cluster of final (sequenced via consensus), sequentially allocated compressed IDs.\n * A final ID in a cluster decompresses to a sequentially allocated UUID that is the result of adding its offset within\n * the cluster to base UUID for the session that created it.\n */\nexport interface IdCluster {\n\t/**\n\t * The session that created this cluster.\n\t */\n\treadonly session: Session;\n\n\t/**\n\t * The first final ID in the cluster.\n\t */\n\treadonly baseFinalId: FinalCompressedId;\n\n\t/**\n\t * The local ID aligned with `baseFinalId`.\n\t */\n\treadonly baseLocalId: LocalCompressedId;\n\n\t/**\n\t * The total number of final IDs reserved for allocation in the cluster.\n\t * Clusters are reserved in blocks as a performance optimization.\n\t */\n\tcapacity: number;\n\n\t/**\n\t * The number of final IDs currently allocated in the cluster.\n\t */\n\tcount: number;\n}\n\nexport function clustersEqual(a: IdCluster, b: IdCluster): boolean {\n\treturn (\n\t\ta.session.sessionUuid === b.session.sessionUuid &&\n\t\ta.baseFinalId === b.baseFinalId &&\n\t\ta.baseLocalId === b.baseLocalId &&\n\t\ta.capacity === b.capacity &&\n\t\ta.count === b.count\n\t);\n}\n\n/**\n * Returns the final ID that is aligned with the supplied local ID within a cluster.\n * Includes allocated IDs.\n */\nexport function getAlignedFinal(\n\tcluster: IdCluster,\n\tlocalWithin: LocalCompressedId,\n): FinalCompressedId | undefined {\n\tconst clusterOffset =\n\t\tgenCountFromLocalId(localWithin) - genCountFromLocalId(cluster.baseLocalId);\n\tif (clusterOffset < cluster.capacity) {\n\t\treturn ((cluster.baseFinalId as number) + clusterOffset) as FinalCompressedId;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the local ID that is aligned with the supplied final ID within a cluster.\n * Fails if the supplied ID does not fall within the cluster bounds.\n */\nexport function getAlignedLocal(\n\tcluster: IdCluster,\n\tfinalWithin: FinalCompressedId,\n): LocalCompressedId {\n\tassert(\n\t\tfinalWithin >= cluster.baseFinalId && finalWithin <= lastAllocatedFinal(cluster),\n\t\t0x763 /* Supplied ID is not within the cluster. */,\n\t);\n\tconst finalDelta = finalWithin - cluster.baseFinalId;\n\treturn (cluster.baseLocalId - finalDelta) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + capacity) within a cluster\n */\nexport function lastAllocatedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.capacity - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + count) within a cluster\n */\nexport function lastFinalizedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.count - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + capacity) within a cluster\n */\nexport function lastAllocatedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.capacity - 1)) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster\n */\nexport function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.count - 1)) as LocalCompressedId;\n}\n"]}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { SessionId, StableId } from "@fluidframework/runtime-definitions";
|
|
6
|
-
import { LocalCompressedId, NumericUuid } from "./identifiers";
|
|
7
|
-
/**
|
|
8
|
-
* Generate a random session ID
|
|
9
|
-
*/
|
|
10
|
-
export declare function createSessionId(): SessionId;
|
|
11
|
-
/**
|
|
12
|
-
* Asserts that the given string is a stable ID.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export declare function assertIsStableId(stableId: string): StableId;
|
|
16
|
-
/**
|
|
17
|
-
* Asserts that the given string is a stable ID.
|
|
18
|
-
*/
|
|
19
|
-
export declare function assertIsSessionId(stableId: string): SessionId;
|
|
20
|
-
/**
|
|
21
|
-
* Generate a random stable ID
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare function generateStableId(): StableId;
|
|
25
|
-
/**
|
|
26
|
-
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
27
|
-
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export declare function isStableId(str: string): str is StableId;
|
|
31
|
-
/**
|
|
32
|
-
* A numeric comparator used for sorting in ascending order.
|
|
33
|
-
*
|
|
34
|
-
* Handles +/-0 like Map: -0 is equal to +0.
|
|
35
|
-
*/
|
|
36
|
-
export declare function compareFiniteNumbers<T extends number>(a: T, b: T): number;
|
|
37
|
-
/**
|
|
38
|
-
* Compares strings lexically to form a strict partial ordering.
|
|
39
|
-
*/
|
|
40
|
-
export declare function compareStrings<T extends string>(a: T, b: T): number;
|
|
41
|
-
/**
|
|
42
|
-
* Compares bigints to form a strict partial ordering.
|
|
43
|
-
*/
|
|
44
|
-
export declare function compareBigints<T extends bigint>(a: T, b: T): number;
|
|
45
|
-
export declare function genCountFromLocalId(localId: LocalCompressedId): number;
|
|
46
|
-
export declare function localIdFromGenCount(genCount: number): LocalCompressedId;
|
|
47
|
-
export declare function numericUuidFromStableId(stableId: StableId): NumericUuid;
|
|
48
|
-
export declare function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId;
|
|
49
|
-
export declare function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid;
|
|
50
|
-
export declare function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
|
|
51
|
-
export declare function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
|
|
52
|
-
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/id-compressor/utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EA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e,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAG3E"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/* eslint-disable no-bitwise */
|
|
6
|
-
import { assert } from "@fluidframework/core-utils";
|
|
7
|
-
import { v4 } from "uuid";
|
|
8
|
-
const hexadecimalCharCodes = Array.from("09afAF").map((c) => c.charCodeAt(0));
|
|
9
|
-
function isHexadecimalCharacter(charCode) {
|
|
10
|
-
return ((charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||
|
|
11
|
-
(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||
|
|
12
|
-
(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5]));
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Generate a random session ID
|
|
16
|
-
*/
|
|
17
|
-
export function createSessionId() {
|
|
18
|
-
return assertIsStableId(v4());
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Asserts that the given string is a stable ID.
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export function assertIsStableId(stableId) {
|
|
25
|
-
assert(isStableId(stableId), 0x4a3 /* Expected a StableId */);
|
|
26
|
-
return stableId;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Asserts that the given string is a stable ID.
|
|
30
|
-
*/
|
|
31
|
-
export function assertIsSessionId(stableId) {
|
|
32
|
-
assertIsStableId(stableId);
|
|
33
|
-
return stableId;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Generate a random stable ID
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export function generateStableId() {
|
|
40
|
-
return assertIsStableId(v4());
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
44
|
-
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export function isStableId(str) {
|
|
48
|
-
if (str.length !== 36) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
for (let i = 0; i < str.length; i++) {
|
|
52
|
-
switch (i) {
|
|
53
|
-
case 8:
|
|
54
|
-
case 13:
|
|
55
|
-
case 18:
|
|
56
|
-
case 23:
|
|
57
|
-
if (str.charAt(i) !== "-") {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case 14:
|
|
62
|
-
if (str.charAt(i) !== "4") {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
case 19: {
|
|
67
|
-
const char = str.charAt(i);
|
|
68
|
-
if (char !== "8" && char !== "9" && char !== "a" && char !== "b") {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
default:
|
|
74
|
-
if (!isHexadecimalCharacter(str.charCodeAt(i))) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* A numeric comparator used for sorting in ascending order.
|
|
84
|
-
*
|
|
85
|
-
* Handles +/-0 like Map: -0 is equal to +0.
|
|
86
|
-
*/
|
|
87
|
-
export function compareFiniteNumbers(a, b) {
|
|
88
|
-
return a - b;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Compares strings lexically to form a strict partial ordering.
|
|
92
|
-
*/
|
|
93
|
-
export function compareStrings(a, b) {
|
|
94
|
-
return a > b ? 1 : a === b ? 0 : -1;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Compares bigints to form a strict partial ordering.
|
|
98
|
-
*/
|
|
99
|
-
export function compareBigints(a, b) {
|
|
100
|
-
return a > b ? 1 : a === b ? 0 : -1;
|
|
101
|
-
}
|
|
102
|
-
export function genCountFromLocalId(localId) {
|
|
103
|
-
return -localId;
|
|
104
|
-
}
|
|
105
|
-
export function localIdFromGenCount(genCount) {
|
|
106
|
-
return -genCount;
|
|
107
|
-
}
|
|
108
|
-
// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
|
|
109
|
-
const versionMask = 0x4n << (19n * 4n); // Version 4
|
|
110
|
-
const variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)
|
|
111
|
-
const upperMask = 0xffffffffffffn << (20n * 4n);
|
|
112
|
-
// Upper mask when version/variant bits are removed
|
|
113
|
-
const strippedUpperMask = upperMask >> 6n;
|
|
114
|
-
const middieBittiesMask = 0xfffn << (16n * 4n);
|
|
115
|
-
// Middie mask when version/variant bits are removed
|
|
116
|
-
const strippedMiddieBittiesMask = middieBittiesMask >> 2n;
|
|
117
|
-
// Note: leading character should be 3 to mask at 0011
|
|
118
|
-
// The more-significant half of the N nibble is used to denote the variant (10xx)
|
|
119
|
-
const lowerMask = 0x3fffffffffffffffn;
|
|
120
|
-
export function numericUuidFromStableId(stableId) {
|
|
121
|
-
const uuidU128 = BigInt(`0x${stableId.replace(/-/g, "")}`);
|
|
122
|
-
const upperMasked = uuidU128 & upperMask;
|
|
123
|
-
const middieBittiesMasked = uuidU128 & middieBittiesMask;
|
|
124
|
-
const lowerMasked = uuidU128 & lowerMask;
|
|
125
|
-
const upperMaskedPlaced = upperMasked >> 6n;
|
|
126
|
-
const middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;
|
|
127
|
-
const id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;
|
|
128
|
-
return id;
|
|
129
|
-
}
|
|
130
|
-
export function stableIdFromNumericUuid(numericUuid) {
|
|
131
|
-
// bitwise reverse transform
|
|
132
|
-
const upperMasked = (numericUuid & strippedUpperMask) << 6n;
|
|
133
|
-
const middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;
|
|
134
|
-
const lowerMasked = numericUuid & lowerMask;
|
|
135
|
-
const uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;
|
|
136
|
-
// Pad to 32 characters, inserting leading zeroes if needed
|
|
137
|
-
const uuidString = uuidU128.toString(16).padStart(32, "0");
|
|
138
|
-
return `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(12, 16)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}`;
|
|
139
|
-
}
|
|
140
|
-
export function offsetNumericUuid(numericUuid, offset) {
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
142
|
-
return (numericUuid + BigInt(offset));
|
|
143
|
-
}
|
|
144
|
-
export function subtractNumericUuids(a, b) {
|
|
145
|
-
return (a - b);
|
|
146
|
-
}
|
|
147
|
-
export function addNumericUuids(a, b) {
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
149
|
-
return (a + b);
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=utilities.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../src/id-compressor/utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+BAA+B;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAG1B,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,o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AAC,IAAI,EAAE,CAAC;IAC5D,MAAM,mBAAmB,GAAG,CAAC,WAAW,GAAG,yBAAyB,CAAC,IAAI,EAAE,CAAC;IAC5E,MAAM,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;IAC5C,MAAM,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,mBAAmB,GAAG,WAAW,GAAG,WAAW,CAAC;IAC7F,2DAA2D;IAC3D,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,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\";\nimport { SessionId, StableId } from \"@fluidframework/runtime-definitions\";\nimport { v4 } from \"uuid\";\nimport { LocalCompressedId, NumericUuid } from \"./identifiers\";\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 */\nexport function createSessionId(): SessionId {\n\treturn assertIsStableId(v4()) as SessionId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n * @public\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 * @public\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 * @public\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,366 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* eslint-disable tsdoc/syntax */
|
|
7
|
-
/* eslint-disable no-bitwise */
|
|
8
|
-
import { assert } from "@fluidframework/core-utils";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A map in which entries are always added in key-sorted order.
|
|
12
|
-
* Supports appending and searching.
|
|
13
|
-
*/
|
|
14
|
-
export class AppendOnlySortedMap<K, V> {
|
|
15
|
-
protected readonly elements: (K | V)[] = [];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param comparator - a comparator for keys
|
|
19
|
-
*/
|
|
20
|
-
public constructor(protected readonly comparator: (a: K, b: K) => number) {}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @returns the number of entries in this map
|
|
24
|
-
*/
|
|
25
|
-
public get size(): number {
|
|
26
|
-
return this.elements.length / 2;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @returns the min key in the map.
|
|
31
|
-
*/
|
|
32
|
-
public minKey(): K | undefined {
|
|
33
|
-
return this.elements[0] as K | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @returns the max key in the map.
|
|
38
|
-
*/
|
|
39
|
-
public maxKey(): K | undefined {
|
|
40
|
-
return this.elements[this.elements.length - 2] as K | undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @returns the min value in the map.
|
|
45
|
-
*/
|
|
46
|
-
public minValue(): V | undefined {
|
|
47
|
-
return this.elements[1] as V | undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @returns the min value in the map.
|
|
52
|
-
*/
|
|
53
|
-
public maxValue(): V | undefined {
|
|
54
|
-
return this.elements[this.elements.length - 1] as V | undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @returns the min key in the map.
|
|
59
|
-
*/
|
|
60
|
-
public first(): [K, V] | undefined {
|
|
61
|
-
const { elements } = this;
|
|
62
|
-
const { length } = elements;
|
|
63
|
-
if (length === 0) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
return [elements[0] as K, elements[1] as V];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @returns the max key in the map.
|
|
71
|
-
*/
|
|
72
|
-
public last(): [K, V] | undefined {
|
|
73
|
-
const { elements } = this;
|
|
74
|
-
const { length } = elements;
|
|
75
|
-
if (length === 0) {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
const lastKeyIndex = length - 2;
|
|
79
|
-
return [elements[lastKeyIndex] as K, elements[lastKeyIndex + 1] as V];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Returns the element at the insertion index.
|
|
84
|
-
*/
|
|
85
|
-
public getAtIndex(index: number): [K, V] | undefined {
|
|
86
|
-
const realIndex = index * 2;
|
|
87
|
-
const { elements } = this;
|
|
88
|
-
if (realIndex < 0 || realIndex > elements.length - 1) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
return [elements[realIndex] as K, elements[realIndex + 1] as V];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @returns an iterable of the entries in the map.
|
|
96
|
-
*/
|
|
97
|
-
public *entries(): IterableIterator<readonly [K, V]> {
|
|
98
|
-
const { elements } = this;
|
|
99
|
-
for (let i = 0; i < elements.length; i += 2) {
|
|
100
|
-
yield [elements[i] as K, elements[i + 1] as V];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @returns an iterable of the keys in the map.
|
|
106
|
-
*/
|
|
107
|
-
public *keys(): IterableIterator<K> {
|
|
108
|
-
const { elements } = this;
|
|
109
|
-
for (let i = 0; i < elements.length; i += 2) {
|
|
110
|
-
yield elements[i] as K;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @returns an iterable of the values in the map.
|
|
116
|
-
*/
|
|
117
|
-
public *values(): IterableIterator<V> {
|
|
118
|
-
const { elements } = this;
|
|
119
|
-
for (let i = 0; i < elements.length; i += 2) {
|
|
120
|
-
yield elements[i + 1] as V;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @returns an iterable of the entries in the map, reversed.
|
|
126
|
-
*/
|
|
127
|
-
public *entriesReversed(): IterableIterator<readonly [K, V]> {
|
|
128
|
-
const { elements } = this;
|
|
129
|
-
for (let i = elements.length - 2; i >= 0; i -= 2) {
|
|
130
|
-
yield [elements[i] as K, elements[i + 1] as V];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Adds a new key/value pair to the map. `key` must be > to all keys in the map.
|
|
136
|
-
* @param key - the key to add.
|
|
137
|
-
* @param value - the value to add.
|
|
138
|
-
*/
|
|
139
|
-
public append(key: K, value: V): void {
|
|
140
|
-
const { elements } = this;
|
|
141
|
-
const { length } = elements;
|
|
142
|
-
if (length !== 0 && this.comparator(key, this.maxKey() as K) <= 0) {
|
|
143
|
-
throw new Error("Inserted key must be > all others in the map.");
|
|
144
|
-
}
|
|
145
|
-
elements.push(key);
|
|
146
|
-
elements.push(value);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Replaces the last key/value pair with the given one. If the map is empty, it simply appends.
|
|
151
|
-
* `key` must be > to all keys in the map prior to the one replaced.
|
|
152
|
-
* @param key - the key to add.
|
|
153
|
-
* @param value - the value to add.
|
|
154
|
-
*/
|
|
155
|
-
public replaceLast(key: K, value: V): void {
|
|
156
|
-
const { elements, comparator } = this;
|
|
157
|
-
const { length } = elements;
|
|
158
|
-
if (length !== 0) {
|
|
159
|
-
elements.pop();
|
|
160
|
-
elements.pop();
|
|
161
|
-
if (comparator(key, this.maxKey() as K) <= 0) {
|
|
162
|
-
throw new Error("Inserted key must be > all others in the map.");
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
elements.push(key);
|
|
166
|
-
elements.push(value);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* @param key - the key to lookup.
|
|
171
|
-
* @returns the value associated with `key` if such an entry exists, and undefined otherwise.
|
|
172
|
-
*/
|
|
173
|
-
public get(key: K): V | undefined {
|
|
174
|
-
const index = AppendOnlySortedMap.keyIndexOf(this.elements, key, this.comparator);
|
|
175
|
-
if (index < 0) {
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
return this.elements[index + 1] as V;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @param key - the key to lookup.
|
|
183
|
-
* @returns the entry associated with `key` if such an entry exists, the entry associated with the next lower key if such an entry
|
|
184
|
-
* exists, and undefined otherwise.
|
|
185
|
-
*/
|
|
186
|
-
public getPairOrNextLower(key: K): readonly [K, V] | undefined {
|
|
187
|
-
return this.getPairOrNextLowerBy(key, this.comparator);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @param key - the key to lookup.
|
|
192
|
-
* @returns the entry associated with `key` if such an entry exists, the entry associated with the next higher key if such an entry
|
|
193
|
-
* exists, and undefined otherwise.
|
|
194
|
-
*/
|
|
195
|
-
public getPairOrNextHigher(key: K): readonly [K, V] | undefined {
|
|
196
|
-
return this.getPairOrNextHigherBy(key, this.comparator);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Compares two `AppendOnlySortedMap`s.
|
|
201
|
-
*/
|
|
202
|
-
public equals(
|
|
203
|
-
other: AppendOnlySortedMap<K, V>,
|
|
204
|
-
compareValues: (a: V, b: V) => boolean,
|
|
205
|
-
): boolean {
|
|
206
|
-
if (other === this) {
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (this.elements.length !== other.elements.length) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
for (let i = this.elements.length - 2; i >= 0; i -= 2) {
|
|
215
|
-
const keyThis = this.elements[i] as K;
|
|
216
|
-
const valueThis = this.elements[i + 1] as V;
|
|
217
|
-
const keyOther = other.elements[i] as K;
|
|
218
|
-
const valueOther = other.elements[i + 1] as V;
|
|
219
|
-
if (this.comparator(keyThis, keyOther) !== 0) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
if (!compareValues(valueThis, valueOther)) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Test-only expensive assertions to check the internal validity of the data structure.
|
|
232
|
-
*/
|
|
233
|
-
public assertValid(): void {
|
|
234
|
-
let prev: readonly [K, unknown] | undefined;
|
|
235
|
-
for (const kv of this.entries()) {
|
|
236
|
-
if (prev !== undefined) {
|
|
237
|
-
assert(
|
|
238
|
-
this.comparator(kv[0], prev[0]) > 0,
|
|
239
|
-
0x752 /* Keys in map must be sorted. */,
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
prev = kv;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Queries a range of entries.
|
|
248
|
-
* @param from - the key to start the range query at, inclusive.
|
|
249
|
-
* @param to - the key to end the range query at, inclusive.
|
|
250
|
-
* @returns the range of entries.
|
|
251
|
-
*/
|
|
252
|
-
public *getRange(from: K, to: K): IterableIterator<readonly [K, V]> {
|
|
253
|
-
const keyIndexFrom = this.getKeyIndexOfOrNextHigher(from, this.comparator);
|
|
254
|
-
if (keyIndexFrom === undefined) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const keyIndexTo = this.getKeyIndexOfOrNextLower(to, this.comparator);
|
|
259
|
-
if (keyIndexTo === undefined) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
for (let i = keyIndexFrom; i <= keyIndexTo; i += 2) {
|
|
264
|
-
yield [this.elements[i] as K, this.elements[i + 1] as V];
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
protected getPairOrNextLowerBy<T>(
|
|
269
|
-
search: T,
|
|
270
|
-
comparator: (search: T, key: K, value: V) => number,
|
|
271
|
-
): readonly [K, V] | undefined {
|
|
272
|
-
const keyIndex = this.getKeyIndexOfOrNextLower(search, comparator);
|
|
273
|
-
if (keyIndex === undefined) {
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private getKeyIndexOfOrNextLower<T>(
|
|
281
|
-
search: T,
|
|
282
|
-
comparator: (search: T, key: K, value: V) => number,
|
|
283
|
-
): number | undefined {
|
|
284
|
-
const { elements } = this;
|
|
285
|
-
if (elements.length === 0) {
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
288
|
-
let keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);
|
|
289
|
-
if (keyIndex < 0) {
|
|
290
|
-
keyIndex ^= AppendOnlySortedMap.failureXor;
|
|
291
|
-
if (keyIndex > 0) {
|
|
292
|
-
return keyIndex - 2;
|
|
293
|
-
}
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
return keyIndex;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
protected getPairOrNextHigherBy<T>(
|
|
300
|
-
search: T,
|
|
301
|
-
comparator: (search: T, key: K, value: V) => number,
|
|
302
|
-
): readonly [K, V] | undefined {
|
|
303
|
-
const keyIndex = this.getKeyIndexOfOrNextHigher(search, comparator);
|
|
304
|
-
if (keyIndex === undefined) {
|
|
305
|
-
return undefined;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return [this.elements[keyIndex] as K, this.elements[keyIndex + 1] as V];
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
private getKeyIndexOfOrNextHigher<T>(
|
|
312
|
-
search: T,
|
|
313
|
-
comparator: (search: T, key: K, value: V) => number,
|
|
314
|
-
): number | undefined {
|
|
315
|
-
const { elements } = this;
|
|
316
|
-
const { length } = elements;
|
|
317
|
-
if (length === 0) {
|
|
318
|
-
return undefined;
|
|
319
|
-
}
|
|
320
|
-
let keyIndex = AppendOnlySortedMap.keyIndexOf(elements, search, comparator);
|
|
321
|
-
if (keyIndex < 0) {
|
|
322
|
-
keyIndex ^= AppendOnlySortedMap.failureXor;
|
|
323
|
-
if (keyIndex < length) {
|
|
324
|
-
return keyIndex;
|
|
325
|
-
}
|
|
326
|
-
return undefined;
|
|
327
|
-
}
|
|
328
|
-
return keyIndex;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* The value xor'd with the result index when a search fails.
|
|
333
|
-
*/
|
|
334
|
-
public static readonly failureXor = -1;
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Performs a binary search on the sorted array.
|
|
338
|
-
* @returns the index of the key for `search`, or (if not present) the index it would have been inserted into xor'd
|
|
339
|
-
* with `failureXor`. Note that negating is not an adequate solution as that could result in -0.
|
|
340
|
-
*/
|
|
341
|
-
public static keyIndexOf<T, K, V>(
|
|
342
|
-
elements: readonly (K | V)[],
|
|
343
|
-
search: T,
|
|
344
|
-
comparator: (search: T, key: K, value: V) => number,
|
|
345
|
-
): number {
|
|
346
|
-
// Low, high, and mid are addresses of [K,V] pairs and *not* key indices
|
|
347
|
-
let low = 0;
|
|
348
|
-
let high = elements.length / 2;
|
|
349
|
-
let mid = high >> 1;
|
|
350
|
-
while (low < high) {
|
|
351
|
-
const keyIndex = mid * 2;
|
|
352
|
-
const c = comparator(search, elements[keyIndex] as K, elements[keyIndex + 1] as V);
|
|
353
|
-
if (c > 0) {
|
|
354
|
-
low = mid + 1;
|
|
355
|
-
} else if (c < 0) {
|
|
356
|
-
high = mid;
|
|
357
|
-
} else if (c === 0) {
|
|
358
|
-
return keyIndex;
|
|
359
|
-
} else {
|
|
360
|
-
throw new Error("Invalid comparator.");
|
|
361
|
-
}
|
|
362
|
-
mid = (low + high) >> 1;
|
|
363
|
-
}
|
|
364
|
-
return (mid * 2) ^ AppendOnlySortedMap.failureXor;
|
|
365
|
-
}
|
|
366
|
-
}
|