@fluidframework/merge-tree 2.118.0 → 3.0.0
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 +34 -4
- package/README.md +53 -50
- package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
- package/dist/MergeTreeTextHelper.js +1 -0
- package/dist/MergeTreeTextHelper.js.map +1 -1
- package/dist/attributionCollection.js +6 -4
- package/dist/attributionCollection.js.map +1 -1
- package/dist/attributionPolicy.js +3 -4
- package/dist/attributionPolicy.js.map +1 -1
- package/dist/client.js +27 -10
- package/dist/client.js.map +1 -1
- package/dist/collections/rbTree.d.ts.map +1 -1
- package/dist/collections/rbTree.js +3 -0
- package/dist/collections/rbTree.js.map +1 -1
- package/dist/endOfTreeSegment.d.ts.map +1 -1
- package/dist/endOfTreeSegment.js +25 -26
- package/dist/endOfTreeSegment.js.map +1 -1
- package/dist/localReference.js +17 -7
- package/dist/localReference.js.map +1 -1
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +90 -74
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeNodeWalk.js +5 -5
- package/dist/mergeTreeNodeWalk.js.map +1 -1
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +117 -90
- package/dist/mergeTreeNodes.js.map +1 -1
- package/dist/mergeTreeTracking.js +4 -0
- package/dist/mergeTreeTracking.js.map +1 -1
- package/dist/opBuilder.js +9 -10
- package/dist/opBuilder.js.map +1 -1
- package/dist/ordinal.js +1 -2
- package/dist/ordinal.js.map +1 -1
- package/dist/partialLengths.js +109 -73
- package/dist/partialLengths.js.map +1 -1
- package/dist/perspective.js +31 -11
- package/dist/perspective.js.map +1 -1
- package/dist/properties.js +6 -7
- package/dist/properties.js.map +1 -1
- package/dist/referencePositions.d.ts.map +1 -1
- package/dist/referencePositions.js +7 -7
- package/dist/referencePositions.js.map +1 -1
- package/dist/revertibles.js +4 -5
- package/dist/revertibles.js.map +1 -1
- package/dist/segmentGroupCollection.js +2 -0
- package/dist/segmentGroupCollection.js.map +1 -1
- package/dist/segmentInfos.d.ts.map +1 -1
- package/dist/segmentInfos.js +5 -5
- package/dist/segmentInfos.js.map +1 -1
- package/dist/segmentPropertiesManager.js +3 -5
- package/dist/segmentPropertiesManager.js.map +1 -1
- package/dist/sequencePlace.js +3 -3
- package/dist/sequencePlace.js.map +1 -1
- package/dist/snapshotChunks.js +4 -5
- package/dist/snapshotChunks.js.map +1 -1
- package/dist/snapshotLoader.js +85 -70
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js +34 -14
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js +18 -10
- package/dist/snapshotlegacy.js.map +1 -1
- package/dist/sortedSet.js +1 -3
- package/dist/sortedSet.js.map +1 -1
- package/dist/stamps.js +11 -12
- package/dist/stamps.js.map +1 -1
- package/dist/test/attributionCollection.spec.js +1 -1
- package/dist/test/attributionCollection.spec.js.map +1 -1
- package/dist/test/beastTest.spec.js +15 -11
- package/dist/test/beastTest.spec.js.map +1 -1
- package/dist/test/client.apis.spec.js +2 -3
- package/dist/test/client.apis.spec.js.map +1 -1
- package/dist/test/client.replay.spec.js +17 -7
- package/dist/test/client.replay.spec.js.map +1 -1
- package/dist/test/clientTestHelper.js +7 -4
- package/dist/test/clientTestHelper.js.map +1 -1
- package/dist/test/mergeTreeOperationRunner.js +26 -16
- package/dist/test/mergeTreeOperationRunner.js.map +1 -1
- package/dist/test/obliterateOperations.d.ts.map +1 -1
- package/dist/test/revertibles.spec.js +1 -2
- package/dist/test/revertibles.spec.js.map +1 -1
- package/dist/test/snapshot.utils.d.ts.map +1 -1
- package/dist/test/snapshot.utils.js +7 -5
- package/dist/test/snapshot.utils.js.map +1 -1
- package/dist/test/stamps.spec.js +17 -7
- package/dist/test/stamps.spec.js.map +1 -1
- package/dist/test/testClient.d.ts.map +1 -1
- package/dist/test/testClient.js +19 -17
- package/dist/test/testClient.js.map +1 -1
- package/dist/test/testClientLogger.d.ts.map +1 -1
- package/dist/test/testClientLogger.js +12 -8
- package/dist/test/testClientLogger.js.map +1 -1
- package/dist/test/testServer.js +7 -7
- package/dist/test/testServer.js.map +1 -1
- package/dist/test/testUtils.d.ts +0 -1
- package/dist/test/testUtils.d.ts.map +1 -1
- package/dist/test/testUtils.js +9 -10
- package/dist/test/testUtils.js.map +1 -1
- package/dist/test/text.js +2 -3
- package/dist/test/text.js.map +1 -1
- package/dist/test/wordUnitTests.spec.js +1 -2
- package/dist/test/wordUnitTests.spec.js.map +1 -1
- package/dist/textSegment.js +3 -2
- package/dist/textSegment.js.map +1 -1
- package/dist/zamboni.js +20 -10
- package/dist/zamboni.js.map +1 -1
- package/lib/MergeTreeTextHelper.js +1 -0
- package/lib/MergeTreeTextHelper.js.map +1 -1
- package/lib/attributionCollection.js +4 -2
- package/lib/attributionCollection.js.map +1 -1
- package/lib/client.js +10 -3
- package/lib/client.js.map +1 -1
- package/lib/collections/rbTree.d.ts.map +1 -1
- package/lib/collections/rbTree.js +3 -0
- package/lib/collections/rbTree.js.map +1 -1
- package/lib/endOfTreeSegment.d.ts.map +1 -1
- package/lib/endOfTreeSegment.js +25 -26
- package/lib/endOfTreeSegment.js.map +1 -1
- package/lib/legacy.d.ts +1 -1
- package/lib/localReference.js +12 -2
- package/lib/localReference.js.map +1 -1
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +68 -62
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +111 -84
- package/lib/mergeTreeNodes.js.map +1 -1
- package/lib/mergeTreeTracking.js +4 -0
- package/lib/mergeTreeTracking.js.map +1 -1
- package/lib/partialLengths.js +89 -63
- package/lib/partialLengths.js.map +1 -1
- package/lib/perspective.js +12 -2
- package/lib/perspective.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/referencePositions.d.ts.map +1 -1
- package/lib/segmentGroupCollection.js +2 -0
- package/lib/segmentGroupCollection.js.map +1 -1
- package/lib/segmentInfos.d.ts.map +1 -1
- package/lib/segmentPropertiesManager.js +1 -3
- package/lib/segmentPropertiesManager.js.map +1 -1
- package/lib/snapshotLoader.js +68 -63
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js +17 -7
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js +18 -10
- package/lib/snapshotlegacy.js.map +1 -1
- package/lib/sortedSet.js +1 -3
- package/lib/sortedSet.js.map +1 -1
- package/lib/test/attributionCollection.spec.js +1 -1
- package/lib/test/attributionCollection.spec.js.map +1 -1
- package/lib/test/beastTest.spec.js +7 -3
- package/lib/test/beastTest.spec.js.map +1 -1
- package/lib/test/clientTestHelper.js +7 -4
- package/lib/test/clientTestHelper.js.map +1 -1
- package/lib/test/obliterateOperations.d.ts.map +1 -1
- package/lib/test/snapshot.utils.d.ts.map +1 -1
- package/lib/test/snapshot.utils.js +5 -3
- package/lib/test/snapshot.utils.js.map +1 -1
- package/lib/test/testClient.d.ts.map +1 -1
- package/lib/test/testClient.js +16 -14
- package/lib/test/testClient.js.map +1 -1
- package/lib/test/testClientLogger.d.ts.map +1 -1
- package/lib/test/testClientLogger.js +10 -6
- package/lib/test/testClientLogger.js.map +1 -1
- package/lib/test/testServer.js +5 -5
- package/lib/test/testServer.js.map +1 -1
- package/lib/test/testUtils.d.ts +0 -1
- package/lib/test/testUtils.d.ts.map +1 -1
- package/lib/textSegment.js +3 -2
- package/lib/textSegment.js.map +1 -1
- package/package.json +39 -58
- package/tsconfig.json +1 -1
- package/internal.d.ts +0 -11
- package/legacy.d.ts +0 -11
- /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
- /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rbTree.js","sourceRoot":"","sources":["../../src/collections/rbTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACU,QAAA,OAAO,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;CACC,CAAC;AA4GX;;GAEG;AACH,MAAa,YAAY;IAGxB,YACkB,WAA8B,EAC9B,GAAkC;QADlC,gBAAW,GAAX,WAAW,CAAmB;QAC9B,QAAG,GAAH,GAAG,CAA+B;IACjD,CAAC;IAEI,QAAQ,CAAC,GAAS,EAAE,IAAW,EAAE,KAAc,EAAE,IAAY;QACpE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAoC,CAAC;IACrE,CAAC;IAEO,KAAK,CAAC,IAAqC;QAClD,OAAO,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,eAAO,CAAC,GAAG,CAAC;IAC7C,CAAC;IAEO,QAAQ,CAAC,IAAqC;QACrD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACM,IAAI;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACM,OAAO;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACM,GAAG,CAAC,GAAS;QACnB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;IACO,OAAO,CACd,IAAqC,EACrC,GAAS;QAET,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,OAAO,KAAK,EAAE,CAAC;YACd,MAAM,GAAG,GAAG,IAAI,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,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,EAAE,IAAI,QAAQ,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YACxC,mCAAmC;YACnC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,EAAE,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAtlBD,oCAslBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * @internal\n */\nexport const RBColor = {\n\tRED: 0,\n\tBLACK: 1,\n} as const;\n\n/**\n * @internal\n */\nexport type RBColor = (typeof RBColor)[keyof typeof RBColor];\n\n/**\n * @internal\n */\nexport interface RBNode<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n\tleft: RBNode<TKey, TData> | undefined;\n\tright: RBNode<TKey, TData> | undefined;\n\tcolor: RBColor;\n\tsize: number;\n}\n/**\n * @internal\n */\nexport interface IRBAugmentation<TKey, TData> {\n\tupdate(node: RBNode<TKey, TData>): void;\n}\n/**\n * @internal\n */\nexport interface IRBMatcher<TKey, TData> {\n\tcontinueSubtree(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n\tmatchNode(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n}\n\n/**\n * @internal\n */\nexport interface RBNodeActions<TKey, TData> {\n\tinfix?(node: RBNode<TKey, TData>): boolean;\n\tpre?(node: RBNode<TKey, TData>): boolean;\n\tpost?(node: RBNode<TKey, TData>): boolean;\n\tshowStructure?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface KeyComparer<TKey> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(a: TKey, b: TKey): number;\n}\n\n/**\n * @internal\n */\nexport interface Property<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n}\n\n/**\n * @internal\n */\nexport interface PropertyAction<TKey, TData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t<TAccum>(p: Property<TKey, TData>, accum?: TAccum): boolean;\n}\n\n/**\n * @internal\n */\nexport interface QProperty<TKey, TData> {\n\tkey?: TKey;\n\tdata?: TData;\n}\n\n/**\n * @internal\n */\nexport type ConflictAction<TKey, TData> = (\n\tkey: TKey,\n\tcurrentKey: TKey,\n\tdata: TData,\n\tcurrentData: TData,\n) => QProperty<TKey, TData>;\n\n/**\n * @internal\n */\nexport interface SortedDictionary<TKey, TData> extends Dictionary<TKey, TData> {\n\tmax(): Property<TKey, TData> | undefined;\n\tmin(): Property<TKey, TData> | undefined;\n\tmapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void;\n}\n\n/**\n * @internal\n */\nexport interface Dictionary<TKey, TData> {\n\tget(key: TKey): Property<TKey, TData> | undefined;\n\tput(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void;\n\tremove(key: TKey): void;\n\tmap<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void;\n}\n\n/**\n * @internal\n */\nexport class RedBlackTree<TKey, TData> implements SortedDictionary<TKey, TData> {\n\tprivate root: RBNode<TKey, TData> | undefined;\n\n\tconstructor(\n\t\tprivate readonly compareKeys: KeyComparer<TKey>,\n\t\tprivate readonly aug?: IRBAugmentation<TKey, TData>,\n\t) {}\n\n\tprivate makeNode(key: TKey, data: TData, color: RBColor, size: number): RBNode<TKey, TData> {\n\t\treturn { key, data, color, size } as unknown as RBNode<TKey, TData>;\n\t}\n\n\tprivate isRed(node: RBNode<TKey, TData> | undefined): boolean {\n\t\treturn !!node && node.color === RBColor.RED;\n\t}\n\n\tprivate nodeSize(node: RBNode<TKey, TData> | undefined): number {\n\t\treturn node ? node.size : 0;\n\t}\n\tpublic size(): number {\n\t\treturn this.nodeSize(this.root);\n\t}\n\tpublic isEmpty(): boolean {\n\t\treturn !this.root;\n\t}\n\tpublic get(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (key !== undefined) {\n\t\t\treturn this.nodeGet(this.root, key);\n\t\t}\n\t}\n\tprivate nodeGet(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\twhile (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node = _node.left;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node = _node.right;\n\t\t\t} else {\n\t\t\t\treturn _node;\n\t\t\t}\n\t\t}\n\t}\n\tprivate contains(key: TKey): RBNode<TKey, TData> | undefined {\n\t\treturn this.get(key);\n\t}\n\n\tpublic gather(key: TKey, matcher: IRBMatcher<TKey, TData>): RBNode<TKey, TData>[] {\n\t\tconst results = [] as RBNode<TKey, TData>[];\n\t\tif (key !== undefined) {\n\t\t\tthis.nodeGather(this.root, results, key, matcher);\n\t\t}\n\t\treturn results;\n\t}\n\n\tprivate nodeGather(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tresults: RBNode<TKey, TData>[],\n\t\tkey: TKey,\n\t\tmatcher: IRBMatcher<TKey, TData>,\n\t): void {\n\t\tif (node) {\n\t\t\tif (matcher.continueSubtree(node.left, key)) {\n\t\t\t\tthis.nodeGather(node.left, results, key, matcher);\n\t\t\t}\n\t\t\tif (matcher.matchNode(node, key)) {\n\t\t\t\tresults.push(node);\n\t\t\t}\n\t\t\tif (matcher.continueSubtree(node.right, key)) {\n\t\t\t\tthis.nodeGather(node.right, results, key, matcher);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic walkExactMatchesForward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesForward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesForward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic walkExactMatchesBackward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (cmp: number) => boolean,\n\t\tcontinueRightFn: (cmp: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void {\n\t\tif (key !== undefined) {\n\t\t\tif (data === undefined) {\n\t\t\t\tthis.remove(key);\n\t\t\t} else {\n\t\t\t\tthis.root = this.nodePut(this.root, key, data, conflict);\n\t\t\t\tthis.root.color = RBColor.BLACK;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate nodePut(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t\tdata: TData,\n\t\tconflict?: ConflictAction<TKey, TData>,\n\t): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tif (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node.left = this.nodePut(_node.left, key, data, conflict);\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node.right = this.nodePut(_node.right, key, data, conflict);\n\t\t\t} else {\n\t\t\t\tif (conflict) {\n\t\t\t\t\tconst kd = conflict(key, _node.key, data, _node.data);\n\t\t\t\t\tif (kd.key) {\n\t\t\t\t\t\t_node.key = kd.key;\n\t\t\t\t\t}\n\t\t\t\t\t_node.data = kd.data ?? data;\n\t\t\t\t} else {\n\t\t\t\t\t_node.data = data;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isRed(_node.right) && !this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.right)) {\n\t\t\t\tthis.flipColors(_node);\n\t\t\t}\n\t\t\t_node.size = this.nodeSize(_node.left) + this.nodeSize(_node.right) + 1;\n\t\t\tif (this.aug) {\n\t\t\t\tthis.updateLocal(_node);\n\t\t\t}\n\t\t\treturn _node;\n\t\t} else {\n\t\t\treturn this.makeNode(key, data, RBColor.RED, 1);\n\t\t}\n\t}\n\n\tprivate updateLocal(node: RBNode<TKey, TData>): void {\n\t\tif (this.aug) {\n\t\t\tif (this.isRed(node.left)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.left!);\n\t\t\t}\n\t\t\tif (this.isRed(node.right)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.right!);\n\t\t\t}\n\t\t\tthis.aug.update(node);\n\t\t}\n\t}\n\n\tprivate nodeRemoveMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (_node.left) {\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemoveMin(_node.left!);\n\t\t\treturn this.balance(_node);\n\t\t}\n\t}\n\n\tpublic remove(key: TKey): void {\n\t\tif (key !== undefined) {\n\t\t\tif (!this.contains(key)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.removeExisting(key);\n\t\t}\n\t\t// TODO: error on undefined key\n\t}\n\n\tpublic removeExisting(key: TKey): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (!this.isRed(this.root!.left) && !this.isRed(this.root!.right)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.root!.color = RBColor.RED;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.root = this.nodeRemove(this.root!, key);\n\t}\n\n\tprivate nodeRemove(node: RBNode<TKey, TData>, key: TKey): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (this.compareKeys(key, _node.key) < 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemove(_node.left!, key);\n\t\t} else {\n\t\t\tif (this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0 && !_node.right) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.right) && !this.isRed(_node.right!.left)) {\n\t\t\t\t_node = this.moveRedRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst subtreeMin = this.nodeMin(_node.right!);\n\t\t\t\t_node.key = subtreeMin.key;\n\t\t\t\t_node.data = subtreeMin.data;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemoveMin(_node.right!);\n\t\t\t} else {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemove(_node.right!, key);\n\t\t\t}\n\t\t}\n\t\treturn this.balance(_node);\n\t}\n\n\t/**\n\t * Finds the largest node that is less than or equal to a given key.\n\t */\n\tpublic floor(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeFloor(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeFloor(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp < 0) {\n\t\t\t\treturn this.nodeFloor(node.left, key);\n\t\t\t} else {\n\t\t\t\tconst rightFloor = this.nodeFloor(node.right, key);\n\t\t\t\treturn rightFloor ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the smallest node that is greater than or equal to a given key.\n\t */\n\tpublic ceil(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeCeil(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeCeil(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\treturn this.nodeCeil(node.right, key);\n\t\t\t} else {\n\t\t\t\tconst leftCeil = this.nodeCeil(node.left, key);\n\t\t\t\treturn leftCeil ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic min(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMin(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.left ? this.nodeMin(node.left) : node;\n\t}\n\n\tpublic max(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMax(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMax(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.right ? this.nodeMax(node.right) : node;\n\t}\n\n\tprivate rotateRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst leftChild = node.left!;\n\t\tnode.left = leftChild.right;\n\t\tleftChild.right = node;\n\t\tleftChild.color = leftChild.right.color;\n\t\tleftChild.right.color = RBColor.RED;\n\t\tleftChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(leftChild);\n\t\t}\n\t\treturn leftChild;\n\t}\n\n\tprivate rotateLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst rightChild = node.right!;\n\t\tnode.right = rightChild.left;\n\t\trightChild.left = node;\n\t\trightChild.color = rightChild.left.color;\n\t\trightChild.left.color = RBColor.RED;\n\t\trightChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(rightChild);\n\t\t}\n\t\treturn rightChild;\n\t}\n\n\tprivate oppositeColor(c: RBColor): RBColor {\n\t\treturn c === RBColor.BLACK ? RBColor.RED : RBColor.BLACK;\n\t}\n\n\tprivate flipColors(node: RBNode<TKey, TData>): void {\n\t\tnode.color = this.oppositeColor(node.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.left!.color = this.oppositeColor(node.left!.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.right!.color = this.oppositeColor(node.right!.color);\n\t}\n\n\tprivate moveRedLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.right!.left)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.right = this.rotateRight(_node.right!);\n\t\t\t_node = this.rotateLeft(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate moveRedRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.left!.left)) {\n\t\t\t_node = this.rotateRight(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate balance(input: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet node: RBNode<TKey, TData> | undefined = input;\n\t\tif (this.isRed(node.right)) {\n\t\t\tnode = this.rotateLeft(node);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(node.left) && this.isRed(node.left!.left)) {\n\t\t\tnode = this.rotateRight(node);\n\t\t}\n\t\tif (this.isRed(node.left) && this.isRed(node.right)) {\n\t\t\tthis.flipColors(node);\n\t\t}\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.aug.update(node);\n\t\t}\n\t\treturn node;\n\t}\n\n\tpublic mapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void {\n\t\tthis.nodeMap(this.root, action, accum, start, end);\n\t}\n\n\tpublic map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void {\n\t\t// TODO: optimize to avoid comparisons\n\t\tthis.nodeMap(this.root, action, accum);\n\t}\n\n\tpublic keys(): TKey[] {\n\t\tconst keyList: TKey[] = [];\n\t\tconst actions: RBNodeActions<TKey, TData> = {\n\t\t\tshowStructure: true,\n\t\t\tinfix: (node) => {\n\t\t\t\tkeyList.push(node.key);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\tthis.walk(actions);\n\t\treturn keyList;\n\t}\n\n\t/**\n\t * Depth-first traversal with custom action; if action returns\n\t * false, traversal is halted.\n\t * @param action - action to apply to each node\n\t */\n\tpublic walk(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalk(this.root, actions);\n\t}\n\n\tpublic walkBackward(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalkBackward(this.root, actions);\n\t}\n\n\tprivate nodeWalk(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.left) {\n\t\t\t\tgo = this.nodeWalk(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalk(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeWalkBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.right) {\n\t\t\t\tgo = this.nodeWalkBackward(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalkBackward(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeMap<TAccum>(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): boolean {\n\t\tlet _start = start;\n\t\tlet _end = end;\n\t\tif (!node) {\n\t\t\treturn true;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_start === undefined) {\n\t\t\t_start = this.nodeMin(node).key;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_end === undefined) {\n\t\t\t_end = this.nodeMax(node).key;\n\t\t}\n\t\tconst cmpStart = this.compareKeys(_start, node.key);\n\t\tconst cmpEnd = this.compareKeys(_end, node.key);\n\t\tlet go = true;\n\t\tif (cmpStart < 0) {\n\t\t\tgo = this.nodeMap(node.left, action, accum, _start, _end);\n\t\t}\n\t\tif (go && cmpStart <= 0 && cmpEnd >= 0) {\n\t\t\t// REVIEW: test for black node here\n\t\t\tgo = action(node, accum);\n\t\t}\n\t\tif (go && cmpEnd > 0) {\n\t\t\tgo = this.nodeMap(node.right, action, accum, _start, _end);\n\t\t}\n\t\treturn go;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rbTree.js","sourceRoot":"","sources":["../../src/collections/rbTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACU,QAAA,OAAO,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;CACC,CAAC;AA4GX;;GAEG;AACH,MAAa,YAAY;IAIN;IACA;IAJV,IAAI,CAAkC;IAE9C,YACkB,WAA8B,EAC9B,GAAkC;QADlC,gBAAW,GAAX,WAAW,CAAmB;QAC9B,QAAG,GAAH,GAAG,CAA+B;IACjD,CAAC;IAEI,QAAQ,CAAC,GAAS,EAAE,IAAW,EAAE,KAAc,EAAE,IAAY;QACpE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAoC,CAAC;IACrE,CAAC;IAEO,KAAK,CAAC,IAAqC;QAClD,OAAO,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,eAAO,CAAC,GAAG,CAAC;IAC7C,CAAC;IAEO,QAAQ,CAAC,IAAqC;QACrD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACM,IAAI;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACM,OAAO;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACM,GAAG,CAAC,GAAS;QACnB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,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G,CAAC,CAAC;QAChD,IAAI,EAAE,GAAG,IAAI,CAAC;QACd,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YAClB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,EAAE,IAAI,QAAQ,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YACxC,mCAAmC;YACnC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,EAAE,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAtlBD,oCAslBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * @internal\n */\nexport const RBColor = {\n\tRED: 0,\n\tBLACK: 1,\n} as const;\n\n/**\n * @internal\n */\nexport type RBColor = (typeof RBColor)[keyof typeof RBColor];\n\n/**\n * @internal\n */\nexport interface RBNode<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n\tleft: RBNode<TKey, TData> | undefined;\n\tright: RBNode<TKey, TData> | undefined;\n\tcolor: RBColor;\n\tsize: number;\n}\n/**\n * @internal\n */\nexport interface IRBAugmentation<TKey, TData> {\n\tupdate(node: RBNode<TKey, TData>): void;\n}\n/**\n * @internal\n */\nexport interface IRBMatcher<TKey, TData> {\n\tcontinueSubtree(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n\tmatchNode(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n}\n\n/**\n * @internal\n */\nexport interface RBNodeActions<TKey, TData> {\n\tinfix?(node: RBNode<TKey, TData>): boolean;\n\tpre?(node: RBNode<TKey, TData>): boolean;\n\tpost?(node: RBNode<TKey, TData>): boolean;\n\tshowStructure?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface KeyComparer<TKey> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(a: TKey, b: TKey): number;\n}\n\n/**\n * @internal\n */\nexport interface Property<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n}\n\n/**\n * @internal\n */\nexport interface PropertyAction<TKey, TData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t<TAccum>(p: Property<TKey, TData>, accum?: TAccum): boolean;\n}\n\n/**\n * @internal\n */\nexport interface QProperty<TKey, TData> {\n\tkey?: TKey;\n\tdata?: TData;\n}\n\n/**\n * @internal\n */\nexport type ConflictAction<TKey, TData> = (\n\tkey: TKey,\n\tcurrentKey: TKey,\n\tdata: TData,\n\tcurrentData: TData,\n) => QProperty<TKey, TData>;\n\n/**\n * @internal\n */\nexport interface SortedDictionary<TKey, TData> extends Dictionary<TKey, TData> {\n\tmax(): Property<TKey, TData> | undefined;\n\tmin(): Property<TKey, TData> | undefined;\n\tmapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void;\n}\n\n/**\n * @internal\n */\nexport interface Dictionary<TKey, TData> {\n\tget(key: TKey): Property<TKey, TData> | undefined;\n\tput(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void;\n\tremove(key: TKey): void;\n\tmap<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void;\n}\n\n/**\n * @internal\n */\nexport class RedBlackTree<TKey, TData> implements SortedDictionary<TKey, TData> {\n\tprivate root: RBNode<TKey, TData> | undefined;\n\n\tconstructor(\n\t\tprivate readonly compareKeys: KeyComparer<TKey>,\n\t\tprivate readonly aug?: IRBAugmentation<TKey, TData>,\n\t) {}\n\n\tprivate makeNode(key: TKey, data: TData, color: RBColor, size: number): RBNode<TKey, TData> {\n\t\treturn { key, data, color, size } as unknown as RBNode<TKey, TData>;\n\t}\n\n\tprivate isRed(node: RBNode<TKey, TData> | undefined): boolean {\n\t\treturn !!node && node.color === RBColor.RED;\n\t}\n\n\tprivate nodeSize(node: RBNode<TKey, TData> | undefined): number {\n\t\treturn node ? node.size : 0;\n\t}\n\tpublic size(): number {\n\t\treturn this.nodeSize(this.root);\n\t}\n\tpublic isEmpty(): boolean {\n\t\treturn !this.root;\n\t}\n\tpublic get(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (key !== undefined) {\n\t\t\treturn this.nodeGet(this.root, key);\n\t\t}\n\t}\n\tprivate nodeGet(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\twhile (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node = _node.left;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node = _node.right;\n\t\t\t} else {\n\t\t\t\treturn _node;\n\t\t\t}\n\t\t}\n\t}\n\tprivate contains(key: TKey): RBNode<TKey, TData> | undefined {\n\t\treturn this.get(key);\n\t}\n\n\tpublic gather(key: TKey, matcher: IRBMatcher<TKey, TData>): RBNode<TKey, TData>[] {\n\t\tconst results = [] as RBNode<TKey, TData>[];\n\t\tif (key !== undefined) {\n\t\t\tthis.nodeGather(this.root, results, key, matcher);\n\t\t}\n\t\treturn results;\n\t}\n\n\tprivate nodeGather(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tresults: RBNode<TKey, TData>[],\n\t\tkey: TKey,\n\t\tmatcher: IRBMatcher<TKey, TData>,\n\t): void {\n\t\tif (node) {\n\t\t\tif (matcher.continueSubtree(node.left, key)) {\n\t\t\t\tthis.nodeGather(node.left, results, key, matcher);\n\t\t\t}\n\t\t\tif (matcher.matchNode(node, key)) {\n\t\t\t\tresults.push(node);\n\t\t\t}\n\t\t\tif (matcher.continueSubtree(node.right, key)) {\n\t\t\t\tthis.nodeGather(node.right, results, key, matcher);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic walkExactMatchesForward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesForward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesForward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic walkExactMatchesBackward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (cmp: number) => boolean,\n\t\tcontinueRightFn: (cmp: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void {\n\t\tif (key !== undefined) {\n\t\t\tif (data === undefined) {\n\t\t\t\tthis.remove(key);\n\t\t\t} else {\n\t\t\t\tthis.root = this.nodePut(this.root, key, data, conflict);\n\t\t\t\tthis.root.color = RBColor.BLACK;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate nodePut(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t\tdata: TData,\n\t\tconflict?: ConflictAction<TKey, TData>,\n\t): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tif (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node.left = this.nodePut(_node.left, key, data, conflict);\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node.right = this.nodePut(_node.right, key, data, conflict);\n\t\t\t} else {\n\t\t\t\tif (conflict) {\n\t\t\t\t\tconst kd = conflict(key, _node.key, data, _node.data);\n\t\t\t\t\tif (kd.key) {\n\t\t\t\t\t\t_node.key = kd.key;\n\t\t\t\t\t}\n\t\t\t\t\t_node.data = kd.data ?? data;\n\t\t\t\t} else {\n\t\t\t\t\t_node.data = data;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isRed(_node.right) && !this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.right)) {\n\t\t\t\tthis.flipColors(_node);\n\t\t\t}\n\t\t\t_node.size = this.nodeSize(_node.left) + this.nodeSize(_node.right) + 1;\n\t\t\tif (this.aug) {\n\t\t\t\tthis.updateLocal(_node);\n\t\t\t}\n\t\t\treturn _node;\n\t\t} else {\n\t\t\treturn this.makeNode(key, data, RBColor.RED, 1);\n\t\t}\n\t}\n\n\tprivate updateLocal(node: RBNode<TKey, TData>): void {\n\t\tif (this.aug) {\n\t\t\tif (this.isRed(node.left)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.left!);\n\t\t\t}\n\t\t\tif (this.isRed(node.right)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.right!);\n\t\t\t}\n\t\t\tthis.aug.update(node);\n\t\t}\n\t}\n\n\tprivate nodeRemoveMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (_node.left) {\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemoveMin(_node.left!);\n\t\t\treturn this.balance(_node);\n\t\t}\n\t}\n\n\tpublic remove(key: TKey): void {\n\t\tif (key !== undefined) {\n\t\t\tif (!this.contains(key)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.removeExisting(key);\n\t\t}\n\t\t// TODO: error on undefined key\n\t}\n\n\tpublic removeExisting(key: TKey): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (!this.isRed(this.root!.left) && !this.isRed(this.root!.right)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.root!.color = RBColor.RED;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.root = this.nodeRemove(this.root!, key);\n\t}\n\n\tprivate nodeRemove(node: RBNode<TKey, TData>, key: TKey): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (this.compareKeys(key, _node.key) < 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemove(_node.left!, key);\n\t\t} else {\n\t\t\tif (this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0 && !_node.right) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.right) && !this.isRed(_node.right!.left)) {\n\t\t\t\t_node = this.moveRedRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst subtreeMin = this.nodeMin(_node.right!);\n\t\t\t\t_node.key = subtreeMin.key;\n\t\t\t\t_node.data = subtreeMin.data;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemoveMin(_node.right!);\n\t\t\t} else {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemove(_node.right!, key);\n\t\t\t}\n\t\t}\n\t\treturn this.balance(_node);\n\t}\n\n\t/**\n\t * Finds the largest node that is less than or equal to a given key.\n\t */\n\tpublic floor(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeFloor(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeFloor(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp < 0) {\n\t\t\t\treturn this.nodeFloor(node.left, key);\n\t\t\t} else {\n\t\t\t\tconst rightFloor = this.nodeFloor(node.right, key);\n\t\t\t\treturn rightFloor ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the smallest node that is greater than or equal to a given key.\n\t */\n\tpublic ceil(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeCeil(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeCeil(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\treturn this.nodeCeil(node.right, key);\n\t\t\t} else {\n\t\t\t\tconst leftCeil = this.nodeCeil(node.left, key);\n\t\t\t\treturn leftCeil ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic min(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMin(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.left ? this.nodeMin(node.left) : node;\n\t}\n\n\tpublic max(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMax(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMax(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.right ? this.nodeMax(node.right) : node;\n\t}\n\n\tprivate rotateRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst leftChild = node.left!;\n\t\tnode.left = leftChild.right;\n\t\tleftChild.right = node;\n\t\tleftChild.color = leftChild.right.color;\n\t\tleftChild.right.color = RBColor.RED;\n\t\tleftChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(leftChild);\n\t\t}\n\t\treturn leftChild;\n\t}\n\n\tprivate rotateLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst rightChild = node.right!;\n\t\tnode.right = rightChild.left;\n\t\trightChild.left = node;\n\t\trightChild.color = rightChild.left.color;\n\t\trightChild.left.color = RBColor.RED;\n\t\trightChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(rightChild);\n\t\t}\n\t\treturn rightChild;\n\t}\n\n\tprivate oppositeColor(c: RBColor): RBColor {\n\t\treturn c === RBColor.BLACK ? RBColor.RED : RBColor.BLACK;\n\t}\n\n\tprivate flipColors(node: RBNode<TKey, TData>): void {\n\t\tnode.color = this.oppositeColor(node.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.left!.color = this.oppositeColor(node.left!.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.right!.color = this.oppositeColor(node.right!.color);\n\t}\n\n\tprivate moveRedLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.right!.left)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.right = this.rotateRight(_node.right!);\n\t\t\t_node = this.rotateLeft(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate moveRedRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.left!.left)) {\n\t\t\t_node = this.rotateRight(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate balance(input: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet node: RBNode<TKey, TData> | undefined = input;\n\t\tif (this.isRed(node.right)) {\n\t\t\tnode = this.rotateLeft(node);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(node.left) && this.isRed(node.left!.left)) {\n\t\t\tnode = this.rotateRight(node);\n\t\t}\n\t\tif (this.isRed(node.left) && this.isRed(node.right)) {\n\t\t\tthis.flipColors(node);\n\t\t}\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.aug.update(node);\n\t\t}\n\t\treturn node;\n\t}\n\n\tpublic mapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void {\n\t\tthis.nodeMap(this.root, action, accum, start, end);\n\t}\n\n\tpublic map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void {\n\t\t// TODO: optimize to avoid comparisons\n\t\tthis.nodeMap(this.root, action, accum);\n\t}\n\n\tpublic keys(): TKey[] {\n\t\tconst keyList: TKey[] = [];\n\t\tconst actions: RBNodeActions<TKey, TData> = {\n\t\t\tshowStructure: true,\n\t\t\tinfix: (node) => {\n\t\t\t\tkeyList.push(node.key);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\tthis.walk(actions);\n\t\treturn keyList;\n\t}\n\n\t/**\n\t * Depth-first traversal with custom action; if action returns\n\t * false, traversal is halted.\n\t * @param action - action to apply to each node\n\t */\n\tpublic walk(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalk(this.root, actions);\n\t}\n\n\tpublic walkBackward(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalkBackward(this.root, actions);\n\t}\n\n\tprivate nodeWalk(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.left) {\n\t\t\t\tgo = this.nodeWalk(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalk(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeWalkBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.right) {\n\t\t\t\tgo = this.nodeWalkBackward(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalkBackward(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeMap<TAccum>(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): boolean {\n\t\tlet _start = start;\n\t\tlet _end = end;\n\t\tif (!node) {\n\t\t\treturn true;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_start === undefined) {\n\t\t\t_start = this.nodeMin(node).key;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_end === undefined) {\n\t\t\t_end = this.nodeMax(node).key;\n\t\t}\n\t\tconst cmpStart = this.compareKeys(_start, node.key);\n\t\tconst cmpEnd = this.compareKeys(_end, node.key);\n\t\tlet go = true;\n\t\tif (cmpStart < 0) {\n\t\t\tgo = this.nodeMap(node.left, action, accum, _start, _end);\n\t\t}\n\t\tif (go && cmpStart <= 0 && cmpEnd >= 0) {\n\t\t\t// REVIEW: test for black node here\n\t\t\tgo = action(node, accum);\n\t\t}\n\t\tif (go && cmpEnd > 0) {\n\t\t\tgo = this.nodeMap(node.right, action, accum, _start, _end);\n\t\t}\n\t\treturn go;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endOfTreeSegment.d.ts","sourceRoot":"","sources":["../src/endOfTreeSegment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAgB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uBAAe,mBACd,YAAW,cAAc,EAAE,eAAe,EAAE,iBAAiB;IAEjD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;gBAApB,SAAS,EAAE,SAAS;IAOnD,OAAO;;;;QAAqE;IAC5E,WAAW,EAAE,SAAS,CAAC;IACvB,eAAe,EAAE,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS,CAAC;IACtB,YAAY,SAAK;IAEjB,MAAM;;;;MAAgE;IAEtE,MAAM,IAAI,IAAI,IAAI,QAAQ;IAI1B,SAAS,CAAC,QAAQ,CAAC,oBAAoB,IAAI;QAC1C,MAAM,EAAE,UAAU,CAAC;QACnB,KAAK,EAAE,MAA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AM,CAElB;IAED,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC;IAE/B,SAAS,CAAC,EAAE,wBAAwB,CAAC;IAMrC,IAAI,aAAa,IAAI,KAAK,CAEzB;IACD,IAAI,kBAAkB,IAAI,KAAK,CAE9B;IACD,aAAa,QASW,KAAK,CATA;IAC7B,KAAK,QAQmB,KAAK,CARR;IACrB,SAAS,QAOe,KAAK,CAPJ;IACzB,MAAM,QAMkB,KAAK,CANP;IACtB,OAAO,QAKiB,KAAK,CALN;IACvB,YAAY,QAIY,KAAK,CAJD;IAC5B,GAAG,QAGqB,KAAK,CAHV;CACnB;AAMD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,mBAAoB,YAAW,QAAQ;IAC9E,IAAI,EAAE,MAAM,CAAwB;IACpC,QAAQ,CAAC,YAAY,WAAW;IAEhC;;;OAGG;IACH,SAAS,CAAC,oBAAoB,IAAI;QACjC,MAAM,EAAE,UAAU,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd;IA2BD,IAAI,OAAO,IAAI,MAAM,CAKpB;CACD;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,mBAAoB,YAAW,QAAQ;IAC5E,IAAI,EAAE,MAAM,CAAsB;IAClC,QAAQ,CAAC,YAAY,SAAS;IAE9B;;;OAGG;IACH,SAAS,CAAC,oBAAoB,IAAI;QACjC,MAAM,EAAE,UAAU,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd;IA2BD,IAAI,OAAO,IAAI,MAAM,CAMpB;CACD"}
|
package/dist/endOfTreeSegment.js
CHANGED
|
@@ -30,25 +30,22 @@ const mergeTreeNodeWalk_js_1 = require("./mergeTreeNodeWalk.js");
|
|
|
30
30
|
* respectively. The endpoint segments allow us to support such behavior.
|
|
31
31
|
*/
|
|
32
32
|
class BaseEndpointSegment {
|
|
33
|
+
mergeTree;
|
|
33
34
|
constructor(mergeTree) {
|
|
34
35
|
this.mergeTree = mergeTree;
|
|
35
|
-
/*
|
|
36
|
-
* segments must be of at least length one, but
|
|
37
|
-
* removed segments will have a calculated length
|
|
38
|
-
* of undefined/0. we leverage this to create
|
|
39
|
-
* a 0 length segment for an endpoint of the tree
|
|
40
|
-
*/
|
|
41
|
-
this.removes = [{ type: "setRemove", seq: 0, clientId: constants_js_1.LocalClientId }];
|
|
42
|
-
this.cachedLength = 1;
|
|
43
|
-
this.insert = { type: "insert", seq: 0, clientId: constants_js_1.LocalClientId };
|
|
44
|
-
this.addProperties = notSupported;
|
|
45
|
-
this.clone = notSupported;
|
|
46
|
-
this.canAppend = notSupported;
|
|
47
|
-
this.append = notSupported;
|
|
48
|
-
this.splitAt = notSupported;
|
|
49
|
-
this.toJSONObject = notSupported;
|
|
50
|
-
this.ack = notSupported;
|
|
51
36
|
}
|
|
37
|
+
/*
|
|
38
|
+
* segments must be of at least length one, but
|
|
39
|
+
* removed segments will have a calculated length
|
|
40
|
+
* of undefined/0. we leverage this to create
|
|
41
|
+
* a 0 length segment for an endpoint of the tree
|
|
42
|
+
*/
|
|
43
|
+
removes = [{ type: "setRemove", seq: 0, clientId: constants_js_1.LocalClientId }];
|
|
44
|
+
attribution;
|
|
45
|
+
propertyManager;
|
|
46
|
+
properties;
|
|
47
|
+
cachedLength = 1;
|
|
48
|
+
insert = { type: "insert", seq: 0, clientId: constants_js_1.LocalClientId };
|
|
52
49
|
isLeaf() {
|
|
53
50
|
return true;
|
|
54
51
|
}
|
|
@@ -58,6 +55,7 @@ class BaseEndpointSegment {
|
|
|
58
55
|
get index() {
|
|
59
56
|
return this.endpointSegmentProps().index;
|
|
60
57
|
}
|
|
58
|
+
localRefs;
|
|
61
59
|
/*
|
|
62
60
|
* since this segment isn't real, throw on any segment
|
|
63
61
|
* operation that isn't expected
|
|
@@ -68,6 +66,13 @@ class BaseEndpointSegment {
|
|
|
68
66
|
get trackingCollection() {
|
|
69
67
|
return notSupported();
|
|
70
68
|
}
|
|
69
|
+
addProperties = notSupported;
|
|
70
|
+
clone = notSupported;
|
|
71
|
+
canAppend = notSupported;
|
|
72
|
+
append = notSupported;
|
|
73
|
+
splitAt = notSupported;
|
|
74
|
+
toJSONObject = notSupported;
|
|
75
|
+
ack = notSupported;
|
|
71
76
|
}
|
|
72
77
|
const notSupported = () => {
|
|
73
78
|
(0, internal_1.fail)(0x3ed /* operation not supported */);
|
|
@@ -76,11 +81,8 @@ const notSupported = () => {
|
|
|
76
81
|
* The position immediately prior to the start of the tree
|
|
77
82
|
*/
|
|
78
83
|
class StartOfTreeSegment extends BaseEndpointSegment {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.type = "StartOfTreeSegment";
|
|
82
|
-
this.endpointType = "start";
|
|
83
|
-
}
|
|
84
|
+
type = "StartOfTreeSegment";
|
|
85
|
+
endpointType = "start";
|
|
84
86
|
/**
|
|
85
87
|
* this segment pretends to be a sibling of the first real segment.
|
|
86
88
|
* so compute the necessary properties to pretend to be that segment.
|
|
@@ -116,11 +118,8 @@ exports.StartOfTreeSegment = StartOfTreeSegment;
|
|
|
116
118
|
* The position immediately after the end of the tree
|
|
117
119
|
*/
|
|
118
120
|
class EndOfTreeSegment extends BaseEndpointSegment {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.type = "EndOfTreeSegment";
|
|
122
|
-
this.endpointType = "end";
|
|
123
|
-
}
|
|
121
|
+
type = "EndOfTreeSegment";
|
|
122
|
+
endpointType = "end";
|
|
124
123
|
/**
|
|
125
124
|
* this segment pretends to be a sibling of the last real segment.
|
|
126
125
|
* so compute the necessary properties to pretend to be that segment.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endOfTreeSegment.js","sourceRoot":"","sources":["../src/endOfTreeSegment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAE3D,iDAA+C;AAG/C,iEAAwE;AAIxE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAe,mBAA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,yCAAkB,EACjB,IAAI,EACJ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,EAClC,CAAC,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,CAAC;YACR,IAAI,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;gBACpB,WAAW,GAAG,IAAI,CAAC;gBACnB,OAAO,iCAAU,CAAC,IAAI,CAAC;YACxB,CAAC;QACF,CAAC,EACD,SAAS,EACT,SAAS,EACT,KAAK,CACL,CAAC;QACF,MAAM,MAAM,GAAG,WAAW,EAAE,MAAM,IAAI,IAAI,CAAC;QAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,OAAO;YACN,MAAM;YACN,KAAK;YACL,KAAK;SACL,CAAC;IACH,CAAC;IAED,IAAI,OAAO;QACV,0CAA0C;QAC1C,sCAAsC;QACtC,8CAA8C;QAC9C,kDAAkD;QAClD,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;CACD;AA9CD,4CA8CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\n\nimport { LocalClientId } from \"./constants.js\";\nimport type { LocalReferenceCollection } from \"./localReference.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport { NodeAction, depthFirstNodeWalk } from \"./mergeTreeNodeWalk.js\";\nimport type { ISegment, ISegmentLeaf, MergeBlock } from \"./mergeTreeNodes.js\";\nimport type { IHasInsertionInfo, IHasRemovalInfo, IMergeNodeInfo } from \"./segmentInfos.js\";\n\n/**\n * This is a special segment that is not bound or known by the merge tree itself,\n * but the segment itself pretends to be a removed segment at an endpoint of the\n * tree. It is removed so it appears as a undefined/0 length segment. This segment\n * adds the capability to hold local references that have been detached from the\n * real merge tree, and give the appearance that they exist at an endpoint of the\n * tree.\n *\n * This is useful today in 2 cases: detached references and interval stickiness.\n *\n * In general, local references only become detached when the tree becomes empty\n * and the EndOfTreeSegment allows us to gracefully handle that case by giving\n * those references a place to live.\n *\n * In the case of interval stickiness, it is desirable to be able to refer to\n * the position immediately after or before a segment, in order for the endpoint\n * of an interval to be exclusive. This means that in order to support intervals\n * that are exclusive and also include the first or last segment of the tree, it\n * must be possible in some way to refer to a position before or after the tree\n * respectively. The endpoint segments allow us to support such behavior.\n */\nabstract class BaseEndpointSegment\n\timplements IMergeNodeInfo, IHasRemovalInfo, IHasInsertionInfo\n{\n\tconstructor(protected readonly mergeTree: MergeTree) {}\n\t/*\n\t * segments must be of at least length one, but\n\t * removed segments will have a calculated length\n\t * of undefined/0. we leverage this to create\n\t * a 0 length segment for an endpoint of the tree\n\t */\n\tremoves = [{ type: \"setRemove\", seq: 0, clientId: LocalClientId } as const];\n\tattribution: undefined;\n\tpropertyManager: undefined;\n\tproperties: undefined;\n\tcachedLength = 1;\n\n\tinsert = { type: \"insert\", seq: 0, clientId: LocalClientId } as const;\n\n\tisLeaf(): this is ISegment {\n\t\treturn true;\n\t}\n\n\tprotected abstract endpointSegmentProps(): {\n\t\tparent: MergeBlock;\n\t\tindex: number;\n\t\tdepth: number;\n\t};\n\n\tget parent(): MergeBlock {\n\t\treturn this.endpointSegmentProps().parent;\n\t}\n\n\tget index(): number {\n\t\treturn this.endpointSegmentProps().index;\n\t}\n\n\tabstract get ordinal(): string;\n\n\tlocalRefs?: LocalReferenceCollection;\n\n\t/*\n\t * since this segment isn't real, throw on any segment\n\t * operation that isn't expected\n\t */\n\tget segmentGroups(): never {\n\t\treturn notSupported();\n\t}\n\tget trackingCollection(): never {\n\t\treturn notSupported();\n\t}\n\taddProperties = notSupported;\n\tclone = notSupported;\n\tcanAppend = notSupported;\n\tappend = notSupported;\n\tsplitAt = notSupported;\n\ttoJSONObject = notSupported;\n\tack = notSupported;\n}\n\nconst notSupported = (): never => {\n\tfail(0x3ed /* operation not supported */);\n};\n\n/**\n * The position immediately prior to the start of the tree\n */\nexport class StartOfTreeSegment extends BaseEndpointSegment implements ISegment {\n\ttype: string = \"StartOfTreeSegment\";\n\treadonly endpointType = \"start\";\n\n\t/**\n\t * this segment pretends to be a sibling of the first real segment.\n\t * so compute the necessary properties to pretend to be that segment.\n\t */\n\tprotected endpointSegmentProps(): {\n\t\tparent: MergeBlock;\n\t\tindex: number;\n\t\tdepth: number;\n\t} {\n\t\tlet firstSegment: ISegmentLeaf | undefined;\n\t\tlet depth = 1;\n\t\tconst root = this.mergeTree.root;\n\t\tdepthFirstNodeWalk(\n\t\t\troot,\n\t\t\troot.children[0],\n\t\t\t(node) => {\n\t\t\t\tdepth++;\n\t\t\t\tif (node?.isLeaf()) {\n\t\t\t\t\tfirstSegment = node;\n\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t);\n\t\tconst parent = firstSegment?.parent ?? root;\n\t\tconst index = 0;\n\t\treturn {\n\t\t\tparent,\n\t\t\tindex,\n\t\t\tdepth,\n\t\t};\n\t}\n\n\tget ordinal(): string {\n\t\t// Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.\n\t\t// The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.\n\t\t// eslint-disable-next-line unicorn/prefer-code-point\n\t\treturn String.fromCharCode(0x00);\n\t}\n}\n\n/**\n * The position immediately after the end of the tree\n */\nexport class EndOfTreeSegment extends BaseEndpointSegment implements ISegment {\n\ttype: string = \"EndOfTreeSegment\";\n\treadonly endpointType = \"end\";\n\n\t/**\n\t * this segment pretends to be a sibling of the last real segment.\n\t * so compute the necessary properties to pretend to be that segment.\n\t */\n\tprotected endpointSegmentProps(): {\n\t\tparent: MergeBlock;\n\t\tindex: number;\n\t\tdepth: number;\n\t} {\n\t\tlet lastSegment: ISegmentLeaf | undefined;\n\t\tlet depth = 1;\n\t\tconst root = this.mergeTree.root;\n\t\tdepthFirstNodeWalk(\n\t\t\troot,\n\t\t\troot.children[root.childCount - 1],\n\t\t\t(node) => {\n\t\t\t\tdepth++;\n\t\t\t\tif (node?.isLeaf()) {\n\t\t\t\t\tlastSegment = node;\n\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t);\n\t\tconst parent = lastSegment?.parent ?? root;\n\t\tconst index = parent.childCount;\n\t\treturn {\n\t\t\tparent,\n\t\t\tindex,\n\t\t\tdepth,\n\t\t};\n\t}\n\n\tget ordinal(): string {\n\t\t// just compute an arbitrarily big ordinal\n\t\t// we base it on the depth of the tree\n\t\t// to ensure it is bigger than all ordinals in\n\t\t// the tree, as each layer appends to the previous\n\t\treturn String.fromCodePoint(0xffff).repeat(this.endpointSegmentProps().depth);\n\t}\n}\n"]}
|
package/dist/localReference.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.LocalReferenceCollection = exports.
|
|
7
|
+
exports.LocalReferenceCollection = exports.SlidingPreference = void 0;
|
|
8
|
+
exports.createDetachedLocalReferencePosition = createDetachedLocalReferencePosition;
|
|
9
|
+
exports.anyLocalReferencePosition = anyLocalReferencePosition;
|
|
10
|
+
exports.filterLocalReferencePositions = filterLocalReferencePositions;
|
|
11
|
+
exports.setValidateRefCount = setValidateRefCount;
|
|
8
12
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
13
|
const internal_2 = require("@fluidframework/telemetry-utils/internal");
|
|
10
14
|
const mergeTreeTracking_js_1 = require("./mergeTreeTracking.js");
|
|
@@ -46,6 +50,15 @@ function _validateReferenceType(refType) {
|
|
|
46
50
|
* @internal
|
|
47
51
|
*/
|
|
48
52
|
class LocalReference {
|
|
53
|
+
refType;
|
|
54
|
+
slidingPreference;
|
|
55
|
+
canSlideToEndpoint;
|
|
56
|
+
properties;
|
|
57
|
+
segment;
|
|
58
|
+
offset = 0;
|
|
59
|
+
listNode;
|
|
60
|
+
callbacks;
|
|
61
|
+
_trackingCollection;
|
|
49
62
|
get trackingCollection() {
|
|
50
63
|
return (this._trackingCollection ??= new mergeTreeTracking_js_1.TrackingGroupCollection(this));
|
|
51
64
|
}
|
|
@@ -53,7 +66,6 @@ class LocalReference {
|
|
|
53
66
|
this.refType = refType;
|
|
54
67
|
this.slidingPreference = slidingPreference;
|
|
55
68
|
this.canSlideToEndpoint = canSlideToEndpoint;
|
|
56
|
-
this.offset = 0;
|
|
57
69
|
_validateReferenceType(refType);
|
|
58
70
|
this.properties = properties;
|
|
59
71
|
}
|
|
@@ -100,7 +112,6 @@ class LocalReference {
|
|
|
100
112
|
function createDetachedLocalReferencePosition(slidingPreference, refType) {
|
|
101
113
|
return new LocalReference(refType, undefined, slidingPreference);
|
|
102
114
|
}
|
|
103
|
-
exports.createDetachedLocalReferencePosition = createDetachedLocalReferencePosition;
|
|
104
115
|
function assertLocalReferences(lref) {
|
|
105
116
|
(0, internal_1.assert)(lref instanceof LocalReference, 0x2e0 /* "lref not a Local Reference" */);
|
|
106
117
|
}
|
|
@@ -115,7 +126,6 @@ function anyLocalReferencePosition(collection, func) {
|
|
|
115
126
|
}
|
|
116
127
|
return false;
|
|
117
128
|
}
|
|
118
|
-
exports.anyLocalReferencePosition = anyLocalReferencePosition;
|
|
119
129
|
/**
|
|
120
130
|
* Finds the local reference positions that satisfy the given predicate.
|
|
121
131
|
*/
|
|
@@ -126,7 +136,6 @@ function* filterLocalReferencePositions(collection, predicate) {
|
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
|
-
exports.filterLocalReferencePositions = filterLocalReferencePositions;
|
|
130
139
|
/**
|
|
131
140
|
* Injectable hook for validating that the refCount property matches the
|
|
132
141
|
* expected value
|
|
@@ -135,7 +144,6 @@ let validateRefCount;
|
|
|
135
144
|
function setValidateRefCount(cb) {
|
|
136
145
|
validateRefCount = cb;
|
|
137
146
|
}
|
|
138
|
-
exports.setValidateRefCount = setValidateRefCount;
|
|
139
147
|
/**
|
|
140
148
|
* Represents a collection of {@link LocalReferencePosition}s associated with
|
|
141
149
|
* one segment in a merge-tree.
|
|
@@ -145,6 +153,7 @@ exports.setValidateRefCount = setValidateRefCount;
|
|
|
145
153
|
* @internal
|
|
146
154
|
*/
|
|
147
155
|
class LocalReferenceCollection {
|
|
156
|
+
segment;
|
|
148
157
|
static append(seg1, seg2) {
|
|
149
158
|
if (seg2.localRefs && !seg2.localRefs.empty) {
|
|
150
159
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
@@ -165,6 +174,8 @@ class LocalReferenceCollection {
|
|
|
165
174
|
static setOrGet(segment) {
|
|
166
175
|
return (segment.localRefs ??= new LocalReferenceCollection(segment));
|
|
167
176
|
}
|
|
177
|
+
refsByOffset;
|
|
178
|
+
refCount = 0;
|
|
168
179
|
constructor(
|
|
169
180
|
/**
|
|
170
181
|
* The segment this `LocalReferenceCollection` is associated with.
|
|
@@ -173,7 +184,6 @@ class LocalReferenceCollection {
|
|
|
173
184
|
length: segment.cachedLength,
|
|
174
185
|
})) {
|
|
175
186
|
this.segment = segment;
|
|
176
|
-
this.refCount = 0;
|
|
177
187
|
// Since javascript arrays are sparse the above won't populate any of the
|
|
178
188
|
// indices, but it will ensure the length property of the array matches
|
|
179
189
|
// the length of the segment.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAK6C;AAC7C,uEAAsE;AAGtE,iEAAqF;AACrF,qCAAyC;AACzC,mDAAkE;AAClE,mEAAsF;AAEtF;;;;GAIG;AACU,QAAA,iBAAiB,GAAG;IAChC;;OAEG;IACH,QAAQ,EA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C,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;gBAC5E,IAAI,SAAS,EAAE,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC3E,OAAO,KAAK,CAAC;gBACd,CAAC;YACF,CAAC;YACD,MAAM,IAAI,SAAS,CAAC;YACpB,eAAe,CAAC,IAAI,CACnB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,EAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK,CAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA/YD,4DA+YC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\ttype ListNode,\n\twalkList,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ISegmentInternal } from \"./mergeTreeNodes.js\";\nimport { type TrackingGroup, TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { ReferenceType } from \"./ops.js\";\nimport { type PropertySet, addProperties } from \"./properties.js\";\nimport { type ReferencePosition, refTypeIncludesFlag } from \"./referencePositions.js\";\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy @beta\n */\nexport const SlidingPreference = {\n\t/**\n\t * Prefer sliding towards the start of the tree\n\t */\n\tBACKWARD: 0,\n\t/**\n\t * Prefer sliding towards the end of the tree\n\t */\n\tFORWARD: 1,\n} as const;\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy @beta\n */\nexport type SlidingPreference = (typeof SlidingPreference)[keyof typeof SlidingPreference];\n\nfunction _validateReferenceType(refType: ReferenceType): void {\n\tlet exclusiveCount = 0;\n\tif (refTypeIncludesFlag(refType, ReferenceType.Transient)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.SlideOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.StayOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (exclusiveCount > 1) {\n\t\tthrow new UsageError(\n\t\t\t\"Reference types can only be one of Transient, SlideOnRemove, and StayOnRemove\",\n\t\t);\n\t}\n}\n/**\n * @sealed\n * @legacy @beta\n */\nexport interface LocalReferencePosition extends ReferencePosition {\n\tcallbacks?: Partial<\n\t\tRecord<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>\n\t>;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this reference position can slide onto one of the two\n\t * special segments representing the position before or after the tree\n\t */\n\treadonly canSlideToEndpoint?: boolean;\n\n\t/**\n\t * @param newProps - Properties to add to this reference.\n\t * @remarks Note that merge-tree does not broadcast changes to other clients. It is up to the consumer\n\t * to ensure broadcast happens if that is desired.\n\t */\n\taddProperties(newProps: PropertySet): void;\n}\n\n/**\n * @privateRemarks This should not be exported outside merge tree.\n * @internal\n */\nclass LocalReference implements LocalReferencePosition {\n\tpublic properties: PropertySet | undefined;\n\n\tprivate segment: ISegmentInternal | undefined;\n\tprivate offset: number = 0;\n\tprivate listNode: ListNode<LocalReference> | undefined;\n\n\tpublic callbacks?:\n\t\t| Partial<Record<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>>\n\t\t| undefined;\n\tprivate _trackingCollection?: TrackingGroupCollection;\n\tpublic get trackingCollection(): TrackingGroupCollection {\n\t\treturn (this._trackingCollection ??= new TrackingGroupCollection(this));\n\t}\n\n\tconstructor(\n\t\tpublic refType = ReferenceType.Simple,\n\t\tproperties?: PropertySet,\n\t\tpublic readonly slidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\t\tpublic readonly canSlideToEndpoint?: boolean,\n\t) {\n\t\t_validateReferenceType(refType);\n\t\tthis.properties = properties;\n\t}\n\n\tpublic link(\n\t\tsegment: ISegmentInternal | undefined,\n\t\toffset: number,\n\t\tlistNode: ListNode<LocalReference> | undefined,\n\t): void {\n\t\tif (listNode !== this.listNode && this.listNode !== undefined) {\n\t\t\tthis.segment?.localRefs?.removeLocalRef(this);\n\t\t}\n\t\tthis.listNode = listNode;\n\n\t\tif (segment !== this.segment) {\n\t\t\tconst groups: TrackingGroup[] = [];\n\t\t\tfor (const tg of this.trackingCollection.trackingGroups) {\n\t\t\t\ttg.unlink(this);\n\t\t\t\tgroups.push(tg);\n\t\t\t}\n\n\t\t\tthis.segment = segment;\n\n\t\t\tfor (const tg of groups) tg.link(this);\n\t\t}\n\t\tthis.offset = offset;\n\t}\n\n\tpublic isLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\tpublic addProperties(newProps: PropertySet): void {\n\t\tthis.properties = addProperties(this.properties, newProps);\n\t}\n\n\tpublic getSegment(): ISegmentInternal | undefined {\n\t\treturn this.segment;\n\t}\n\n\tpublic getOffset(): number {\n\t\treturn this.offset;\n\t}\n\n\tpublic getListNode(): ListNode<LocalReference> | undefined {\n\t\treturn this.listNode;\n\t}\n\n\tpublic getProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n}\n\n/**\n * Creates a new detached local reference.\n * @internal\n */\nexport function createDetachedLocalReferencePosition(\n\tslidingPreference: SlidingPreference | undefined,\n\trefType?: ReferenceType,\n): LocalReferencePosition {\n\treturn new LocalReference(refType, undefined, slidingPreference);\n}\n\ninterface IRefsAtOffset {\n\tbefore?: DoublyLinkedList<LocalReference>;\n\tat?: DoublyLinkedList<LocalReference>;\n\tafter?: DoublyLinkedList<LocalReference>;\n}\n\nfunction assertLocalReferences(lref: unknown): asserts lref is LocalReference {\n\tassert(lref instanceof LocalReference, 0x2e0 /* \"lref not a Local Reference\" */);\n}\n\n/**\n * Determines if the given function is true for any position within the collection.\n */\nexport function anyLocalReferencePosition(\n\tcollection: LocalReferenceCollection,\n\tfunc: (pos: LocalReferencePosition) => boolean,\n): boolean {\n\tfor (const pos of collection) {\n\t\tif (func(pos)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Finds the local reference positions that satisfy the given predicate.\n */\nexport function* filterLocalReferencePositions(\n\tcollection: LocalReferenceCollection,\n\tpredicate: (pos: LocalReferencePosition) => boolean,\n): Generator<LocalReferencePosition> {\n\tfor (const pos of collection) {\n\t\tif (predicate(pos)) {\n\t\t\tyield pos;\n\t\t}\n\t}\n}\n\n/**\n * Injectable hook for validating that the refCount property matches the\n * expected value\n */\nlet validateRefCount: ((collection?: LocalReferenceCollection) => void) | undefined;\n\nexport function setValidateRefCount(\n\tcb?: (collection?: LocalReferenceCollection) => void,\n): void {\n\tvalidateRefCount = cb;\n}\n\n/**\n * Represents a collection of {@link LocalReferencePosition}s associated with\n * one segment in a merge-tree.\n * Represents a collection of {@link LocalReferencePosition}s associated with one segment in a merge-tree.\n * @sealed\n *\n * @internal\n */\nexport class LocalReferenceCollection {\n\tpublic static append(seg1: ISegmentInternal, seg2: ISegmentInternal): void {\n\t\tif (seg2.localRefs && !seg2.localRefs.empty) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\tif (!seg1.localRefs) {\n\t\t\t\tseg1.localRefs = new LocalReferenceCollection(seg1);\n\t\t\t}\n\t\t\tassert(\n\t\t\t\tseg1.localRefs.refsByOffset.length === seg1.cachedLength,\n\t\t\t\t0x2be /* \"LocalReferences array contains a gap\" */,\n\t\t\t);\n\t\t\tseg1.localRefs.append(seg2.localRefs);\n\t\t} else if (seg1.localRefs) {\n\t\t\t// Since creating the LocalReferenceCollection, we may have appended\n\t\t\t// segments that had no local references. Account for them now by padding the array.\n\t\t\tseg1.localRefs.refsByOffset.length += seg2.cachedLength;\n\t\t}\n\t\tvalidateRefCount?.(seg1.localRefs);\n\t\tvalidateRefCount?.(seg2.localRefs);\n\t}\n\n\tpublic static setOrGet(segment: ISegmentInternal): LocalReferenceCollection {\n\t\treturn (segment.localRefs ??= new LocalReferenceCollection(segment));\n\t}\n\n\tprivate readonly refsByOffset: (IRefsAtOffset | undefined)[];\n\tprivate refCount: number = 0;\n\n\tprivate constructor(\n\t\t/**\n\t\t * The segment this `LocalReferenceCollection` is associated with.\n\t\t */\n\t\tprivate readonly segment: ISegmentInternal,\n\t\tinitialRefsByfOffset: (IRefsAtOffset | undefined)[] = Array.from({\n\t\t\tlength: segment.cachedLength,\n\t\t}),\n\t) {\n\t\t// Since javascript arrays are sparse the above won't populate any of the\n\t\t// indices, but it will ensure the length property of the array matches\n\t\t// the length of the segment.\n\t\tthis.refsByOffset = initialRefsByfOffset;\n\t}\n\n\t/**\n\t * Returns an iterator over this LocalReferenceCollection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic [Symbol.iterator](): {\n\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t} {\n\t\tconst subiterators: IterableIterator<ListNode<LocalReferencePosition>>[] = [];\n\t\tfor (const refs of this.refsByOffset) {\n\t\t\tif (refs) {\n\t\t\t\tif (refs.before) {\n\t\t\t\t\tsubiterators.push(refs.before[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.at) {\n\t\t\t\t\tsubiterators.push(refs.at[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.after) {\n\t\t\t\t\tsubiterators.push(refs.after[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<LocalReferencePosition> {\n\t\t\t\twhile (subiterators.length > 0) {\n\t\t\t\t\tconst next = subiterators[0].next();\n\t\t\t\t\tif (next.done === true) {\n\t\t\t\t\t\tsubiterators.shift();\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { done: next.done, value: next.value.data };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { value: undefined, done: true };\n\t\t\t},\n\t\t\t[Symbol.iterator](): {\n\t\t\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t\t\t} {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Determines if the collection has no references in it.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic get empty(): boolean {\n\t\tvalidateRefCount?.(this);\n\t\treturn this.refCount === 0;\n\t}\n\n\t/**\n\t * Creates a new local reference.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic createLocalRef(\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\tconst ref = new LocalReference(refType, properties, slidingPreference, canSlideToEndpoint);\n\t\tref.link(this.segment, offset, undefined);\n\t\tif (!refTypeIncludesFlag(ref, ReferenceType.Transient)) {\n\t\t\tthis.addLocalRef(ref, offset);\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t\treturn ref;\n\t}\n\n\t/**\n\t * Adds a local reference to the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addLocalRef(lref: LocalReferencePosition, offset: number): void {\n\t\tassertLocalReferences(lref);\n\t\tassert(\n\t\t\toffset < this.segment.cachedLength,\n\t\t\t0x348 /* offset cannot be beyond segment length */,\n\t\t);\n\t\tif (refTypeIncludesFlag(lref, ReferenceType.Transient)) {\n\t\t\tlref.link(this.segment, offset, undefined);\n\t\t} else {\n\t\t\tconst refsAtOffset = (this.refsByOffset[offset] = this.refsByOffset[offset] ?? {\n\t\t\t\tat: new DoublyLinkedList(),\n\t\t\t});\n\t\t\tconst atRefs = (refsAtOffset.at = refsAtOffset.at ?? new DoublyLinkedList());\n\n\t\t\tlref.link(this.segment, offset, atRefs.push(lref).last);\n\n\t\t\tthis.refCount++;\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Removes a local reference from the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic removeLocalRef(lref: LocalReferencePosition): LocalReferencePosition | undefined {\n\t\tif (this.has(lref)) {\n\t\t\tassertLocalReferences(lref);\n\n\t\t\tconst node = lref.getListNode();\n\t\t\tnode?.list?.remove(node);\n\n\t\t\tlref.link(undefined, 0, undefined);\n\n\t\t\tthis.refCount--;\n\t\t\tvalidateRefCount?.(this);\n\t\t\treturn lref;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n\t * end of 'this' segment.\n\t *\n\t * Note: This method should be invoked after the caller has ensured that segments can be merged,\n\t * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n\t * will be incorrect.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic append(other: LocalReferenceCollection): void {\n\t\tif (!other || other.empty) {\n\t\t\treturn;\n\t\t}\n\t\tthis.refCount += other.refCount;\n\t\tother.refCount = 0;\n\t\tfor (const lref of other) {\n\t\t\tassertLocalReferences(lref);\n\t\t\tlref.link(this.segment, lref.getOffset() + this.refsByOffset.length, lref.getListNode());\n\t\t}\n\n\t\tthis.refsByOffset.push(...other.refsByOffset);\n\t\tother.refsByOffset.length = 0;\n\t}\n\t/**\n\t * Returns true of the local reference is in the collection, otherwise false.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic has(lref: ReferencePosition): boolean {\n\t\tif (\n\t\t\t!(lref instanceof LocalReference) ||\n\t\t\trefTypeIncludesFlag(lref, ReferenceType.Transient)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst seg = lref.getSegment();\n\t\tif (seg !== this.segment) {\n\t\t\treturn false;\n\t\t}\n\t\t// we should be able to optimize finding the\n\t\t// list head\n\t\tconst listNode = lref.getListNode();\n\t\tif (listNode === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tconst offset = lref.getOffset();\n\t\tconst refsAtOffset = this.refsByOffset[offset];\n\t\tif (\n\t\t\t!!refsAtOffset?.before?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.at?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.after?.includes(listNode)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n\t * Local references in the former half of this split will remain associated with the segment used on construction.\n\t * Local references in the latter half of this split will be transferred to `splitSeg`,\n\t * and its `localRefs` field will be set.\n\t * @param offset - Offset into the original segment at which the collection should be split\n\t * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n\t * before splitting.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic split(offset: number, splitSeg: ISegmentInternal): void {\n\t\tif (this.empty) {\n\t\t\t// shrink the offset array when empty and splitting\n\t\t\tthis.refsByOffset.length = offset;\n\t\t} else {\n\t\t\tconst localRefs = new LocalReferenceCollection(\n\t\t\t\tsplitSeg,\n\t\t\t\tthis.refsByOffset.splice(offset, this.refsByOffset.length - offset),\n\t\t\t);\n\n\t\t\tsplitSeg.localRefs = localRefs;\n\t\t\tfor (const lref of localRefs) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tlref.link(splitSeg, lref.getOffset() - offset, lref.getListNode());\n\t\t\t\tthis.refCount--;\n\t\t\t\tlocalRefs.refCount++;\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Insert a reference before tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addBeforeTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst beforeRefs = this.refsByOffset[0]?.before ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[0]?.before === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[0] ??= { before: beforeRefs });\n\t\t\trefsAtOffset.before ??= beforeRefs;\n\t\t}\n\n\t\tlet precedingRef: ListNode<LocalReference> | undefined;\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tprecedingRef =\n\t\t\t\t\t\tprecedingRef === undefined\n\t\t\t\t\t\t\t? beforeRefs.unshift(lref)?.first\n\t\t\t\t\t\t\t: beforeRefs.insertAfter(precedingRef, lref)?.first;\n\t\t\t\t\tlref.link(this.segment, 0, precedingRef);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\t/**\n\t * Insert a reference after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addAfterTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst lastOffset = this.segment.cachedLength - 1;\n\t\tconst afterRefs = this.refsByOffset[lastOffset]?.after ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[lastOffset]?.after === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[lastOffset] ??= { after: afterRefs });\n\t\t\trefsAtOffset.after ??= afterRefs;\n\t\t}\n\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tafterRefs.push(lref);\n\t\t\t\t\tlref.link(this.segment, lastOffset, afterRefs.last);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Determines if a reference is after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic isAfterTombstone(lref: LocalReferencePosition): boolean {\n\t\tconst after = this.refsByOffset[lref.getOffset()]?.after;\n\t\tif (after) {\n\t\t\tassertLocalReferences(lref);\n\t\t\treturn after.includes(lref.getListNode());\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Walks all of the references in a collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic walkReferences(\n\t\tvisitor: (lref: LocalReferencePosition) => boolean | void | undefined,\n\t\tstart?: LocalReferencePosition,\n\t\tforward: boolean = true,\n\t): boolean {\n\t\tif (start !== undefined) {\n\t\t\tif (!this.has(start)) {\n\t\t\t\tthrow new UsageError(\"start must be in collection\");\n\t\t\t}\n\t\t\tassertLocalReferences(start);\n\t\t}\n\t\tlet offset = start?.getOffset() ?? (forward ? 0 : this.segment.cachedLength - 1);\n\n\t\tconst offsetPositions: DoublyLinkedList<IRefsAtOffset[keyof IRefsAtOffset]> =\n\t\t\tnew DoublyLinkedList();\n\t\toffsetPositions.push(\n\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\tthis.refsByOffset[offset]?.after,\n\t\t);\n\n\t\tconst startNode = start?.getListNode();\n\t\tconst startList = startNode?.list;\n\n\t\tif (startList !== undefined) {\n\t\t\t// Discard the buckets (before/at/after) which precede the bucket containing `start`,\n\t\t\t// so the walk begins at that bucket. `listWalker` then resumes mid-bucket at `startNode`.\n\t\t\tif (forward) {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.first?.data !== startList) {\n\t\t\t\t\toffsetPositions.shift();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.last?.data !== startList) {\n\t\t\t\t\toffsetPositions.pop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst listWalker = (pos: DoublyLinkedList<LocalReference>): boolean => {\n\t\t\treturn walkList(\n\t\t\t\tpos,\n\t\t\t\t(node) => visitor(node.data),\n\t\t\t\tstartList === pos ? startNode : undefined,\n\t\t\t\tforward,\n\t\t\t);\n\t\t};\n\t\tconst increment = forward ? 1 : -1;\n\t\twhile (offset >= 0 && offset < this.refsByOffset.length) {\n\t\t\twhile (offsetPositions.length > 0) {\n\t\t\t\tconst offsetPos = forward ? offsetPositions.shift() : offsetPositions.pop();\n\t\t\t\tif (offsetPos?.data !== undefined && listWalker(offsetPos.data) === false) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += increment;\n\t\t\toffsetPositions.push(\n\t\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\t\tthis.refsByOffset[offset]?.after,\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiKH,oFAKC;AAeD,8DAWC;AAKD,sEASC;AAQD,kDAIC;AAxND,kEAK6C;AAC7C,uEAAsE;AAGtE,iEAAqF;AACrF,qCAAyC;AACzC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AS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,OAAO,MAAM,IAAI,CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACzD,OAAO,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;gBAC5E,IAAI,SAAS,EAAE,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC3E,OAAO,KAAK,CAAC;gBACd,CAAC;YACF,CAAC;YACD,MAAM,IAAI,SAAS,CAAC;YACpB,eAAe,CAAC,IAAI,CACnB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,EAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK,CAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA/YD,4DA+YC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\ttype ListNode,\n\twalkList,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ISegmentInternal } from \"./mergeTreeNodes.js\";\nimport { type TrackingGroup, TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { ReferenceType } from \"./ops.js\";\nimport { type PropertySet, addProperties } from \"./properties.js\";\nimport { type ReferencePosition, refTypeIncludesFlag } from \"./referencePositions.js\";\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy @beta\n */\nexport const SlidingPreference = {\n\t/**\n\t * Prefer sliding towards the start of the tree\n\t */\n\tBACKWARD: 0,\n\t/**\n\t * Prefer sliding towards the end of the tree\n\t */\n\tFORWARD: 1,\n} as const;\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy @beta\n */\nexport type SlidingPreference = (typeof SlidingPreference)[keyof typeof SlidingPreference];\n\nfunction _validateReferenceType(refType: ReferenceType): void {\n\tlet exclusiveCount = 0;\n\tif (refTypeIncludesFlag(refType, ReferenceType.Transient)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.SlideOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.StayOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (exclusiveCount > 1) {\n\t\tthrow new UsageError(\n\t\t\t\"Reference types can only be one of Transient, SlideOnRemove, and StayOnRemove\",\n\t\t);\n\t}\n}\n/**\n * @sealed\n * @legacy @beta\n */\nexport interface LocalReferencePosition extends ReferencePosition {\n\tcallbacks?: Partial<\n\t\tRecord<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>\n\t>;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this reference position can slide onto one of the two\n\t * special segments representing the position before or after the tree\n\t */\n\treadonly canSlideToEndpoint?: boolean;\n\n\t/**\n\t * @param newProps - Properties to add to this reference.\n\t * @remarks Note that merge-tree does not broadcast changes to other clients. It is up to the consumer\n\t * to ensure broadcast happens if that is desired.\n\t */\n\taddProperties(newProps: PropertySet): void;\n}\n\n/**\n * @privateRemarks This should not be exported outside merge tree.\n * @internal\n */\nclass LocalReference implements LocalReferencePosition {\n\tpublic properties: PropertySet | undefined;\n\n\tprivate segment: ISegmentInternal | undefined;\n\tprivate offset: number = 0;\n\tprivate listNode: ListNode<LocalReference> | undefined;\n\n\tpublic callbacks?:\n\t\t| Partial<Record<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>>\n\t\t| undefined;\n\tprivate _trackingCollection?: TrackingGroupCollection;\n\tpublic get trackingCollection(): TrackingGroupCollection {\n\t\treturn (this._trackingCollection ??= new TrackingGroupCollection(this));\n\t}\n\n\tconstructor(\n\t\tpublic refType = ReferenceType.Simple,\n\t\tproperties?: PropertySet,\n\t\tpublic readonly slidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\t\tpublic readonly canSlideToEndpoint?: boolean,\n\t) {\n\t\t_validateReferenceType(refType);\n\t\tthis.properties = properties;\n\t}\n\n\tpublic link(\n\t\tsegment: ISegmentInternal | undefined,\n\t\toffset: number,\n\t\tlistNode: ListNode<LocalReference> | undefined,\n\t): void {\n\t\tif (listNode !== this.listNode && this.listNode !== undefined) {\n\t\t\tthis.segment?.localRefs?.removeLocalRef(this);\n\t\t}\n\t\tthis.listNode = listNode;\n\n\t\tif (segment !== this.segment) {\n\t\t\tconst groups: TrackingGroup[] = [];\n\t\t\tfor (const tg of this.trackingCollection.trackingGroups) {\n\t\t\t\ttg.unlink(this);\n\t\t\t\tgroups.push(tg);\n\t\t\t}\n\n\t\t\tthis.segment = segment;\n\n\t\t\tfor (const tg of groups) tg.link(this);\n\t\t}\n\t\tthis.offset = offset;\n\t}\n\n\tpublic isLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\tpublic addProperties(newProps: PropertySet): void {\n\t\tthis.properties = addProperties(this.properties, newProps);\n\t}\n\n\tpublic getSegment(): ISegmentInternal | undefined {\n\t\treturn this.segment;\n\t}\n\n\tpublic getOffset(): number {\n\t\treturn this.offset;\n\t}\n\n\tpublic getListNode(): ListNode<LocalReference> | undefined {\n\t\treturn this.listNode;\n\t}\n\n\tpublic getProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n}\n\n/**\n * Creates a new detached local reference.\n * @internal\n */\nexport function createDetachedLocalReferencePosition(\n\tslidingPreference: SlidingPreference | undefined,\n\trefType?: ReferenceType,\n): LocalReferencePosition {\n\treturn new LocalReference(refType, undefined, slidingPreference);\n}\n\ninterface IRefsAtOffset {\n\tbefore?: DoublyLinkedList<LocalReference>;\n\tat?: DoublyLinkedList<LocalReference>;\n\tafter?: DoublyLinkedList<LocalReference>;\n}\n\nfunction assertLocalReferences(lref: unknown): asserts lref is LocalReference {\n\tassert(lref instanceof LocalReference, 0x2e0 /* \"lref not a Local Reference\" */);\n}\n\n/**\n * Determines if the given function is true for any position within the collection.\n */\nexport function anyLocalReferencePosition(\n\tcollection: LocalReferenceCollection,\n\tfunc: (pos: LocalReferencePosition) => boolean,\n): boolean {\n\tfor (const pos of collection) {\n\t\tif (func(pos)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Finds the local reference positions that satisfy the given predicate.\n */\nexport function* filterLocalReferencePositions(\n\tcollection: LocalReferenceCollection,\n\tpredicate: (pos: LocalReferencePosition) => boolean,\n): Generator<LocalReferencePosition> {\n\tfor (const pos of collection) {\n\t\tif (predicate(pos)) {\n\t\t\tyield pos;\n\t\t}\n\t}\n}\n\n/**\n * Injectable hook for validating that the refCount property matches the\n * expected value\n */\nlet validateRefCount: ((collection?: LocalReferenceCollection) => void) | undefined;\n\nexport function setValidateRefCount(\n\tcb?: (collection?: LocalReferenceCollection) => void,\n): void {\n\tvalidateRefCount = cb;\n}\n\n/**\n * Represents a collection of {@link LocalReferencePosition}s associated with\n * one segment in a merge-tree.\n * Represents a collection of {@link LocalReferencePosition}s associated with one segment in a merge-tree.\n * @sealed\n *\n * @internal\n */\nexport class LocalReferenceCollection {\n\tpublic static append(seg1: ISegmentInternal, seg2: ISegmentInternal): void {\n\t\tif (seg2.localRefs && !seg2.localRefs.empty) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\tif (!seg1.localRefs) {\n\t\t\t\tseg1.localRefs = new LocalReferenceCollection(seg1);\n\t\t\t}\n\t\t\tassert(\n\t\t\t\tseg1.localRefs.refsByOffset.length === seg1.cachedLength,\n\t\t\t\t0x2be /* \"LocalReferences array contains a gap\" */,\n\t\t\t);\n\t\t\tseg1.localRefs.append(seg2.localRefs);\n\t\t} else if (seg1.localRefs) {\n\t\t\t// Since creating the LocalReferenceCollection, we may have appended\n\t\t\t// segments that had no local references. Account for them now by padding the array.\n\t\t\tseg1.localRefs.refsByOffset.length += seg2.cachedLength;\n\t\t}\n\t\tvalidateRefCount?.(seg1.localRefs);\n\t\tvalidateRefCount?.(seg2.localRefs);\n\t}\n\n\tpublic static setOrGet(segment: ISegmentInternal): LocalReferenceCollection {\n\t\treturn (segment.localRefs ??= new LocalReferenceCollection(segment));\n\t}\n\n\tprivate readonly refsByOffset: (IRefsAtOffset | undefined)[];\n\tprivate refCount: number = 0;\n\n\tprivate constructor(\n\t\t/**\n\t\t * The segment this `LocalReferenceCollection` is associated with.\n\t\t */\n\t\tprivate readonly segment: ISegmentInternal,\n\t\tinitialRefsByfOffset: (IRefsAtOffset | undefined)[] = Array.from({\n\t\t\tlength: segment.cachedLength,\n\t\t}),\n\t) {\n\t\t// Since javascript arrays are sparse the above won't populate any of the\n\t\t// indices, but it will ensure the length property of the array matches\n\t\t// the length of the segment.\n\t\tthis.refsByOffset = initialRefsByfOffset;\n\t}\n\n\t/**\n\t * Returns an iterator over this LocalReferenceCollection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic [Symbol.iterator](): {\n\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t} {\n\t\tconst subiterators: IterableIterator<ListNode<LocalReferencePosition>>[] = [];\n\t\tfor (const refs of this.refsByOffset) {\n\t\t\tif (refs) {\n\t\t\t\tif (refs.before) {\n\t\t\t\t\tsubiterators.push(refs.before[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.at) {\n\t\t\t\t\tsubiterators.push(refs.at[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.after) {\n\t\t\t\t\tsubiterators.push(refs.after[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<LocalReferencePosition> {\n\t\t\t\twhile (subiterators.length > 0) {\n\t\t\t\t\tconst next = subiterators[0].next();\n\t\t\t\t\tif (next.done === true) {\n\t\t\t\t\t\tsubiterators.shift();\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { done: next.done, value: next.value.data };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { value: undefined, done: true };\n\t\t\t},\n\t\t\t[Symbol.iterator](): {\n\t\t\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t\t\t} {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Determines if the collection has no references in it.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic get empty(): boolean {\n\t\tvalidateRefCount?.(this);\n\t\treturn this.refCount === 0;\n\t}\n\n\t/**\n\t * Creates a new local reference.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic createLocalRef(\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\tconst ref = new LocalReference(refType, properties, slidingPreference, canSlideToEndpoint);\n\t\tref.link(this.segment, offset, undefined);\n\t\tif (!refTypeIncludesFlag(ref, ReferenceType.Transient)) {\n\t\t\tthis.addLocalRef(ref, offset);\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t\treturn ref;\n\t}\n\n\t/**\n\t * Adds a local reference to the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addLocalRef(lref: LocalReferencePosition, offset: number): void {\n\t\tassertLocalReferences(lref);\n\t\tassert(\n\t\t\toffset < this.segment.cachedLength,\n\t\t\t0x348 /* offset cannot be beyond segment length */,\n\t\t);\n\t\tif (refTypeIncludesFlag(lref, ReferenceType.Transient)) {\n\t\t\tlref.link(this.segment, offset, undefined);\n\t\t} else {\n\t\t\tconst refsAtOffset = (this.refsByOffset[offset] = this.refsByOffset[offset] ?? {\n\t\t\t\tat: new DoublyLinkedList(),\n\t\t\t});\n\t\t\tconst atRefs = (refsAtOffset.at = refsAtOffset.at ?? new DoublyLinkedList());\n\n\t\t\tlref.link(this.segment, offset, atRefs.push(lref).last);\n\n\t\t\tthis.refCount++;\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Removes a local reference from the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic removeLocalRef(lref: LocalReferencePosition): LocalReferencePosition | undefined {\n\t\tif (this.has(lref)) {\n\t\t\tassertLocalReferences(lref);\n\n\t\t\tconst node = lref.getListNode();\n\t\t\tnode?.list?.remove(node);\n\n\t\t\tlref.link(undefined, 0, undefined);\n\n\t\t\tthis.refCount--;\n\t\t\tvalidateRefCount?.(this);\n\t\t\treturn lref;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n\t * end of 'this' segment.\n\t *\n\t * Note: This method should be invoked after the caller has ensured that segments can be merged,\n\t * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n\t * will be incorrect.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic append(other: LocalReferenceCollection): void {\n\t\tif (!other || other.empty) {\n\t\t\treturn;\n\t\t}\n\t\tthis.refCount += other.refCount;\n\t\tother.refCount = 0;\n\t\tfor (const lref of other) {\n\t\t\tassertLocalReferences(lref);\n\t\t\tlref.link(this.segment, lref.getOffset() + this.refsByOffset.length, lref.getListNode());\n\t\t}\n\n\t\tthis.refsByOffset.push(...other.refsByOffset);\n\t\tother.refsByOffset.length = 0;\n\t}\n\t/**\n\t * Returns true of the local reference is in the collection, otherwise false.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic has(lref: ReferencePosition): boolean {\n\t\tif (\n\t\t\t!(lref instanceof LocalReference) ||\n\t\t\trefTypeIncludesFlag(lref, ReferenceType.Transient)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst seg = lref.getSegment();\n\t\tif (seg !== this.segment) {\n\t\t\treturn false;\n\t\t}\n\t\t// we should be able to optimize finding the\n\t\t// list head\n\t\tconst listNode = lref.getListNode();\n\t\tif (listNode === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tconst offset = lref.getOffset();\n\t\tconst refsAtOffset = this.refsByOffset[offset];\n\t\tif (\n\t\t\t!!refsAtOffset?.before?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.at?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.after?.includes(listNode)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n\t * Local references in the former half of this split will remain associated with the segment used on construction.\n\t * Local references in the latter half of this split will be transferred to `splitSeg`,\n\t * and its `localRefs` field will be set.\n\t * @param offset - Offset into the original segment at which the collection should be split\n\t * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n\t * before splitting.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic split(offset: number, splitSeg: ISegmentInternal): void {\n\t\tif (this.empty) {\n\t\t\t// shrink the offset array when empty and splitting\n\t\t\tthis.refsByOffset.length = offset;\n\t\t} else {\n\t\t\tconst localRefs = new LocalReferenceCollection(\n\t\t\t\tsplitSeg,\n\t\t\t\tthis.refsByOffset.splice(offset, this.refsByOffset.length - offset),\n\t\t\t);\n\n\t\t\tsplitSeg.localRefs = localRefs;\n\t\t\tfor (const lref of localRefs) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tlref.link(splitSeg, lref.getOffset() - offset, lref.getListNode());\n\t\t\t\tthis.refCount--;\n\t\t\t\tlocalRefs.refCount++;\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Insert a reference before tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addBeforeTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst beforeRefs = this.refsByOffset[0]?.before ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[0]?.before === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[0] ??= { before: beforeRefs });\n\t\t\trefsAtOffset.before ??= beforeRefs;\n\t\t}\n\n\t\tlet precedingRef: ListNode<LocalReference> | undefined;\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tprecedingRef =\n\t\t\t\t\t\tprecedingRef === undefined\n\t\t\t\t\t\t\t? beforeRefs.unshift(lref)?.first\n\t\t\t\t\t\t\t: beforeRefs.insertAfter(precedingRef, lref)?.first;\n\t\t\t\t\tlref.link(this.segment, 0, precedingRef);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\t/**\n\t * Insert a reference after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addAfterTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst lastOffset = this.segment.cachedLength - 1;\n\t\tconst afterRefs = this.refsByOffset[lastOffset]?.after ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[lastOffset]?.after === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[lastOffset] ??= { after: afterRefs });\n\t\t\trefsAtOffset.after ??= afterRefs;\n\t\t}\n\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tafterRefs.push(lref);\n\t\t\t\t\tlref.link(this.segment, lastOffset, afterRefs.last);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Determines if a reference is after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic isAfterTombstone(lref: LocalReferencePosition): boolean {\n\t\tconst after = this.refsByOffset[lref.getOffset()]?.after;\n\t\tif (after) {\n\t\t\tassertLocalReferences(lref);\n\t\t\treturn after.includes(lref.getListNode());\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Walks all of the references in a collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic walkReferences(\n\t\tvisitor: (lref: LocalReferencePosition) => boolean | void | undefined,\n\t\tstart?: LocalReferencePosition,\n\t\tforward: boolean = true,\n\t): boolean {\n\t\tif (start !== undefined) {\n\t\t\tif (!this.has(start)) {\n\t\t\t\tthrow new UsageError(\"start must be in collection\");\n\t\t\t}\n\t\t\tassertLocalReferences(start);\n\t\t}\n\t\tlet offset = start?.getOffset() ?? (forward ? 0 : this.segment.cachedLength - 1);\n\n\t\tconst offsetPositions: DoublyLinkedList<IRefsAtOffset[keyof IRefsAtOffset]> =\n\t\t\tnew DoublyLinkedList();\n\t\toffsetPositions.push(\n\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\tthis.refsByOffset[offset]?.after,\n\t\t);\n\n\t\tconst startNode = start?.getListNode();\n\t\tconst startList = startNode?.list;\n\n\t\tif (startList !== undefined) {\n\t\t\t// Discard the buckets (before/at/after) which precede the bucket containing `start`,\n\t\t\t// so the walk begins at that bucket. `listWalker` then resumes mid-bucket at `startNode`.\n\t\t\tif (forward) {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.first?.data !== startList) {\n\t\t\t\t\toffsetPositions.shift();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.last?.data !== startList) {\n\t\t\t\t\toffsetPositions.pop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst listWalker = (pos: DoublyLinkedList<LocalReference>): boolean => {\n\t\t\treturn walkList(\n\t\t\t\tpos,\n\t\t\t\t(node) => visitor(node.data),\n\t\t\t\tstartList === pos ? startNode : undefined,\n\t\t\t\tforward,\n\t\t\t);\n\t\t};\n\t\tconst increment = forward ? 1 : -1;\n\t\twhile (offset >= 0 && offset < this.refsByOffset.length) {\n\t\t\twhile (offsetPositions.length > 0) {\n\t\t\t\tconst offsetPos = forward ? offsetPositions.shift() : offsetPositions.pop();\n\t\t\t\tif (offsetPos?.data !== undefined && listWalker(offsetPos.data) === false) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += increment;\n\t\t\toffsetPositions.push(\n\t\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\t\tthis.refsByOffset[offset]?.after,\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|