@fluidframework/merge-tree 2.81.1 → 2.82.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 +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +12 -2
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeTracking.d.ts.map +1 -1
- package/dist/mergeTreeTracking.js +3 -1
- package/dist/mergeTreeTracking.js.map +1 -1
- package/dist/partialLengths.d.ts.map +1 -1
- package/dist/partialLengths.js.map +1 -1
- package/dist/test/beastTest.spec.d.ts.map +1 -1
- package/dist/test/beastTest.spec.js +3 -1
- package/dist/test/beastTest.spec.js.map +1 -1
- package/dist/test/testServer.d.ts.map +1 -1
- package/dist/test/testServer.js +3 -1
- package/dist/test/testServer.js.map +1 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +3 -1
- package/lib/client.js.map +1 -1
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +12 -2
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeTracking.d.ts.map +1 -1
- package/lib/mergeTreeTracking.js +3 -1
- package/lib/mergeTreeTracking.js.map +1 -1
- package/lib/partialLengths.d.ts.map +1 -1
- package/lib/partialLengths.js.map +1 -1
- package/lib/test/beastTest.spec.d.ts.map +1 -1
- package/lib/test/beastTest.spec.js +3 -1
- package/lib/test/beastTest.spec.js.map +1 -1
- package/lib/test/testServer.d.ts.map +1 -1
- package/lib/test/testServer.js +3 -1
- package/lib/test/testServer.js.map +1 -1
- package/package.json +17 -17
- package/src/client.ts +1 -0
- package/src/mergeTree.ts +27 -9
- package/src/mergeTreeTracking.ts +1 -0
- package/src/partialLengths.ts +5 -1
- package/biome.jsonc +0 -4
package/lib/mergeTree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AA6G;YAC7G,uBAAuB;YACvB,MAAM,wBAAwB,GAC7B,qBAAqB,KAAK,WAAW;gBACrC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACvD,IACC,CAAC,GAAG,KAAK,SAAS,IAAI,WAAW,KAAK,CAAC,CAAC;gBACxC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,wBAAwB,IAAI,WAAW,KAAK,CAAC,CAAC,EAC5D,CAAC;gBACF,OAAO,UAAU,CAAC,IAAI,CAAC;YACxB,CAAC;YAED,MAAM,OAAO,GAAG,GAAG,GAAG,WAAW,CAAC;YAClC,sDAAsD;YACtD,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACtB,GAAG,GAAG,OAAO,CAAC;gBACd,OAAO,UAAU,CAAC,IAAI,CAAC;YACxB,CAAC;YAED,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBACnB,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC1D,OAAO,UAAU,CAAC,IAAI,CAAC;gBACxB,CAAC;gBACD,GAAG,GAAG,OAAO,CAAC;YACf,CAAC;QACF,CAAC,EACD,SAAS,EACT,IAAI,CACJ,CAAC;IACH,CAAC;;AAxzEsB,iBAAO,GAAG;IAChC,iBAAiB,EAAE,IAAI;IACvB,sBAAsB,EAAE,IAAI;IAC5B,eAAe,EAAE,IAAI;CACrB,AAJ6B,CAI5B;AAEF;;;;GAIG;AACqB,2BAAiB,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC,EAA2B,AAA9C,CAA+C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable no-bitwise */\n\nimport {\n\tassert,\n\tHeap,\n\ttype IComparer,\n\tDoublyLinkedList,\n\ttype ListNode,\n} from \"@fluidframework/core-utils/internal\";\nimport { DataProcessingError, UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IAttributionCollectionSerializer } from \"./attributionCollection.js\";\nimport type { Client } from \"./client.js\";\nimport {\n\tNonCollabClient,\n\tTreeMaintenanceSequenceNumber,\n\tUnassignedSequenceNumber,\n} from \"./constants.js\";\nimport { EndOfTreeSegment, StartOfTreeSegment } from \"./endOfTreeSegment.js\";\nimport {\n\tLocalReferenceCollection,\n\ttype LocalReferencePosition,\n\tSlidingPreference,\n\tanyLocalReferencePosition,\n\tfilterLocalReferencePositions,\n} from \"./localReference.js\";\nimport {\n\ttype IMergeTreeDeltaOpArgs,\n\ttype IMergeTreeSegmentDelta,\n\ttype MergeTreeDeltaCallback,\n\ttype MergeTreeMaintenanceCallback,\n\tMergeTreeMaintenanceType,\n} from \"./mergeTreeDeltaCallback.js\";\nimport {\n\tLeafAction,\n\tNodeAction,\n\tbackwardExcursion,\n\tdepthFirstNodeWalk,\n\tforwardExcursion,\n\twalkAllChildSegments,\n} from \"./mergeTreeNodeWalk.js\";\nimport {\n\tCollaborationWindow,\n\ttype IMergeNode,\n\ttype ISegmentAction,\n\ttype ISegmentChanges,\n\ttype InsertContext,\n\tMarker,\n\tMaxNodesInBlock,\n\tMergeBlock,\n\ttype SegmentGroup,\n\tassertSegmentLeaf,\n\tassignChild,\n\tgetMinSeqPerspective,\n\tgetMinSeqStamp,\n\tisSegmentLeaf,\n\treservedMarkerIdKey,\n\ttype IMergeNodeBuilder,\n\ttype ISegmentInternal,\n\ttype ISegmentLeaf,\n\ttype ISegmentPrivate,\n\ttype ObliterateInfo,\n} from \"./mergeTreeNodes.js\";\nimport { UnorderedTrackingGroup, type TrackingGroup } from \"./mergeTreeTracking.js\";\nimport {\n\tcreateAnnotateRangeOp,\n\tcreateInsertSegmentOp,\n\tcreateRemoveRangeOp,\n} from \"./opBuilder.js\";\nimport {\n\ttype IRelativePosition,\n\tMergeTreeDeltaType,\n\tReferenceType,\n\ttype IMergeTreeOp,\n} from \"./ops.js\";\nimport { PartialSequenceLengths } from \"./partialLengths.js\";\nimport {\n\tPriorPerspective,\n\tLocalReconnectingPerspective,\n\ttype Perspective,\n\tLocalDefaultPerspective,\n\tRemoteObliteratePerspective,\n\tallAckedChangesPerspective,\n} from \"./perspective.js\";\nimport { type PropertySet, createMap, extend, extendIfUndefined } from \"./properties.js\";\nimport {\n\tDetachedReferencePosition,\n\ttype ReferencePosition,\n\trefGetTileLabels,\n\trefHasTileLabel,\n\trefTypeIncludesFlag,\n} from \"./referencePositions.js\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\tassertRemoved,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n\tisMergeNodeInfo,\n\tisRemoved,\n\toverwriteInfo,\n\tremoveRemovalInfo,\n\ttoRemovalInfo,\n\ttype IHasInsertionInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tcopyPropertiesAndManager,\n\tPropertiesManager,\n\ttype PropsOrAdjust,\n} from \"./segmentPropertiesManager.js\";\nimport { Side, type InteriorSequencePlace } from \"./sequencePlace.js\";\nimport { SortedSegmentSet } from \"./sortedSegmentSet.js\";\nimport type {\n\tOperationStamp,\n\tInsertOperationStamp,\n\tRemoveOperationStamp,\n\tSetRemoveOperationStamp,\n\tSliceRemoveOperationStamp,\n} from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\nimport { zamboniSegments } from \"./zamboni.js\";\n\nexport function isRemovedAndAcked(\n\tsegment: ISegmentPrivate,\n): segment is ISegmentLeaf & IHasRemovalInfo {\n\tconst removalInfo = toRemovalInfo(segment);\n\treturn removalInfo !== undefined && opstampUtils.isAcked(removalInfo.removes[0]);\n}\n\nfunction nodeTotalLength(mergeTree: MergeTree, node: IMergeNode): number | undefined {\n\tif (!node.isLeaf()) {\n\t\treturn node.cachedLength;\n\t}\n\treturn mergeTree.leafLength(node);\n}\n\nconst LRUSegmentComparer: IComparer<LRUSegment> = {\n\tmin: { maxSeq: -2 },\n\tcompare: (a, b) => a.maxSeq - b.maxSeq,\n};\n\nfunction ackSegment(\n\tsegment: ISegmentLeaf,\n\tsegmentGroup: SegmentGroup,\n\topArgs: IMergeTreeDeltaOpArgs,\n\tstamp: OperationStamp,\n): boolean {\n\tconst currentSegmentGroup = segment.segmentGroups?.dequeue();\n\tassert(currentSegmentGroup === segmentGroup, 0x043 /* \"On ack, unexpected segmentGroup!\" */);\n\tassert(opArgs.sequencedMessage !== undefined, 0xa6e /* must have sequencedMessage */);\n\tconst {\n\t\top,\n\t\tsequencedMessage: { sequenceNumber, minimumSequenceNumber },\n\t} = opArgs;\n\tlet allowIncrementalPartialLengthsUpdate = true;\n\tswitch (op.type) {\n\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\tassert(\n\t\t\t\t!!segment.propertyManager,\n\t\t\t\t0x044 /* \"On annotate ack, missing segment property manager!\" */,\n\t\t\t);\n\t\t\tsegment.propertyManager.ack(sequenceNumber, minimumSequenceNumber, op);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\tassert(\n\t\t\t\topstampUtils.isLocal(segment.insert),\n\t\t\t\t0x045 /* \"On insert, seq number already assigned!\" */,\n\t\t\t);\n\n\t\t\tsegment.insert = {\n\t\t\t\t...stamp,\n\t\t\t\ttype: \"insert\",\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase MergeTreeDeltaType.REMOVE:\n\t\tcase MergeTreeDeltaType.OBLITERATE:\n\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED: {\n\t\t\tassertRemoved(segment);\n\t\t\tconst latestRemove = segment.removes[segment.removes.length - 1];\n\t\t\tassert(\n\t\t\t\topstampUtils.isLocal(latestRemove),\n\t\t\t\t0xb5d /* Expected last remove to be unacked */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tsegment.removes.length === 1 ||\n\t\t\t\t\topstampUtils.isAcked(segment.removes[segment.removes.length - 2]),\n\t\t\t\t0xb5e /* Expected prior remove to be acked */,\n\t\t\t);\n\n\t\t\tallowIncrementalPartialLengthsUpdate = segment.removes.length === 1;\n\t\t\tconst removeStamp: RemoveOperationStamp = {\n\t\t\t\t...stamp,\n\t\t\t\ttype: op.type === MergeTreeDeltaType.REMOVE ? \"setRemove\" : \"sliceRemove\",\n\t\t\t};\n\t\t\tsegment.removes[segment.removes.length - 1] = removeStamp;\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new Error(`${op.type} is in unrecognized operation type`);\n\t\t}\n\t}\n\n\treturn allowIncrementalPartialLengthsUpdate;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeOptions {\n\tcatchUpBlobName?: string;\n\t/**\n\t * Whether or not reference positions can slide to special endpoint segments\n\t * denoting the positions immediately before the start and immediately after\n\t * the end of the string.\n\t *\n\t * This is primarily useful in the case of interval stickiness.\n\t */\n\tmergeTreeReferencesCanSlideToEndpoint?: boolean;\n\tmergeTreeSnapshotChunkSize?: number;\n\t/**\n\t * Whether to use the SnapshotV1 format over SnapshotLegacy.\n\t *\n\t * SnapshotV1 stores a view of the merge-tree at the current sequence number, preserving merge metadata\n\t * (e.g. clientId, seq, etc.) only for segment changes within the collab window.\n\t *\n\t * SnapshotLegacy stores a view of the merge-tree at the minimum sequence number along with the ops between\n\t * the minimum sequence number and the current sequence number.\n\t *\n\t * Both formats merge segments where possible (see {@link ISegment.canAppend})\n\t *\n\t * default: false\n\t *\n\t * @remarks\n\t * Despite the \"legacy\"/\"V1\" naming, both formats are actively used at the time of writing. SharedString\n\t * uses legacy and Matrix uses V1.\n\t */\n\tnewMergeTreeSnapshotFormat?: boolean;\n\n\t/**\n\t * Enables support for the obliterate operation -- a stronger form of remove\n\t * which deletes concurrently inserted segments\n\t *\n\t * Obliterate is currently experimental and may not work in all scenarios.\n\t *\n\t * Default value: false\n\t */\n\tmergeTreeEnableObliterate?: boolean;\n\n\t/**\n\t * Enables support for reconnecting when obliterate operations are present\n\t *\n\t * Obliterate is currently experimental and may not work in all scenarios.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableObliterateReconnect?: boolean;\n\n\t/**\n\t * Enables support for obliterate endpoint expansion.\n\t * When enabled, obliterate operations can have sidedness specified for their endpoints.\n\t * If an endpoint is externally anchored\n\t * (aka the start is after a given position, or the end is before a given position),\n\t * then concurrent inserts adjacent to the exclusive endpoint of an obliterated range will be included in the obliteration\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableSidedObliterate?: boolean;\n\n\t/**\n\t * Enables support for annotate adjust operations, which allow for specifying\n\t * a summand which is summed with the current value to compute the new value.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableAnnotateAdjust?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IMergeTreeOptionsInternal extends IMergeTreeOptions {\n\t/**\n\t * Options related to attribution\n\t */\n\tattribution?: IMergeTreeAttributionOptions;\n}\n\nexport function errorIfOptionNotTrue(\n\toptions: IMergeTreeOptions | undefined,\n\toption: keyof IMergeTreeOptions,\n): void {\n\tif (options?.[option] !== true) {\n\t\tthrow new Error(`${option} is not enabled.`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface IMergeTreeAttributionOptions {\n\t/**\n\t * If enabled, segments will store attribution keys which can be used with the runtime to determine\n\t * attribution information (i.e. who created the content and when it was created).\n\t *\n\t * This flag only applied to new documents: if a snapshot is loaded, whether or not attribution keys\n\t * are tracked is determined by the presence of existing attribution keys in the snapshot.\n\t *\n\t * default: false\n\t */\n\ttrack?: boolean;\n\n\t/**\n\t * Provides a policy for how to track attribution data on segments.\n\t * This option must be provided if either:\n\t * - `track` is set to true\n\t * - a document containing existing attribution information is loaded\n\t */\n\tpolicyFactory?: () => AttributionPolicy;\n}\n\n/**\n * Implements policy dictating which kinds of operations should be attributed and how.\n * @sealed\n * @internal\n */\nexport interface AttributionPolicy {\n\t/**\n\t * Enables tracking attribution information for operations on this merge-tree.\n\t * This function is expected to subscribe to appropriate change events in order\n\t * to manage any attribution data it stores on segments.\n\t *\n\t * This must be done in an eventually consistent fashion.\n\t */\n\tattach: (client: Client) => void;\n\t/**\n\t * Disables tracking attribution information on segments.\n\t */\n\tdetach: () => void;\n\t/***/\n\tisAttached: boolean;\n\t/**\n\t * Serializer capable of serializing any attribution data this policy stores on segments.\n\t */\n\tserializer: IAttributionCollectionSerializer;\n}\n\n/**\n * @internal\n */\nexport interface LRUSegment {\n\tsegment?: ISegmentLeaf;\n\tmaxSeq: number;\n}\n\nexport interface IRootMergeBlock extends MergeBlock {\n\tmergeTree?: MergeTree;\n}\n\nexport function findRootMergeBlock(\n\tsegmentOrNode: IMergeNode | undefined,\n): IRootMergeBlock | undefined {\n\tif (segmentOrNode === undefined) {\n\t\treturn undefined;\n\t}\n\tlet maybeRoot: IRootMergeBlock | undefined = segmentOrNode.isLeaf()\n\t\t? segmentOrNode.parent\n\t\t: segmentOrNode;\n\twhile (maybeRoot?.parent !== undefined) {\n\t\tmaybeRoot = maybeRoot.parent;\n\t}\n\n\treturn maybeRoot?.mergeTree === undefined ? undefined : maybeRoot;\n}\n\n/**\n * Find the segment to which a reference will slide if it needs to slide, or undefined if there\n * is no valid segment (i.e. the tree is empty).\n *\n * @param segment - The segment to slide from.\n * @param cache - Optional cache mapping segments to their sliding destinations.\n * Excursions will be avoided for segments in the cache, and the cache will be populated with\n * entries for all segments visited during excursion.\n * This can reduce the number of times the tree needs to be scanned if a range containing many\n * SlideOnRemove references is removed.\n */\nfunction getSlideToSegment(\n\tsegment: ISegmentLeaf | undefined,\n\tslidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\tperspective: Perspective,\n\tcache?: Map<ISegmentLeaf, { seg?: ISegmentLeaf }>,\n\tcanSlideToEndpoint: boolean = false,\n): [ISegmentLeaf | undefined, \"start\" | \"end\" | undefined] {\n\tif (\n\t\t!segment ||\n\t\tperspective.isSegmentPresent(segment) ||\n\t\tsegment.endpointType !== undefined\n\t) {\n\t\treturn [segment, undefined];\n\t}\n\n\tconst cachedSegment = cache?.get(segment);\n\tif (cachedSegment !== undefined) {\n\t\treturn [cachedSegment.seg, undefined];\n\t}\n\tconst result: { seg?: ISegmentLeaf } = {};\n\tcache?.set(segment, result);\n\tconst goFurtherToFindSlideToSegment = (seg: ISegmentLeaf): boolean => {\n\t\tif (perspective.isSegmentPresent(seg)) {\n\t\t\tresult.seg = seg;\n\t\t\treturn false;\n\t\t}\n\t\tif (\n\t\t\tcache !== undefined &&\n\t\t\ttoRemovalInfo(seg)?.removes[0].seq === toRemovalInfo(segment)?.removes[0].seq\n\t\t) {\n\t\t\tcache.set(seg, result);\n\t\t}\n\t\treturn true;\n\t};\n\n\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\tbackwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t} else {\n\t\tforwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t}\n\tif (result.seg !== undefined) {\n\t\treturn [result.seg, undefined];\n\t}\n\n\t// in the new sliding behavior, we don't look in the opposite direction\n\t// if we fail to find a segment to slide to in the right direction.\n\t//\n\t// in other words, rather than going `forward ?? backward ?? detached` (or\n\t// `backward ?? forward ?? detached`), we would slide `forward ?? detached`\n\t// or `backward ?? detached`\n\t//\n\t// in both of these cases detached may be substituted for one of the special\n\t// endpoint segments, if such behavior is enabled\n\tif (!canSlideToEndpoint) {\n\t\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\t\tforwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t\t} else {\n\t\t\tbackwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t\t}\n\t}\n\n\tlet maybeEndpoint: \"start\" | \"end\" | undefined;\n\n\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\tmaybeEndpoint = \"start\";\n\t} else if (slidingPreference === SlidingPreference.FORWARD) {\n\t\tmaybeEndpoint = \"end\";\n\t}\n\n\treturn [result.seg, maybeEndpoint];\n}\n\n/**\n * Returns the position to slide a reference to if a slide is required.\n * @param segoff - The segment and offset to slide from\n * @returns segment and offset to slide the reference to\n * @internal\n */\nexport function getSlideToSegoff(\n\tsegoff: { segment: ISegmentInternal; offset: number } | undefined,\n\tslidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\tperspective: Perspective = allAckedChangesPerspective,\n\tcanSlideToEndpoint: boolean = false,\n):\n\t| {\n\t\t\tsegment: ISegmentInternal;\n\t\t\toffset: number;\n\t }\n\t| undefined {\n\tif (!isSegmentLeaf(segoff?.segment)) {\n\t\treturn segoff;\n\t}\n\tconst [segment, _] = getSlideToSegment(\n\t\tsegoff.segment,\n\t\tslidingPreference,\n\t\tperspective,\n\t\tundefined,\n\t\tcanSlideToEndpoint,\n\t);\n\tif (segment === segoff.segment) {\n\t\treturn segoff;\n\t}\n\tif (segment === undefined) {\n\t\treturn undefined;\n\t}\n\n\tconst offset = segment.ordinal < segoff.segment.ordinal ? segment.cachedLength - 1 : 0;\n\treturn {\n\t\tsegment,\n\t\toffset,\n\t};\n}\n\nconst forwardPred = (ref: LocalReferencePosition): boolean =>\n\tref.slidingPreference !== SlidingPreference.BACKWARD;\nconst backwardPred = (ref: LocalReferencePosition): boolean =>\n\tref.slidingPreference === SlidingPreference.BACKWARD;\n\nclass Obliterates {\n\t/**\n\t * Array containing the all obliterate operations within the\n\t * collab window.\n\t *\n\t * The obliterates are stored in sequence order which accelerates clean up in setMinSeq\n\t *\n\t * See https://github.com/microsoft/FluidFramework/blob/main/packages/dds/merge-tree/docs/Obliterate.md#remote-perspective\n\t * for additional context\n\t */\n\n\tprivate readonly seqOrdered = new DoublyLinkedList<ObliterateInfo>();\n\n\t/**\n\t * This contains a sorted lists of all obliterate starts\n\t * and is used to accelerate finding overlapping obliterates\n\t * as well as determining if there are any obliterates at all.\n\t */\n\tprivate readonly startOrdered = new SortedSegmentSet<LocalReferencePosition>();\n\n\tconstructor(private readonly mergeTree: MergeTree) {}\n\n\tpublic setMinSeq(minSeq: number): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\twhile (!this.seqOrdered.empty && this.seqOrdered.first?.data.stamp.seq! <= minSeq) {\n\t\t\tconst ob = this.seqOrdered.shift()!;\n\t\t\tthis.startOrdered.remove(ob.data.start);\n\t\t\tthis.mergeTree.removeLocalReferencePosition(ob.data.start);\n\t\t\tthis.mergeTree.removeLocalReferencePosition(ob.data.end);\n\t\t}\n\t}\n\n\tpublic onNormalize(): void {\n\t\tthis.startOrdered.onSortOrderChange();\n\t}\n\n\tpublic addOrUpdate(obliterateInfo: ObliterateInfo): void {\n\t\tconst {\n\t\t\tstamp: { seq },\n\t\t\tstart,\n\t\t} = obliterateInfo;\n\t\tif (seq !== UnassignedSequenceNumber) {\n\t\t\tthis.seqOrdered.push(obliterateInfo);\n\t\t}\n\t\tthis.startOrdered.addOrUpdate(start);\n\t}\n\n\tpublic empty(): boolean {\n\t\treturn this.startOrdered.size === 0;\n\t}\n\n\tpublic findOverlapping(seg: ISegmentLeaf): Iterable<ObliterateInfo> {\n\t\tconst overlapping: ObliterateInfo[] = [];\n\t\tfor (const start of this.startOrdered.items) {\n\t\t\tconst startSeg = start.getSegment();\n\t\t\tif (isMergeNodeInfo(startSeg) && startSeg.ordinal <= seg.ordinal) {\n\t\t\t\tconst ob = start.properties?.obliterate as ObliterateInfo;\n\t\t\t\tconst endSeg = ob.end.getSegment();\n\t\t\t\tif (isMergeNodeInfo(endSeg) && endSeg.ordinal >= seg.ordinal) {\n\t\t\t\t\toverlapping.push(ob);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// the start is past the seg, so exit\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn overlapping;\n\t}\n\n\t/**\n\t * Remove a local obliterate from this data structure.\n\t * @privateRemarks\n\t * This data structure could support removing non-local obliterates if we wanted it to, but when adding support for that\n\t * we should reconsider the indexing structure for seq ordered obliterates (right now it would be an O(# obliterates) operation)\n\t */\n\tpublic removeLocalObliterate(obliterateInfo: ObliterateInfo): void {\n\t\tassert(\n\t\t\tobliterateInfo.stamp.seq === UnassignedSequenceNumber,\n\t\t\t0xb6e /* Expected local obliterate */,\n\t\t);\n\t\tthis.startOrdered.remove(obliterateInfo.start);\n\t}\n\n\t/**\n\t * Returns an iterator over the `ObliterateInfo` for all obliterates in the collab window. Obliterates are not guaranteed to be ordered.\n\t * The iterator is not guaranteed to be valid over edits to the set of obliterates.\n\t */\n\tpublic [Symbol.iterator](): IterableIterator<ObliterateInfo> {\n\t\tlet index = 0;\n\t\tconst { items: starts } = this.startOrdered;\n\t\tconst iterator: IterableIterator<ObliterateInfo> = {\n\t\t\tnext(): IteratorResult<ObliterateInfo> {\n\t\t\t\tif (index < starts.length) {\n\t\t\t\t\tconst start = starts[index++];\n\t\t\t\t\tconst info = start.properties?.obliterate as ObliterateInfo;\n\t\t\t\t\tassert(\n\t\t\t\t\t\tinfo?.start !== undefined && info?.end !== undefined,\n\t\t\t\t\t\t0xb6f /* Expected obliterateInfo endpoint to map to its obliterate */,\n\t\t\t\t\t);\n\t\t\t\t\treturn { value: info, done: false };\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\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n}\n\ninterface InsertResult {\n\t/**\n\t * If the insertion necessitated rebalancing, this field contains a `MergeBlock` that should be inserted after the block that `insertRecursive` was called on.\n\t */\n\tremainder: MergeBlock | undefined;\n\t/**\n\t * Whether the insert changed anything (including recursive changes) in the subtree of the block that `insertRecursive` was called on.\n\t */\n\thadChanges: boolean;\n}\n\n/**\n * @internal\n */\nexport class MergeTree {\n\tpublic static readonly options = {\n\t\tincrementalUpdate: true,\n\t\tinsertAfterRemovedSegs: true,\n\t\tzamboniSegments: true,\n\t};\n\n\t/**\n\t * A sentinel value that indicates an inserting walk should continue to the next block sibling.\n\t * This can occur for example when tie-break forces insertion of a segment past an entire block (and\n\t * the inserting walk first recurses into the block before realizing that).\n\t */\n\tprivate static readonly theUnfinishedNode = { childCount: -1 } as unknown as MergeBlock;\n\n\tpublic readonly collabWindow = new CollaborationWindow();\n\n\tpublic readonly pendingSegments = new DoublyLinkedList<SegmentGroup>();\n\n\tpublic readonly segmentsToScour = new Heap<LRUSegment>(LRUSegmentComparer);\n\n\tpublic readonly attributionPolicy: AttributionPolicy | undefined;\n\n\tpublic get localPerspective(): Perspective {\n\t\treturn this.collabWindow.localPerspective;\n\t}\n\n\t/**\n\t * Whether or not all blocks in the mergeTree currently have information about local partial lengths computed.\n\t * This information is only necessary on reconnect, and otherwise costly to bookkeep.\n\t * This field enables tracking whether partials need to be recomputed using localSeq information.\n\t */\n\tprivate localPartialsComputed = false;\n\t// for now assume only markers have ids and so point directly at the Segment\n\t// if we need to have pointers to non-markers, we can change to point at local refs\n\tprivate readonly idToMarker = new Map<string, Marker>();\n\tpublic mergeTreeDeltaCallback?: MergeTreeDeltaCallback;\n\tpublic mergeTreeMaintenanceCallback?: MergeTreeMaintenanceCallback;\n\n\t// TODO:AB#29553: This property doesn't seem to be adequately round-tripped through summarization.\n\t// Specifically, it seems like we drop information about obliterates within the collab window for at least V1 summaries.\n\tprivate readonly obliterates = new Obliterates(this);\n\n\tpublic constructor(public options?: IMergeTreeOptionsInternal) {\n\t\tthis._root = this.makeBlock(0);\n\t\tthis._root.mergeTree = this;\n\t\tthis.attributionPolicy = options?.attribution?.policyFactory?.();\n\t}\n\n\tpublic rebaseObliterateTo(\n\t\texisting: ObliterateInfo,\n\t\tnewObliterate: ObliterateInfo | undefined,\n\t): void {\n\t\tthis.obliterates.removeLocalObliterate(existing);\n\t\tif (newObliterate !== undefined) {\n\t\t\tthis.obliterates.addOrUpdate(newObliterate);\n\t\t}\n\t}\n\n\tprivate _root: IRootMergeBlock;\n\tpublic get root(): IRootMergeBlock {\n\t\treturn this._root;\n\t}\n\n\tpublic set root(value: IRootMergeBlock) {\n\t\tthis._root = value;\n\t\tvalue.mergeTree = this;\n\t}\n\n\tpublic makeBlock(childCount: number): MergeBlock {\n\t\tconst block = new MergeBlock(childCount);\n\t\tblock.ordinal = \"\";\n\t\treturn block;\n\t}\n\n\t/**\n\t * Compute the net length of this segment leaf from some perspective.\n\t * @returns Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore\n\t * may not even be present on clients that have loaded from a summary beyond this point). Otherwise, the length of the segment.\n\t */\n\tpublic leafLength(\n\t\tsegment: ISegmentLeaf,\n\t\tperspective: Perspective = this.localPerspective,\n\t): number | undefined {\n\t\tconst removalInfo = toRemovalInfo(segment);\n\t\tif (\n\t\t\tremovalInfo &&\n\t\t\tgetMinSeqPerspective(this.collabWindow).hasOccurred(removalInfo.removes[0])\n\t\t) {\n\t\t\t// this segment's removal has already moved outside the collab window which means it is zamboni eligible\n\t\t\t// this also means the segment could be completely absent from other client's in-memory merge trees,\n\t\t\t// so we should not consider it when making decisions about conflict resolutions\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn perspective.isSegmentPresent(segment) ? segment.cachedLength : 0;\n\t}\n\n\tpublic unlinkMarker(marker: Marker): void {\n\t\tconst id = marker.getId();\n\t\tif (id) {\n\t\t\tthis.idToMarker.delete(id);\n\t\t}\n\t}\n\n\tprivate addNode(block: MergeBlock, node: IMergeNodeBuilder): number {\n\t\tconst index = block.childCount++;\n\t\tassignChild(block, node, index, false);\n\t\treturn index;\n\t}\n\n\tpublic reloadFromSegments(segments: SegmentWithInfo<IHasInsertionInfo>[]): void {\n\t\t// This code assumes that a later call to `startCollaboration()` will initialize partial lengths.\n\t\tassert(\n\t\t\t!this.collabWindow.collaborating,\n\t\t\t0x049 /* \"Trying to reload from segments while collaborating!\" */,\n\t\t);\n\n\t\tconst maxChildren = MaxNodesInBlock - 1;\n\n\t\t// Starting with the leaf segments, recursively builds the B-Tree layer by layer from the bottom up.\n\t\tconst buildMergeBlock = (nodes: IMergeNodeBuilder[]): IRootMergeBlock => {\n\t\t\tconst blockCount = Math.ceil(nodes.length / maxChildren); // Compute # blocks require for this level of B-Tree\n\t\t\tconst blocks: MergeBlock[] = Array.from({ length: blockCount }); // Pre-alloc array to collect nodes\n\n\t\t\t// For each block in this level of the B-Tree...\n\t\t\tfor (\n\t\t\t\tlet nodeIndex = 0, blockIndex = 0; // Start with the first block and first node\n\t\t\t\tblockIndex < blockCount; // If we have more blocks, we also have more nodes to insert\n\t\t\t\tblockIndex++ // Advance to next block in this layer.\n\t\t\t) {\n\t\t\t\tconst block = (blocks[blockIndex] = this.makeBlock(0));\n\n\t\t\t\t// For each child of the current block, insert a node (while we have nodes left)\n\t\t\t\t// and update the block's info.\n\t\t\t\tfor (\n\t\t\t\t\tlet childIndex = 0;\n\t\t\t\t\tchildIndex < maxChildren && nodeIndex < nodes.length; // While we still have children & nodes left\n\t\t\t\t\tchildIndex++, nodeIndex++ // Advance to next child & node\n\t\t\t\t) {\n\t\t\t\t\t// Insert the next node into the current block\n\t\t\t\t\tthis.addNode(block, nodes[nodeIndex]);\n\t\t\t\t}\n\n\t\t\t\t// Calculate this block's info. Previously this was inlined into the above loop as a micro-optimization,\n\t\t\t\t// but it turns out to be negligible in practice since `reloadFromSegments()` is only invoked for the\n\t\t\t\t// snapshot header. The bulk of the segments in long documents are inserted via `insertSegments()`.\n\t\t\t\tthis.blockUpdate(block);\n\t\t\t}\n\n\t\t\treturn blocks.length === 1 // If there is only one block at this layer...\n\t\t\t\t? blocks[0] // ...then we're done. Return the root.\n\t\t\t\t: buildMergeBlock(blocks); // ...otherwise recursively build the next layer above blocks.\n\t\t};\n\t\tif (segments.length > 0) {\n\t\t\tthis.root = buildMergeBlock(segments);\n\t\t\tthis.nodeUpdateOrdinals(this.root);\n\t\t} else {\n\t\t\tthis.root = this.makeBlock(0);\n\t\t}\n\t}\n\n\t// For now assume min starts at zero\n\tpublic startCollaboration(localClientId: number, minSeq: number, currentSeq: number): void {\n\t\tthis.collabWindow.clientId = localClientId;\n\t\tthis.collabWindow.minSeq = minSeq;\n\t\tthis.collabWindow.collaborating = true;\n\t\tthis.collabWindow.currentSeq = currentSeq;\n\t\tthis.collabWindow.localPerspective = new LocalDefaultPerspective(localClientId);\n\t\tthis.nodeUpdateLengthNewStructure(this.root, true);\n\t}\n\n\tprivate addToLRUSet(leaf: ISegmentLeaf, seq: number): void {\n\t\t// If the parent node has not yet been marked for scour (i.e., needsScour is not false or undefined),\n\t\t// add the segment and mark the mark the node now.\n\n\t\t// TODO: 'seq' may be less than the current sequence number when inserting pre-ACKed\n\t\t// segments from a snapshot. We currently skip these for now.\n\t\tif (leaf.parent.needsScour !== true && seq > this.collabWindow.currentSeq) {\n\t\t\tleaf.parent.needsScour = true;\n\t\t\tthis.segmentsToScour.add({ segment: leaf, maxSeq: seq });\n\t\t}\n\t}\n\n\tpublic getLength(perspective: Perspective): number {\n\t\treturn this.nodeLength(this.root, perspective) ?? 0;\n\t}\n\n\t/**\n\t * Returns the current length of the MergeTree for the local client.\n\t */\n\tpublic get length(): number | undefined {\n\t\treturn this.root.cachedLength;\n\t}\n\n\tpublic getPosition(node: IMergeNode, perspective: Perspective): number {\n\t\tif (node.isLeaf() && node.endpointType === \"start\") {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlet totalOffset = 0;\n\t\tlet parent = node.parent;\n\t\tlet prevParent: MergeBlock | undefined;\n\t\twhile (parent) {\n\t\t\tconst children = parent.children;\n\t\t\tfor (let childIndex = 0; childIndex < parent.childCount; childIndex++) {\n\t\t\t\tconst child = children[childIndex];\n\t\t\t\tif ((!!prevParent && child === prevParent) || child === node) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ttotalOffset += this.nodeLength(child, perspective) ?? 0;\n\t\t\t}\n\t\t\tprevParent = parent;\n\t\t\tparent = parent.parent;\n\t\t}\n\t\treturn totalOffset;\n\t}\n\n\tpublic getContainingSegment(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t):\n\t\t| {\n\t\t\t\tsegment: ISegmentLeaf;\n\t\t\t\toffset: number;\n\t\t }\n\t\t| undefined {\n\t\tassert(\n\t\t\tperspective.localSeq === undefined ||\n\t\t\t\tperspective.clientId === this.collabWindow.clientId,\n\t\t\t0x39b /* localSeq provided for non-local client */,\n\t\t);\n\n\t\tlet segment: ISegmentLeaf | undefined;\n\t\tlet offset: number | undefined;\n\n\t\tconst leaf = (leafSeg: ISegmentLeaf, _: number, start: number): boolean => {\n\t\t\tsegment = leafSeg;\n\t\t\toffset = start;\n\t\t\treturn false;\n\t\t};\n\t\tthis.nodeMap(perspective, leaf, undefined, pos, pos + 1);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { segment, offset };\n\t}\n\n\t/**\n\t * Slides or removes references from the provided list of segments.\n\t *\n\t * The order of the references is preserved for references of the same sliding\n\t * preference. Relative order between references that slide backward and those\n\t * that slide forward is not preserved, even in the case when they slide to\n\t * the same segment.\n\t *\n\t * @remarks\n\t *\n\t * 1. Preserving the order of the references is a useful property for reference-based undo/redo\n\t * (see revertibles.ts).\n\t *\n\t * 2. For use cases which necessitate eventual consistency across clients,\n\t * this method should only be called with segments for which the current client sequence number is\n\t * max(remove segment sequence number, add reference sequence number).\n\t * See `packages\\dds\\merge-tree\\REFERENCEPOSITIONS.md`\n\t *\n\t * @param segments - An array of (not necessarily contiguous) segments with increasing ordinals.\n\t */\n\tprivate slideAckedRemovedSegmentReferences(segments: ISegmentLeaf[]): void {\n\t\t// References are slid in groups to preserve their order.\n\t\tlet currentForwardSlideGroup: LocalReferenceCollection[] = [];\n\t\tlet currentBackwardSlideGroup: LocalReferenceCollection[] = [];\n\n\t\tlet currentForwardMaybeEndpoint: \"start\" | \"end\" | undefined;\n\t\tlet currentForwardSlideDestination: ISegmentLeaf | undefined;\n\t\tlet currentForwardSlideIsForward: boolean | undefined;\n\n\t\tlet currentBackwardMaybeEndpoint: \"start\" | \"end\" | undefined;\n\t\tlet currentBackwardSlideDestination: ISegmentLeaf | undefined;\n\t\tlet currentBackwardSlideIsForward: boolean | undefined;\n\n\t\tconst slideGroup = (\n\t\t\tcurrentSlideDestination: ISegmentLeaf | undefined,\n\t\t\tcurrentSlideIsForward: boolean | undefined,\n\t\t\tcurrentSlideGroup: LocalReferenceCollection[],\n\t\t\tpred: (ref: LocalReferencePosition) => boolean,\n\t\t\tmaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t): void => {\n\t\t\tif (currentSlideIsForward === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nonEndpointRefsToAdd = currentSlideGroup.map((collection) =>\n\t\t\t\tfilterLocalReferencePositions(\n\t\t\t\t\tcollection,\n\t\t\t\t\t(ref) => pred(ref) && (maybeEndpoint ? !ref.canSlideToEndpoint : true),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tconst endpointRefsToAdd = currentSlideGroup.map((collection) =>\n\t\t\t\tfilterLocalReferencePositions(\n\t\t\t\t\tcollection,\n\t\t\t\t\t(ref) => pred(ref) && !!ref.canSlideToEndpoint,\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tif (maybeEndpoint) {\n\t\t\t\tconst endpoint = maybeEndpoint === \"start\" ? this.startOfTree : this.endOfTree;\n\t\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(endpoint);\n\t\t\t\tif (currentSlideIsForward) {\n\t\t\t\t\tlocalRefs.addBeforeTombstones(...endpointRefsToAdd);\n\t\t\t\t} else {\n\t\t\t\t\tlocalRefs.addAfterTombstones(...endpointRefsToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentSlideDestination === undefined) {\n\t\t\t\tfor (const collection of currentSlideGroup) {\n\t\t\t\t\tfor (const ref of collection) {\n\t\t\t\t\t\tif (pred(ref) && !refTypeIncludesFlag(ref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\t\t\tref.callbacks?.beforeSlide?.(ref);\n\t\t\t\t\t\t\tcollection.removeLocalRef(ref);\n\t\t\t\t\t\t\tref.callbacks?.afterSlide?.(ref);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(currentSlideDestination);\n\t\t\t\tif (currentSlideIsForward) {\n\t\t\t\t\tlocalRefs.addBeforeTombstones(...nonEndpointRefsToAdd);\n\t\t\t\t} else {\n\t\t\t\t\tlocalRefs.addAfterTombstones(...nonEndpointRefsToAdd);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst trySlideSegment = (\n\t\t\tsegment: ISegmentLeaf,\n\t\t\tcurrentSlideDestination: ISegmentLeaf | undefined,\n\t\t\tcurrentSlideIsForward: boolean | undefined,\n\t\t\tcurrentSlideGroup: LocalReferenceCollection[],\n\t\t\tpred: (ref: LocalReferencePosition) => boolean,\n\t\t\tslidingPreference: SlidingPreference,\n\t\t\tcurrentMaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t\treassign: (\n\t\t\t\tlocalRefs: LocalReferenceCollection,\n\t\t\t\tslideToSegment: ISegmentLeaf | undefined,\n\t\t\t\tslideIsForward: boolean,\n\t\t\t\tmaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t\t) => void,\n\t\t): void => {\n\t\t\t// avoid sliding logic if this segment doesn't have any references\n\t\t\t// with the given sliding preference\n\t\t\tif (!segment.localRefs || !anyLocalReferencePosition(segment.localRefs, pred)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst [slideToSegment, maybeEndpoint] = getSlideToSegment(\n\t\t\t\tsegment,\n\t\t\t\tslidingPreference,\n\t\t\t\tallAckedChangesPerspective,\n\t\t\t\tslidingPreference === SlidingPreference.FORWARD\n\t\t\t\t\t? forwardSegmentCache\n\t\t\t\t\t: backwardSegmentCache,\n\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint,\n\t\t\t);\n\t\t\tconst slideIsForward =\n\t\t\t\tslideToSegment === undefined ? false : slideToSegment.ordinal > segment.ordinal;\n\n\t\t\tif (\n\t\t\t\tslideToSegment !== currentSlideDestination ||\n\t\t\t\tslideIsForward !== currentSlideIsForward ||\n\t\t\t\tmaybeEndpoint !== currentMaybeEndpoint\n\t\t\t) {\n\t\t\t\tslideGroup(\n\t\t\t\t\tcurrentSlideDestination,\n\t\t\t\t\tcurrentSlideIsForward,\n\t\t\t\t\tcurrentSlideGroup,\n\t\t\t\t\tpred,\n\t\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint ? maybeEndpoint : undefined,\n\t\t\t\t);\n\t\t\t\treassign(\n\t\t\t\t\tsegment.localRefs,\n\t\t\t\t\tslideToSegment,\n\t\t\t\t\tslideIsForward,\n\t\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint ? maybeEndpoint : undefined,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tcurrentSlideGroup.push(segment.localRefs);\n\t\t\t}\n\t\t};\n\n\t\tconst forwardSegmentCache = new Map<ISegmentLeaf, { seg?: ISegmentLeaf }>();\n\t\tconst backwardSegmentCache = new Map<ISegmentLeaf, { seg?: ISegmentLeaf }>();\n\t\tfor (const segment of segments) {\n\t\t\tassert(\n\t\t\t\tisRemovedAndAcked(segment),\n\t\t\t\t0x2f1 /* slideReferences from a segment which has not been removed and acked */,\n\t\t\t);\n\t\t\tif (segment.localRefs === undefined || segment.localRefs.empty) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttrySlideSegment(\n\t\t\t\tsegment,\n\t\t\t\tcurrentForwardSlideDestination,\n\t\t\t\tcurrentForwardSlideIsForward,\n\t\t\t\tcurrentForwardSlideGroup,\n\t\t\t\tforwardPred,\n\t\t\t\tSlidingPreference.FORWARD,\n\t\t\t\tcurrentForwardMaybeEndpoint,\n\t\t\t\t(localRefs, slideToSegment, slideIsForward, maybeEndpoint) => {\n\t\t\t\t\tcurrentForwardSlideGroup = [localRefs];\n\t\t\t\t\tcurrentForwardSlideDestination = slideToSegment;\n\t\t\t\t\tcurrentForwardSlideIsForward = slideIsForward;\n\t\t\t\t\tcurrentForwardMaybeEndpoint = maybeEndpoint;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\ttrySlideSegment(\n\t\t\t\tsegment,\n\t\t\t\tcurrentBackwardSlideDestination,\n\t\t\t\tcurrentBackwardSlideIsForward,\n\t\t\t\tcurrentBackwardSlideGroup,\n\t\t\t\tbackwardPred,\n\t\t\t\tSlidingPreference.BACKWARD,\n\t\t\t\tcurrentBackwardMaybeEndpoint,\n\t\t\t\t(localRefs, slideToSegment, slideIsForward, maybeEndpoint) => {\n\t\t\t\t\tcurrentBackwardSlideGroup = [localRefs];\n\t\t\t\t\tcurrentBackwardSlideDestination = slideToSegment;\n\t\t\t\t\tcurrentBackwardSlideIsForward = slideIsForward;\n\t\t\t\t\tcurrentBackwardMaybeEndpoint = maybeEndpoint;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tslideGroup(\n\t\t\tcurrentForwardSlideDestination,\n\t\t\tcurrentForwardSlideIsForward,\n\t\t\tcurrentForwardSlideGroup,\n\t\t\tforwardPred,\n\t\t\tcurrentForwardMaybeEndpoint,\n\t\t);\n\t\tslideGroup(\n\t\t\tcurrentBackwardSlideDestination,\n\t\t\tcurrentBackwardSlideIsForward,\n\t\t\tcurrentBackwardSlideGroup,\n\t\t\tbackwardPred,\n\t\t\tcurrentBackwardMaybeEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Compute local partial length information\n\t *\n\t * Public only for use by internal tests\n\t */\n\tpublic computeLocalPartials(refSeq: number): void {\n\t\tif (this.localPartialsComputed) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rebaseCollabWindow = new CollaborationWindow();\n\t\trebaseCollabWindow.loadFrom(this.collabWindow);\n\t\tif (refSeq < this.collabWindow.minSeq) {\n\t\t\trebaseCollabWindow.minSeq = refSeq;\n\t\t}\n\t\tthis.root.partialLengths = PartialSequenceLengths.combine(\n\t\t\tthis.root,\n\t\t\trebaseCollabWindow,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t\tthis.localPartialsComputed = true;\n\t}\n\n\tprivate nodeLength(node: IMergeNode, perspective: Perspective): number | undefined {\n\t\tif (node.isLeaf()) {\n\t\t\treturn this.leafLength(node, perspective);\n\t\t}\n\n\t\tconst { refSeq, clientId, localSeq } = perspective;\n\n\t\tconst isLocalPerspective =\n\t\t\t!this.collabWindow.collaborating || this.collabWindow.clientId === clientId;\n\t\tif (\n\t\t\tisLocalPerspective &&\n\t\t\t(localSeq === undefined ||\n\t\t\t\t(localSeq === this.collabWindow.localSeq && refSeq >= this.collabWindow.currentSeq))\n\t\t) {\n\t\t\t// All changes are visible. Small note on why we allow refSeq >= this.collabWindow.currentSeq rather than just equality:\n\t\t\t// merge-tree eventing occurs before the collab window is updated to account for whatever op it is processing, and we want\n\t\t\t// to support resolving positions from within the event handler which account for that op. e.g. undo-redo relies on this\n\t\t\t// behavior with local references.\n\t\t\treturn node.cachedLength;\n\t\t}\n\n\t\tif (localSeq !== undefined) {\n\t\t\tthis.computeLocalPartials(refSeq);\n\t\t}\n\n\t\tconst length = node.partialLengths!.getPartialLength(refSeq, clientId, localSeq);\n\n\t\tPartialSequenceLengths.options.verifyExpected?.(this, node, refSeq, clientId, localSeq);\n\t\treturn length;\n\t}\n\n\tpublic setMinSeq(minSeq: number): void {\n\t\tassert(\n\t\t\tminSeq <= this.collabWindow.currentSeq,\n\t\t\t0x04e /* \"Trying to set minSeq above currentSeq of collab window!\" */,\n\t\t);\n\n\t\t// Only move forward\n\t\tassert(\n\t\t\tthis.collabWindow.minSeq <= minSeq,\n\t\t\t0x04f /* \"minSeq of collab window > target minSeq!\" */,\n\t\t);\n\n\t\tif (minSeq > this.collabWindow.minSeq) {\n\t\t\tthis.collabWindow.minSeq = minSeq;\n\t\t\tthis.obliterates.setMinSeq(minSeq);\n\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\tzamboniSegments(this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the count of elements before the given reference position from the given perspective.\n\t *\n\t * @param refPos - The reference position to resolve.\n\t * @param refSeq - The number of the latest sequenced change to consider.\n\t * Defaults to including all edits which have been applied.\n\t * @param clientId - The ID of the client from whose perspective to resolve this reference. Defaults to the current client.\n\t * @param localSeq - The local sequence number to consider. Defaults to including all local edits.\n\t */\n\tpublic referencePositionToLocalPosition(\n\t\trefPos: ReferencePosition,\n\t\t// Note: this is not `this.collabWindow.currentSeq` because we want to support resolving local reference positions to positions\n\t\t// from within event handlers, and the collab window's sequence numbers are not updated in time in all of those cases.\n\t\trefSeq = Number.MAX_SAFE_INTEGER,\n\t\tclientId = this.collabWindow.clientId,\n\t\tlocalSeq: number | undefined = undefined,\n\t): number {\n\t\tconst perspective =\n\t\t\tclientId === this.collabWindow.clientId\n\t\t\t\t? localSeq === undefined\n\t\t\t\t\t? this.localPerspective\n\t\t\t\t\t: new LocalReconnectingPerspective(refSeq, clientId, localSeq)\n\t\t\t\t: new PriorPerspective(refSeq, clientId);\n\t\tconst seg = refPos.getSegment();\n\t\tif (seg === undefined || !isSegmentLeaf(seg)) {\n\t\t\t// We have no idea where this reference is, because it refers to a segment which is not in the tree.\n\t\t\treturn DetachedReferencePosition;\n\t\t}\n\t\tif (refPos.isLeaf()) {\n\t\t\treturn this.getPosition(seg, perspective);\n\t\t}\n\t\tif (refTypeIncludesFlag(refPos, ReferenceType.Transient) || seg.localRefs?.has(refPos)) {\n\t\t\tif (\n\t\t\t\tseg !== this.startOfTree &&\n\t\t\t\tseg !== this.endOfTree &&\n\t\t\t\t!perspective.isSegmentPresent(seg)\n\t\t\t) {\n\t\t\t\tconst forward = refPos.slidingPreference === SlidingPreference.FORWARD;\n\t\t\t\tconst removeInfo = toRemovalInfo(seg);\n\t\t\t\tconst firstRemove = removeInfo?.removes[0];\n\t\t\t\tconst slideSeq =\n\t\t\t\t\tfirstRemove !== undefined && opstampUtils.isAcked(firstRemove)\n\t\t\t\t\t\t? firstRemove.seq\n\t\t\t\t\t\t: refSeq;\n\n\t\t\t\tconst slidePerspective =\n\t\t\t\t\tfirstRemove?.localSeq === undefined\n\t\t\t\t\t\t? new PriorPerspective(slideSeq, this.collabWindow.clientId)\n\t\t\t\t\t\t: new LocalReconnectingPerspective(\n\t\t\t\t\t\t\t\tslideSeq,\n\t\t\t\t\t\t\t\tthis.collabWindow.clientId,\n\t\t\t\t\t\t\t\tfirstRemove.localSeq,\n\t\t\t\t\t\t\t);\n\n\t\t\t\tconst slidSegment = this.nextSegment(slidePerspective, seg, forward);\n\t\t\t\treturn (\n\t\t\t\t\tthis.getPosition(slidSegment, perspective) +\n\t\t\t\t\t(forward ? 0 : slidSegment.cachedLength === 0 ? 0 : slidSegment.cachedLength - 1)\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.getPosition(seg, perspective) + refPos.getOffset();\n\t\t}\n\t\treturn DetachedReferencePosition;\n\t}\n\n\t/**\n\t * Returns the immediately adjacent segment in the specified direction from this perspective.\n\t * There may actually be multiple segments between the given segment and the returned segment,\n\t * but they were either inserted after this perspective, or have been removed before this perspective.\n\t *\n\t * @param segment - The segment to start from.\n\t * @param forward - The direction to search.\n\t * @returns the next segment in the specified direction, or the start or end of the tree if there is no next segment.\n\t */\n\tprivate nextSegment(\n\t\tperspective: Perspective,\n\t\tsegment: ISegmentLeaf,\n\t\tforward: boolean = true,\n\t): ISegmentLeaf {\n\t\tlet next: ISegmentLeaf | undefined;\n\t\tconst action = (seg: ISegmentLeaf): boolean | undefined => {\n\t\t\tif (perspective.isSegmentPresent(seg)) {\n\t\t\t\tnext = seg;\n\t\t\t\treturn LeafAction.Exit;\n\t\t\t}\n\t\t};\n\t\t(forward ? forwardExcursion : backwardExcursion)(segment, action);\n\t\treturn next ?? (forward ? this.endOfTree : this.startOfTree);\n\t}\n\n\t/**\n\t * Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `forwards`.\n\t * Uses depthFirstNodeWalk in addition to block-accelerated functionality. The search position will be included in\n\t * the nodes to walk, so searching on all positions, including the endpoints, can be considered inclusive.\n\t * Any out of bound search positions will return undefined, so in order to search the whole string, a forward\n\t * search can begin at 0, or a backward search can begin at length-1.\n\t *\n\t * @param startPos - Position at which to start the search\n\t * @param clientId - clientId dictating the perspective to search from\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the string should be searched in the forward or backward direction\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\tlet foundMarker: Marker | undefined;\n\n\t\tconst segoff = this.getContainingSegment(startPos, this.localPerspective);\n\t\tif (!isSegmentLeaf(segoff?.segment)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst { segment } = segoff;\n\n\t\tdepthFirstNodeWalk(\n\t\t\tsegment.parent,\n\t\t\tsegment,\n\t\t\t(node) => {\n\t\t\t\tif (node.isLeaf()) {\n\t\t\t\t\tif (!isRemoved(node) && Marker.is(node) && refHasTileLabel(node, markerLabel)) {\n\t\t\t\t\t\tfoundMarker = node;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst marker = forwards\n\t\t\t\t\t\t? node.leftmostTiles[markerLabel]\n\t\t\t\t\t\t: node.rightmostTiles[markerLabel];\n\t\t\t\t\tif (marker !== undefined) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tmarker.isLeaf() && Marker.is(marker),\n\t\t\t\t\t\t\t0x751 /* Object returned is not a valid marker */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tfoundMarker = marker;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn foundMarker === undefined ? NodeAction.Skip : NodeAction.Exit;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tforwards,\n\t\t);\n\n\t\treturn foundMarker;\n\t}\n\n\tprivate updateRoot(splitNode: MergeBlock): void {\n\t\tconst newRoot = this.makeBlock(2);\n\t\tassignChild(newRoot, this.root, 0, false);\n\t\tassignChild(newRoot, splitNode, 1, false);\n\t\tthis.root = newRoot;\n\t\tthis.nodeUpdateOrdinals(this.root);\n\t\tthis.nodeUpdateLengthNewStructure(this.root);\n\t}\n\n\t/**\n\t * Assign sequence number to existing segments affected by an op; update partial lengths to reflect the change\n\t */\n\tpublic ackOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tconst seq = opArgs.sequencedMessage!.sequenceNumber;\n\t\tconst stamp: OperationStamp = {\n\t\t\tseq,\n\t\t\tclientId: this.collabWindow.clientId,\n\t\t};\n\t\tconst pendingSegmentGroup = this.pendingSegments.shift()?.data;\n\t\tconst nodesToUpdate: MergeBlock[] = [];\n\t\tlet overwrite = false;\n\t\tif (pendingSegmentGroup !== undefined) {\n\t\t\tconst { obliterateInfo, segments } = pendingSegmentGroup;\n\t\t\tconst hasObliterateInfo = obliterateInfo !== undefined;\n\t\t\tconst isObliterate =\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED;\n\t\t\tassert(hasObliterateInfo === isObliterate, 0xa40 /* must have obliterate info */);\n\t\t\tif (hasObliterateInfo) {\n\t\t\t\tobliterateInfo.stamp = { ...stamp, type: \"sliceRemove\" };\n\t\t\t\tthis.obliterates.addOrUpdate(obliterateInfo);\n\t\t\t\tassert(\n\t\t\t\t\tobliterateInfo.tiebreakTrackingGroup !== undefined,\n\t\t\t\t\t0xb70 /* obliterateInfo should have a tiebreak tracking group on ack */,\n\t\t\t\t);\n\t\t\t\tfor (const segment of obliterateInfo.tiebreakTrackingGroup.tracked) {\n\t\t\t\t\tsegment.trackingCollection.unlink(obliterateInfo.tiebreakTrackingGroup);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tisSegmentLeaf(segment) && isInsideObliterate(segment),\n\t\t\t\t\t\t0xb71 /* Expected segment leaf inside obliterate */,\n\t\t\t\t\t);\n\t\t\t\t\tsegment.insertionRefSeqStamp = undefined;\n\t\t\t\t}\n\t\t\t\tobliterateInfo.tiebreakTrackingGroup = undefined;\n\t\t\t}\n\n\t\t\tconst deltaSegments: IMergeTreeSegmentDelta[] = [];\n\t\t\tconst overlappingRemoves: boolean[] = [];\n\t\t\tsegments.map((pendingSegment: ISegmentLeaf) => {\n\t\t\t\tconst overlappingRemove = !ackSegment(\n\t\t\t\t\tpendingSegment,\n\t\t\t\t\tpendingSegmentGroup,\n\t\t\t\t\topArgs,\n\t\t\t\t\tstamp,\n\t\t\t\t);\n\n\t\t\t\toverwrite ||= overlappingRemove;\n\n\t\t\t\toverlappingRemoves.push(overlappingRemove);\n\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\tthis.addToLRUSet(pendingSegment, seq);\n\t\t\t\t}\n\t\t\t\tif (!nodesToUpdate.includes(pendingSegment.parent)) {\n\t\t\t\t\tnodesToUpdate.push(pendingSegment.parent);\n\t\t\t\t}\n\t\t\t\tdeltaSegments.push({\n\t\t\t\t\tsegment: pendingSegment,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// Perform slides after all segments have been acked, so that\n\t\t\t// positions after slide are final\n\t\t\tif (\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.REMOVE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED\n\t\t\t) {\n\t\t\t\tthis.slideAckedRemovedSegmentReferences(segments);\n\t\t\t}\n\n\t\t\tthis.mergeTreeMaintenanceCallback?.(\n\t\t\t\t{\n\t\t\t\t\tdeltaSegments,\n\t\t\t\t\toperation: MergeTreeMaintenanceType.ACKNOWLEDGED,\n\t\t\t\t},\n\t\t\t\topArgs,\n\t\t\t);\n\n\t\t\tfor (const node of nodesToUpdate) {\n\t\t\t\tthis.blockUpdatePathLengths(node, stamp, overwrite);\n\t\t\t}\n\t\t}\n\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tprivate addToPendingList(\n\t\tsegment: ISegmentLeaf,\n\n\t\tsegmentGroup?: SegmentGroup,\n\t\tlocalSeq?: number,\n\t\tpreviousProps?: PropertySet,\n\t): SegmentGroup {\n\t\tlet _segmentGroup = segmentGroup;\n\t\tif (_segmentGroup === undefined) {\n\t\t\tassert(\n\t\t\t\tlocalSeq !== undefined,\n\t\t\t\t0xb72 /* Local seq should be passed when creating new segment group */,\n\t\t\t);\n\t\t\t_segmentGroup = {\n\t\t\t\tsegments: [],\n\t\t\t\tlocalSeq,\n\t\t\t\trefSeq: this.collabWindow.currentSeq,\n\t\t\t};\n\t\t\tif (previousProps) {\n\t\t\t\t_segmentGroup.previousProps = [];\n\t\t\t}\n\t\t\tthis.pendingSegments.push(_segmentGroup);\n\t\t}\n\n\t\tif (\n\t\t\t(!_segmentGroup.previousProps && !!previousProps) ||\n\t\t\t(!!_segmentGroup.previousProps && !previousProps)\n\t\t) {\n\t\t\tthrow new Error(\"All segments in group should have previousProps or none\");\n\t\t}\n\t\tif (previousProps) {\n\t\t\t_segmentGroup.previousProps!.push(previousProps);\n\t\t}\n\n\t\tconst segmentGroups = (segment.segmentGroups ??= new SegmentGroupCollection(segment));\n\t\tsegmentGroups.enqueue(_segmentGroup);\n\t\treturn _segmentGroup;\n\t}\n\n\t// TODO: error checking\n\tpublic getMarkerFromId(id: string): Marker | undefined {\n\t\tconst marker = this.idToMarker.get(id);\n\t\treturn marker === undefined || isRemoved(marker) ? undefined : marker;\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t * @param refseq - The reference sequence number at which to compute the position.\n\t * @param clientId - The client id with which to compute the position.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition, perspective: Perspective): number {\n\t\tlet pos = -1;\n\t\tlet marker: Marker | undefined;\n\t\tif (relativePos.id) {\n\t\t\tmarker = this.getMarkerFromId(relativePos.id);\n\t\t}\n\t\tif (isSegmentLeaf(marker)) {\n\t\t\tpos = this.getPosition(marker, perspective);\n\t\t\tif (relativePos.before) {\n\t\t\t\tif (relativePos.offset !== undefined) {\n\t\t\t\t\tpos -= relativePos.offset;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpos += marker.cachedLength;\n\t\t\t\tif (relativePos.offset !== undefined) {\n\t\t\t\t\tpos += relativePos.offset;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn pos;\n\t}\n\n\tpublic insertSegments(\n\t\tpos: number,\n\t\tsegments: ISegmentPrivate[],\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs | undefined,\n\t): void {\n\t\tconst stamp: InsertOperationStamp = { ...stampArg, type: \"insert\" };\n\t\tthis.ensureIntervalBoundary(pos, perspective);\n\n\t\tthis.blockInsert(pos, perspective, stamp, segments);\n\n\t\t// opArgs == undefined => loading snapshot or test code\n\t\tif (opArgs !== undefined) {\n\t\t\tconst deltaSegments = segments\n\t\t\t\t.filter((segment) => !isRemoved(segment))\n\t\t\t\t.map((segment) => ({ segment }));\n\n\t\t\tif (deltaSegments.length > 0) {\n\t\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\t\t\tdeltaSegments,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\tMergeTree.options.zamboniSegments &&\n\t\t\topstampUtils.isAcked(stamp)\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: number,\n\t): number | undefined {\n\t\tif (remoteClientRefSeq < this.collabWindow.minSeq) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst remotePerspective = new PriorPerspective(remoteClientRefSeq, remoteClientId);\n\t\tconst segmentInfo = this.getContainingSegment(remoteClientPosition, remotePerspective);\n\n\t\tif (isSegmentLeaf(segmentInfo?.segment)) {\n\t\t\tconst segmentPosition = this.getPosition(segmentInfo.segment, this.localPerspective);\n\t\t\treturn segmentPosition + segmentInfo.offset;\n\t\t} else {\n\t\t\tif (remoteClientPosition === this.getLength(remotePerspective)) {\n\t\t\t\treturn this.getLength(this.localPerspective);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate blockInsert<T extends ISegmentPrivate>(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: InsertOperationStamp,\n\t\tnewSegments: T[],\n\t): void {\n\t\t// Keeping this function within the scope of blockInsert for readability.\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst continueFrom = (node: MergeBlock): boolean => {\n\t\t\tlet siblingExists = false;\n\t\t\tforwardExcursion(node, () => {\n\t\t\t\tsiblingExists = true;\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\treturn siblingExists;\n\t\t};\n\n\t\tlet segmentGroup: SegmentGroup;\n\t\tconst saveIfLocal = (locSegment: ISegmentLeaf): void => {\n\t\t\t// Save segment so we can assign sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(locSegment.insert) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(locSegment, segmentGroup, stamp.localSeq);\n\t\t\t\t}\n\t\t\t\t// LocSegment.seq === 0 when coming from SharedSegmentSequence.loadBody()\n\t\t\t\t// In all other cases this has to be true (checked by addToLRUSet):\n\t\t\t\t// locSegment.seq > this.collabWindow.currentSeq\n\t\t\t\telse if (\n\t\t\t\t\tMergeTree.options.zamboniSegments &&\n\t\t\t\t\topstampUtils.greaterThan(locSegment.insert, getMinSeqStamp(this.collabWindow))\n\t\t\t\t) {\n\t\t\t\t\tthis.addToLRUSet(locSegment, locSegment.insert.seq);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst onLeaf = (\n\t\t\tsegment: ISegmentLeaf | undefined,\n\t\t\t_pos: number,\n\t\t\tcontext: InsertContext,\n\t\t\t// Keeping this function within the scope of blockInsert for readability.\n\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\t): ISegmentChanges => {\n\t\t\tconst segmentChanges: ISegmentChanges = {};\n\t\t\tif (segment) {\n\t\t\t\t// Insert before segment\n\t\t\t\tsegmentChanges.replaceCurrent = context.candidateSegment;\n\t\t\t\tsegmentChanges.next = segment;\n\t\t\t} else {\n\t\t\t\tsegmentChanges.next = context.candidateSegment;\n\t\t\t}\n\t\t\treturn segmentChanges;\n\t\t};\n\n\t\t// TODO: build tree from segs and insert all at once\n\t\tlet insertPos = pos;\n\t\tfor (const newSegment of newSegments\n\t\t\t.filter((s) => s.cachedLength > 0)\n\t\t\t.map((s) => overwriteInfo(s, { insert: stamp }))) {\n\t\t\tif (Marker.is(newSegment)) {\n\t\t\t\tconst markerId = newSegment.getId();\n\t\t\t\tif (markerId) {\n\t\t\t\t\tthis.idToMarker.set(markerId, newSegment);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.insertingWalk(insertPos, perspective, stamp, {\n\t\t\t\tleaf: onLeaf,\n\t\t\t\tcandidateSegment: newSegment,\n\t\t\t\tcontinuePredicate: continueFrom,\n\t\t\t});\n\n\t\t\tif (!isSegmentLeaf(newSegment)) {\n\t\t\t\t// Indicates an attempt to insert past the end of the merge-tree's content.\n\t\t\t\tconst errorConstructor =\n\t\t\t\t\tstamp.localSeq === undefined ? DataProcessingError : UsageError;\n\t\t\t\tthrow new errorConstructor(\"MergeTree insert failed\", {\n\t\t\t\t\tcurrentSeq: this.collabWindow.currentSeq,\n\t\t\t\t\tminSeq: this.collabWindow.minSeq,\n\t\t\t\t\tsegSeq: stamp.seq,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tinsertPos += newSegment.cachedLength;\n\n\t\t\tif (!this.options?.mergeTreeEnableObliterate || this.obliterates.empty()) {\n\t\t\t\tsaveIfLocal(newSegment);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst refSeqStamp: OperationStamp = {\n\t\t\t\tseq: perspective.refSeq,\n\t\t\t\tclientId: stamp.clientId,\n\t\t\t};\n\n\t\t\tconst overlappingAckedObliterates: RemoveOperationStamp[] = [];\n\t\t\tlet oldest: ObliterateInfo | undefined;\n\t\t\tlet newest: ObliterateInfo | undefined;\n\t\t\tlet newestAcked: ObliterateInfo | undefined;\n\t\t\tlet oldestUnacked: ObliterateInfo | undefined;\n\n\t\t\tfor (const ob of this.obliterates.findOverlapping(newSegment)) {\n\t\t\t\tif (opstampUtils.greaterThan(ob.stamp, refSeqStamp)) {\n\t\t\t\t\t// Any obliterate from the same client that's inserting this segment cannot cause the segment to be marked as\n\t\t\t\t\t// obliterated (since that client must have performed the obliterate before this insertion).\n\t\t\t\t\t// We still need to consider such obliterates when determining the winning obliterate for the insertion point,\n\t\t\t\t\t// see `obliteratePrecedingInsertion` docs.\n\t\t\t\t\tif (stamp.clientId !== ob.stamp.clientId) {\n\t\t\t\t\t\tif (opstampUtils.isAcked(ob.stamp)) {\n\t\t\t\t\t\t\toverlappingAckedObliterates.push(ob.stamp);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (oldest === undefined || opstampUtils.lessThan(ob.stamp, oldest.stamp)) {\n\t\t\t\t\t\t\toldest = ob;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (newest === undefined || opstampUtils.greaterThan(ob.stamp, newest.stamp)) {\n\t\t\t\t\t\tnewest = ob;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\topstampUtils.isAcked(ob.stamp) &&\n\t\t\t\t\t\t(newestAcked === undefined ||\n\t\t\t\t\t\t\topstampUtils.greaterThan(ob.stamp, newestAcked.stamp))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewestAcked = ob;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\topstampUtils.isLocal(ob.stamp) &&\n\t\t\t\t\t\t(oldestUnacked === undefined ||\n\t\t\t\t\t\t\topstampUtils.greaterThan(oldestUnacked.stamp, ob.stamp))\n\t\t\t\t\t) {\n\t\t\t\t\t\t// There can be one local obliterate surrounding a segment if a client repeatedly obliterates\n\t\t\t\t\t\t// a region (ex: in the text ABCDEFG, obliterate D, then obliterate CE, then BF). In this case,\n\t\t\t\t\t\t// the first one that's applied will be the one that actually removes the segment.\n\t\t\t\t\t\toldestUnacked = ob;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(newSegment, {\n\t\t\t\tobliteratePrecedingInsertion: newest,\n\t\t\t});\n\t\t\tif (newest !== undefined && opstampUtils.isLocal(newest.stamp)) {\n\t\t\t\tassert(\n\t\t\t\t\tnewest?.tiebreakTrackingGroup !== undefined,\n\t\t\t\t\t0xb73 /* Expected local obliterateinfo to have tiebreak group */,\n\t\t\t\t);\n\t\t\t\tnewest.tiebreakTrackingGroup.link(newSegment);\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(newSegment, {\n\t\t\t\t\tinsertionRefSeqStamp: refSeqStamp,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// See doc comment on obliteratePrecedingInsertion for more details: if the newest obliterate was performed\n\t\t\t// by the same client that's inserting this segment, we let them insert into this range and therefore don't\n\t\t\t// mark it obliterated.\n\t\t\tif (oldest && newest?.stamp.clientId !== stamp.clientId) {\n\t\t\t\tconst removeInfo: IHasRemovalInfo = { removes: [] };\n\t\t\t\tif (newestAcked === newest || newestAcked?.stamp.clientId !== stamp.clientId) {\n\t\t\t\t\tremoveInfo.removes = overlappingAckedObliterates;\n\t\t\t\t\t// Because we found these by looking at overlapping obliterates, they are not necessarily currently sorted by seq.\n\t\t\t\t\t// Address that now.\n\t\t\t\t\tremoveInfo.removes.sort(opstampUtils.compare);\n\t\t\t\t}\n\n\t\t\t\t// Note that we don't need to worry about preserving any existing remove information since the segment is new.\n\t\t\t\toverwriteInfo(newSegment, removeInfo);\n\n\t\t\t\tif (oldestUnacked !== undefined) {\n\t\t\t\t\tremoveInfo.removes.push(oldestUnacked.stamp);\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\toldestUnacked.segmentGroup !== undefined,\n\t\t\t\t\t\t0x86c /* expected segment group to exist */,\n\t\t\t\t\t);\n\n\t\t\t\t\tthis.addToPendingList(newSegment, oldestUnacked.segmentGroup);\n\t\t\t\t}\n\n\t\t\t\tif (newSegment.parent) {\n\t\t\t\t\t// The incremental update codepath in theory can handle most cases where segments are obliterated upon insertion,\n\t\t\t\t\t// but it's not idempotent with respect to segment insertion in the first place. Since we already update partial\n\t\t\t\t\t// lengths inside the inserting walk, we'd be at risk of double-counting the insertion in any case if we allow\n\t\t\t\t\t// incremental updates here.\n\t\t\t\t\tconst newStructure = true;\n\t\t\t\t\tthis.blockUpdatePathLengths(newSegment.parent, removeInfo.removes[0], newStructure);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsaveIfLocal(newSegment);\n\t\t}\n\t}\n\n\tprivate computeObliteratePrecedingInsertion(\n\t\tsegment: ISegmentLeaf,\n\t\trefSeqStamp: OperationStamp,\n\t): ObliterateInfo | undefined {\n\t\tlet newest: ObliterateInfo | undefined;\n\t\tfor (const ob of this.obliterates.findOverlapping(segment)) {\n\t\t\tif (\n\t\t\t\topstampUtils.greaterThan(ob.stamp, refSeqStamp) &&\n\t\t\t\t(newest === undefined || opstampUtils.greaterThan(ob.stamp, newest.stamp))\n\t\t\t) {\n\t\t\t\tnewest = ob;\n\t\t\t}\n\t\t}\n\t\treturn newest;\n\t}\n\n\tprivate readonly splitLeafSegment = (\n\t\tsegment: ISegmentLeaf | undefined,\n\t\tpos: number,\n\t): ISegmentChanges => {\n\t\tif (!(pos > 0 && segment)) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst next = segment.splitAt(pos)!;\n\t\tassertSegmentLeaf(next);\n\n\t\tif (segment?.segmentGroups) {\n\t\t\tnext.segmentGroups ??= new SegmentGroupCollection(next);\n\t\t\tsegment.segmentGroups.copyTo(next.segmentGroups);\n\t\t}\n\n\t\tcopyPropertiesAndManager(segment, next);\n\t\tsegment.localRefs?.split(pos, next);\n\n\t\tthis.mergeTreeMaintenanceCallback?.(\n\t\t\t{\n\t\t\t\toperation: MergeTreeMaintenanceType.SPLIT,\n\t\t\t\tdeltaSegments: [{ segment }, { segment: next }],\n\t\t\t},\n\t\t\tundefined,\n\t\t);\n\n\t\treturn { next };\n\t};\n\n\tprivate ensureIntervalBoundary(pos: number, perspective: Perspective): void {\n\t\tthis.insertingWalk(\n\t\t\tpos,\n\t\t\tperspective,\n\t\t\t{\n\t\t\t\tseq: TreeMaintenanceSequenceNumber,\n\t\t\t\tclientId: perspective.clientId,\n\t\t\t},\n\t\t\t{ leaf: this.splitLeafSegment },\n\t\t);\n\t}\n\n\t// Assume called only when pos == len\n\tprivate breakTie(pos: number, node: IMergeNode, insertStamp: OperationStamp): boolean {\n\t\tif (node.isLeaf()) {\n\t\t\tif (pos !== 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\topstampUtils.greaterThan(insertStamp, node.insert) ||\n\t\t\t\t(isRemoved(node) &&\n\t\t\t\t\topstampUtils.isAcked(node.removes[0]) &&\n\t\t\t\t\topstampUtils.greaterThan(node.removes[0], insertStamp))\n\t\t\t);\n\t\t} else {\n\t\t\treturn true;\n\t\t}\n\t}\n\tprivate insertingWalk(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\tcontext: InsertContext,\n\t): void {\n\t\tconst { remainder } = this.insertRecursive(\n\t\t\tthis.root,\n\t\t\tpos,\n\t\t\tperspective,\n\t\t\tstamp,\n\t\t\tcontext,\n\t\t\ttrue,\n\t\t);\n\t\tif (remainder !== undefined) {\n\t\t\tthis.updateRoot(remainder);\n\t\t}\n\t}\n\n\tprivate insertRecursive(\n\t\tblock: MergeBlock,\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\tcontext: InsertContext,\n\t\tisLastBlock: boolean,\n\t): InsertResult {\n\t\tlet _pos: number = pos;\n\n\t\tconst children = block.children;\n\t\tlet childIndex: number;\n\t\tlet child: IMergeNode;\n\t\tlet newNode: IMergeNodeBuilder | undefined;\n\t\tlet fromSplit: MergeBlock | undefined;\n\t\tlet hadChanges = false;\n\t\tfor (childIndex = 0; childIndex < block.childCount; childIndex++) {\n\t\t\tchild = children[childIndex];\n\t\t\t// removed blocks below the min seq will have an undefined length, and be skipped\n\t\t\t// however if it is the last block in the layer of the tree we don't want to skip it, so we correctly\n\t\t\t// walk down the far edge of the tree.\n\t\t\tconst isLastChildOfLastBlock = isLastBlock && childIndex === block.childCount - 1;\n\t\t\tconst len =\n\t\t\t\tthis.nodeLength(child, perspective) ?? (isLastChildOfLastBlock ? 0 : undefined);\n\n\t\t\tif (len === undefined) {\n\t\t\t\t// if the seg len is undefined, the segment\n\t\t\t\t// will be removed, so should just be skipped for now\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tassert(len >= 0, 0x4bc /* Length should not be negative */);\n\n\t\t\tif (_pos < len || (_pos === len && this.breakTie(_pos, child, stamp))) {\n\t\t\t\t// Found entry containing pos\n\t\t\t\tif (child.isLeaf()) {\n\t\t\t\t\tconst segment = child;\n\t\t\t\t\tconst segmentChanges = context.leaf(segment, _pos, context);\n\t\t\t\t\tif (segmentChanges.replaceCurrent) {\n\t\t\t\t\t\thadChanges = true;\n\t\t\t\t\t\tassignChild(block, segmentChanges.replaceCurrent, childIndex, false);\n\t\t\t\t\t\tsegmentChanges.replaceCurrent.ordinal = child.ordinal;\n\t\t\t\t\t}\n\t\t\t\t\tif (segmentChanges.next) {\n\t\t\t\t\t\thadChanges = true;\n\t\t\t\t\t\tnewNode = segmentChanges.next;\n\t\t\t\t\t\tchildIndex++; // Insert after\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { remainder: undefined, hadChanges };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Internal node\n\t\t\t\t\tconst insertResult = this.insertRecursive(\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\t_pos,\n\t\t\t\t\t\tperspective,\n\t\t\t\t\t\tstamp,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tisLastChildOfLastBlock,\n\t\t\t\t\t);\n\t\t\t\t\thadChanges ||= insertResult.hadChanges;\n\t\t\t\t\tif (insertResult.remainder === undefined) {\n\t\t\t\t\t\tif (insertResult.hadChanges) {\n\t\t\t\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn insertResult;\n\t\t\t\t\t} else if (insertResult.remainder === MergeTree.theUnfinishedNode) {\n\t\t\t\t\t\t_pos -= len; // Act as if shifted segment\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewNode = insertResult.remainder;\n\t\t\t\t\t\tfromSplit = insertResult.remainder;\n\t\t\t\t\t\tchildIndex++; // Insert after\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t_pos -= len;\n\t\t\t}\n\t\t}\n\t\tif (!newNode && _pos === 0) {\n\t\t\tif (context.continuePredicate?.(block)) {\n\t\t\t\treturn { remainder: MergeTree.theUnfinishedNode, hadChanges };\n\t\t\t} else {\n\t\t\t\tconst segmentChanges = context.leaf(undefined, _pos, context);\n\t\t\t\tnewNode = segmentChanges.next;\n\t\t\t\t// Assert segmentChanges.replaceCurrent === undefined\n\t\t\t}\n\t\t}\n\t\tif (newNode) {\n\t\t\thadChanges = true;\n\t\t\tfor (let i = block.childCount; i > childIndex; i--) {\n\t\t\t\tblock.children[i] = block.children[i - 1];\n\t\t\t\tblock.children[i].index = i;\n\t\t\t}\n\t\t\tassignChild(block, newNode, childIndex, false);\n\t\t\tblock.childCount++;\n\t\t\tblock.setOrdinal(newNode, childIndex);\n\t\t\tif (block.childCount < MaxNodesInBlock) {\n\t\t\t\tif (fromSplit) {\n\t\t\t\t\tthis.nodeUpdateOrdinals(fromSplit);\n\t\t\t\t}\n\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t\treturn { remainder: undefined, hadChanges };\n\t\t\t} else {\n\t\t\t\t// Don't update ordinals because higher block will do it\n\t\t\t\tconst newNodeFromSplit = this.split(block);\n\n\t\t\t\tPartialSequenceLengths.options.verifyExpected?.(\n\t\t\t\t\tthis,\n\t\t\t\t\tblock,\n\t\t\t\t\tperspective.refSeq,\n\t\t\t\t\tstamp.clientId,\n\t\t\t\t);\n\t\t\t\tPartialSequenceLengths.options.verifyExpected?.(\n\t\t\t\t\tthis,\n\t\t\t\t\tnewNodeFromSplit,\n\t\t\t\t\tperspective.refSeq,\n\t\t\t\t\tstamp.clientId,\n\t\t\t\t);\n\n\t\t\t\treturn { remainder: newNodeFromSplit, hadChanges };\n\t\t\t}\n\t\t} else {\n\t\t\treturn { remainder: undefined, hadChanges };\n\t\t}\n\t}\n\n\tprivate split(node: MergeBlock): MergeBlock {\n\t\tconst halfCount = MaxNodesInBlock / 2;\n\t\tconst newNode = this.makeBlock(halfCount);\n\t\tnode.childCount = halfCount;\n\t\t// Update ordinals to reflect lowered child count\n\t\tthis.nodeUpdateOrdinals(node);\n\t\tfor (let i = 0; i < halfCount; i++) {\n\t\t\tassignChild(newNode, node.children[halfCount + i], i, false);\n\t\t\tnode.children[halfCount + i] = undefined!;\n\t\t}\n\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\tthis.nodeUpdateLengthNewStructure(newNode);\n\t\treturn newNode;\n\t}\n\n\tpublic nodeUpdateOrdinals(block: MergeBlock): void {\n\t\tfor (let i = 0; i < block.childCount; i++) {\n\t\t\tconst child = block.children[i];\n\t\t\tblock.setOrdinal(child, i);\n\t\t\tif (!child.isLeaf()) {\n\t\t\t\tthis.nodeUpdateOrdinals(child);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Annotate a range with properties\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param propsOrAdjust - The properties or adjustments to annotate the range with\n\t * @param refSeq - The reference sequence number to use to apply the annotate\n\t * @param clientId - The id of the client making the annotate\n\t * @param seq - The sequence number of the annotate operation\n\t * @param opArgs - The op args for the annotate op. this is passed to the merge tree callback if there is one\n\t */\n\tpublic annotateRange(\n\t\tstart: number,\n\t\tend: number,\n\t\tpropsOrAdjust: PropsOrAdjust,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tif (propsOrAdjust.adjust !== undefined) {\n\t\t\terrorIfOptionNotTrue(this.options, \"mergeTreeEnableAnnotateAdjust\");\n\t\t}\n\n\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\tthis.ensureIntervalBoundary(end, perspective);\n\t\tconst deltaSegments: IMergeTreeSegmentDelta[] = [];\n\n\t\tlet segmentGroup: SegmentGroup | undefined;\n\t\tconst opObj = propsOrAdjust.props ?? propsOrAdjust.adjust;\n\t\tconst annotateSegment = (segment: ISegmentLeaf): boolean => {\n\t\t\tassert(\n\t\t\t\t!Marker.is(segment) ||\n\t\t\t\t\t!(reservedMarkerIdKey in opObj) ||\n\t\t\t\t\topObj.markerId === segment.properties?.markerId,\n\t\t\t\t0x5ad /* Cannot change the markerId of an existing marker */,\n\t\t\t);\n\n\t\t\tconst propertyManager = (segment.propertyManager ??= new PropertiesManager());\n\t\t\tconst propertyDeltas = propertyManager.handleProperties(\n\t\t\t\tpropsOrAdjust,\n\t\t\t\tsegment,\n\t\t\t\tstamp.seq,\n\t\t\t\tthis.collabWindow.minSeq,\n\t\t\t\tthis.collabWindow.collaborating,\n\t\t\t\topArgs?.rollback === true,\n\t\t\t);\n\n\t\t\tif (!isRemoved(segment)) {\n\t\t\t\tdeltaSegments.push({ segment, propertyDeltas });\n\t\t\t}\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (opstampUtils.isLocal(stamp)) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tsegmentGroup,\n\t\t\t\t\t\tstamp.localSeq,\n\t\t\t\t\t\tpropertyDeltas,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.nodeMap(perspective, annotateSegment, undefined, start, end);\n\n\t\t// OpArgs == undefined => test code\n\t\tif (deltaSegments.length > 0) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\tdeltaSegments,\n\t\t\t});\n\t\t}\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tprivate obliterateRangeSided(\n\t\tstart: InteriorSequencePlace,\n\t\tend: InteriorSequencePlace,\n\t\tperspective: Perspective,\n\t\tstamp: SliceRemoveOperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tconst startPos = start.side === Side.Before ? start.pos : start.pos + 1;\n\t\tconst endPos = end.side === Side.Before ? end.pos : end.pos + 1;\n\n\t\tthis.ensureIntervalBoundary(startPos, perspective);\n\t\tthis.ensureIntervalBoundary(endPos, perspective);\n\n\t\tlet _overwrite = false;\n\t\tconst localOverlapWithRefs: ISegmentLeaf[] = [];\n\t\tconst removedSegments: SegmentWithInfo<IHasRemovalInfo, ISegmentLeaf>[] = [];\n\n\t\tconst createRefFromSequencePlace = (\n\t\t\tplace: InteriorSequencePlace,\n\t\t): LocalReferencePosition => {\n\t\t\tconst segOff = this.getContainingSegment(place.pos, perspective);\n\t\t\tassert(isSegmentLeaf(segOff?.segment), 0xa3f /* segments cannot be undefined */);\n\t\t\tconst { segment: placeSeg, offset: placeOffset } = segOff;\n\t\t\treturn this.createLocalReferencePosition(\n\t\t\t\tplaceSeg,\n\t\t\t\tplaceOffset,\n\t\t\t\tReferenceType.StayOnRemove,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\tconst obliterate: ObliterateInfo = {\n\t\t\tstart: createRefFromSequencePlace(start),\n\t\t\tstartSide: start.side,\n\t\t\tend: createRefFromSequencePlace(end),\n\t\t\tendSide: end.side,\n\t\t\trefSeq: perspective.refSeq,\n\t\t\tstamp,\n\t\t\tsegmentGroup: undefined,\n\t\t\ttiebreakTrackingGroup: undefined,\n\t\t};\n\t\t// Link references back to this obliterate info\n\t\tobliterate.start.addProperties({ obliterate });\n\t\tobliterate.end.addProperties({ obliterate });\n\n\t\tif (this.collabWindow.collaborating && stamp.clientId === this.collabWindow.clientId) {\n\t\t\t// Always create a segment group for local obliterates,\n\t\t\t// even if there are no segments currently in the obliteration range.\n\t\t\t// Segments may be concurrently inserted into the obliteration range,\n\t\t\t// at which point they are added to the segment group.\n\t\t\tobliterate.segmentGroup = {\n\t\t\t\tsegments: [],\n\t\t\t\tlocalSeq: stamp.localSeq,\n\t\t\t\trefSeq: this.collabWindow.currentSeq,\n\t\t\t\tobliterateInfo: obliterate,\n\t\t\t};\n\t\t\tobliterate.tiebreakTrackingGroup = new UnorderedTrackingGroup();\n\t\t\tthis.pendingSegments.push(obliterate.segmentGroup);\n\t\t}\n\t\tthis.obliterates.addOrUpdate(obliterate);\n\n\t\tconst markRemoved = (segment: ISegmentLeaf, pos: number): boolean => {\n\t\t\tif (\n\t\t\t\t(start.side === Side.After && startPos === pos + segment.cachedLength) || // exclusive start segment\n\t\t\t\t(end.side === Side.Before && endPos === pos && perspective.isSegmentPresent(segment)) // exclusive end segment\n\t\t\t) {\n\t\t\t\t// We walk these segments because we want to also walk any concurrently inserted segments between here and the obliterated segments.\n\t\t\t\t// These segments are outside of the obliteration range though, so return true to keep walking.\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst existingRemoveInfo = toRemovalInfo(segment);\n\n\t\t\t// The \"last-to-obliterate-gets-to-insert\" policy described by the doc comment on `obliteratePrecedingInsertion`\n\t\t\t// is mostly handled by logic at insertion time, but we need a small bit of handling here.\n\t\t\t// Specifically, we want to avoid marking a local-only segment as obliterated when we know one of our own local obliterates\n\t\t\t// will win against the obliterate we're processing, hence the early exit.\n\t\t\tif (\n\t\t\t\topstampUtils.isLocal(segment.insert) &&\n\t\t\t\tisInsideObliterate(segment) &&\n\t\t\t\tsegment.obliteratePrecedingInsertion?.stamp.seq === UnassignedSequenceNumber &&\n\t\t\t\topstampUtils.isAcked(stamp)\n\t\t\t) {\n\t\t\t\t// We chose to not obliterate this segment because we are aware of an unacked local obliteration.\n\t\t\t\t// The local obliterate has not been sequenced yet, so it is still the newest obliterate we are aware of.\n\t\t\t\t// Other clients will also choose not to obliterate this segment because the most recent obliteration has the same clientId\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Partial lengths incrementality is not supported for overlapping obliterate/removes.\n\t\t\t_overwrite ||= existingRemoveInfo !== undefined;\n\n\t\t\t// - Record the segment as removed\n\t\t\t// - If this was the first thing to remove the segment from the local view, add it to removedSegments\n\t\t\t// - Otherwise, if it was the first thing to remove the segment from the acked view, add it to localOverlapWithRefs (so we can slide them)\n\t\t\tif (existingRemoveInfo === undefined) {\n\t\t\t\tconst removed = overwriteInfo<IHasRemovalInfo, ISegmentLeaf>(segment, {\n\t\t\t\t\tremoves: [stamp],\n\t\t\t\t});\n\n\t\t\t\tremovedSegments.push(removed);\n\t\t\t} else {\n\t\t\t\t// The segment has already been removed, so we don't need to add it to removedSegments. However,\n\t\t\t\t// if it's only been removed locally, we still need to slide any references that may exist on it.\n\t\t\t\tif (\n\t\t\t\t\t!opstampUtils.hasAnyAckedOperation(existingRemoveInfo.removes) &&\n\t\t\t\t\tsegment.localRefs?.empty === false\n\t\t\t\t) {\n\t\t\t\t\tlocalOverlapWithRefs.push(segment);\n\t\t\t\t}\n\t\t\t\topstampUtils.spliceIntoList(existingRemoveInfo.removes, stamp);\n\t\t\t}\n\t\t\tassertRemoved(segment);\n\t\t\t// Save segment so can assign sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(segment.removes[0]) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tobliterate.segmentGroup = this.addToPendingList(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tobliterate.segmentGroup,\n\t\t\t\t\t\tstamp.localSeq,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tconst afterMarkRemoved = (node: MergeBlock): boolean => {\n\t\t\tif (_overwrite) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(node, stamp);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.nodeMap(\n\t\t\tperspective,\n\t\t\tmarkRemoved,\n\t\t\tafterMarkRemoved,\n\t\t\tstart.pos,\n\t\t\tend.pos + 1, // include the segment containing the end reference\n\t\t\t// Use a visibilityPerspective which includes all segments (including local ones) which are in the obliteration range.\n\t\t\t// This ensures that concurrently inserted segments will also be marked obliterated.\n\t\t\topstampUtils.isLocal(stamp)\n\t\t\t\t? perspective\n\t\t\t\t: new RemoteObliteratePerspective(stamp.clientId),\n\t\t);\n\n\t\tthis.slideAckedRemovedSegmentReferences(localOverlapWithRefs);\n\t\t// opArgs == undefined => test code\n\t\tif (start.pos !== end.pos || start.side !== end.side) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.OBLITERATE,\n\t\t\t\tdeltaSegments: removedSegments.map((segment) => ({ segment })),\n\t\t\t});\n\t\t}\n\n\t\t// these events are newly removed\n\t\t// so we slide after eventing in case the consumer wants to make reference\n\t\t// changes at remove time, like add a ref to track undo redo.\n\t\tif (!this.collabWindow.collaborating || stamp.clientId !== this.collabWindow.clientId) {\n\t\t\tthis.slideAckedRemovedSegmentReferences(removedSegments);\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tpublic obliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\terrorIfOptionNotTrue(this.options, \"mergeTreeEnableObliterate\");\n\t\tconst stamp: SliceRemoveOperationStamp = { ...stampArg, type: \"sliceRemove\" };\n\t\tif (this.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"object\" && typeof end === \"object\",\n\t\t\t\t0xa45 /* Start and end must be of type InteriorSequencePlace if mergeTreeEnableSidedObliterate is enabled. */,\n\t\t\t);\n\t\t\tthis.obliterateRangeSided(start, end, perspective, stamp, opArgs);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"number\" && typeof end === \"number\",\n\t\t\t\t0xa46 /* Start and end must be numbers if mergeTreeEnableSidedObliterate is not enabled. */,\n\t\t\t);\n\t\t\tthis.obliterateRangeSided(\n\t\t\t\t{ pos: start, side: Side.Before },\n\t\t\t\t{ pos: end - 1, side: Side.After },\n\t\t\t\tperspective,\n\t\t\t\tstamp,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic markRangeRemoved(\n\t\tstart: number,\n\t\tend: number,\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tlet _overwrite = false;\n\t\tconst stamp: SetRemoveOperationStamp = { ...stampArg, type: \"setRemove\" };\n\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\tthis.ensureIntervalBoundary(end, perspective);\n\n\t\tlet segmentGroup: SegmentGroup;\n\t\tconst removedSegments: SegmentWithInfo<IHasRemovalInfo, ISegmentLeaf>[] = [];\n\t\tconst localOverlapWithRefs: ISegmentLeaf[] = [];\n\n\t\tconst markRemoved = (\n\t\t\tsegment: ISegmentLeaf,\n\t\t\tpos: number,\n\t\t\t_start: number,\n\t\t\t_end: number,\n\t\t): boolean => {\n\t\t\tconst existingRemovalInfo = toRemovalInfo(segment);\n\n\t\t\t// Partial lengths incrementality is not supported for overlapping obliterate/removes.\n\t\t\t_overwrite ||= existingRemovalInfo !== undefined;\n\t\t\tif (existingRemovalInfo === undefined) {\n\t\t\t\tconst removed = overwriteInfo<IHasRemovalInfo, ISegmentLeaf>(segment, {\n\t\t\t\t\tremoves: [stamp],\n\t\t\t\t});\n\n\t\t\t\tremovedSegments.push(removed);\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\t!opstampUtils.hasAnyAckedOperation(existingRemovalInfo.removes) &&\n\t\t\t\t\tsegment.localRefs?.empty === false\n\t\t\t\t) {\n\t\t\t\t\tlocalOverlapWithRefs.push(segment);\n\t\t\t\t}\n\t\t\t\topstampUtils.spliceIntoList(existingRemovalInfo.removes, stamp);\n\t\t\t}\n\t\t\tassertRemoved(segment);\n\n\t\t\t// Save segment so we can assign removed sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(segment.removes[0]) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(segment, segmentGroup, stamp.localSeq);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tconst afterMarkRemoved = (node: MergeBlock): boolean => {\n\t\t\tif (_overwrite) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(node, stamp);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tthis.nodeMap(perspective, markRemoved, afterMarkRemoved, start, end);\n\t\t// these segments are already viewed as being removed locally and are not event-ed\n\t\t// so can slide non-StayOnRemove refs immediately\n\t\tthis.slideAckedRemovedSegmentReferences(localOverlapWithRefs);\n\t\t// opArgs == undefined => test code\n\t\tif (removedSegments.length > 0) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.REMOVE,\n\t\t\t\tdeltaSegments: removedSegments.map((segment) => ({ segment })),\n\t\t\t});\n\t\t}\n\t\t// these events are newly removed\n\t\t// so we slide after eventing in case the consumer wants to make reference\n\t\t// changes at remove time, like add a ref to track undo redo.\n\t\tif (!this.collabWindow.collaborating || stamp.clientId !== this.collabWindow.clientId) {\n\t\t\tthis.slideAckedRemovedSegmentReferences(removedSegments);\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\t/**\n\t * Revert an unacked local op\n\t */\n\tpublic rollback(op: IMergeTreeOp, localOpMetadata: SegmentGroup | SegmentGroup[]): void {\n\t\tif (op.type === MergeTreeDeltaType.GROUP) {\n\t\t\tassert(Array.isArray(localOpMetadata), 0xbe2 /* metadata must be array for group ops */);\n\t\t\tfor (let i = op.ops.length - 1; i >= 0; i--) {\n\t\t\t\tthis.rollback(op.ops[i], localOpMetadata[i]);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst rollbackStamp: OperationStamp = {\n\t\t\tseq: TreeMaintenanceSequenceNumber,\n\t\t\tclientId: NonCollabClient,\n\t\t};\n\t\tif (op.type === MergeTreeDeltaType.REMOVE) {\n\t\t\tconst pendingSegmentGroup = this.pendingSegments.pop()?.data;\n\t\t\tif (pendingSegmentGroup === undefined || pendingSegmentGroup !== localOpMetadata) {\n\t\t\t\tthrow new Error(\"Rollback op doesn't match last edit\");\n\t\t\t}\n\t\t\t// Disabling because a for of loop causes the type of segment to be ISegmentLeaf, which does not have parent information stored\n\t\t\t// eslint-disable-next-line unicorn/no-array-for-each\n\t\t\tpendingSegmentGroup.segments.forEach((segment: ISegmentLeaf) => {\n\t\t\t\tconst segmentSegmentGroup = segment?.segmentGroups?.pop();\n\t\t\t\tassert(\n\t\t\t\t\tsegmentSegmentGroup === pendingSegmentGroup,\n\t\t\t\t\t0x3ee /* Unexpected segmentGroup in segment */,\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tisRemoved(segment) && segment.removes[0].type === \"setRemove\",\n\t\t\t\t\t0x39d /* Rollback segment removedClientId does not match local client */,\n\t\t\t\t);\n\t\t\t\t// if a peer client concurrently deleted the segment, don't revive it on rollback\n\t\t\t\tif (segment.removes[0].clientId === this.collabWindow.clientId) {\n\t\t\t\t\t// This also removes obliterates, but that should be ok as we can only remove a segment once.\n\t\t\t\t\t// If we were able to remove it locally, that also means there are no remote removals (since rollback is synchronous).\n\t\t\t\t\tremoveRemovalInfo(segment);\n\n\t\t\t\t\tthis.blockUpdatePathLengths(segment.parent, rollbackStamp);\n\n\t\t\t\t\t// Note: optional chaining short-circuits:\n\t\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#short-circuiting\n\t\t\t\t\tthis.mergeTreeDeltaCallback?.(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\top: createInsertSegmentOp(this.findRollbackPosition(segment), segment),\n\t\t\t\t\t\t\trollback: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\t\t\t\t\tdeltaSegments: [{ segment }],\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (\n\t\t\top.type === MergeTreeDeltaType.INSERT ||\n\t\t\top.type === MergeTreeDeltaType.ANNOTATE\n\t\t) {\n\t\t\tconst pendingSegmentGroup = this.pendingSegments.pop()?.data;\n\t\t\tif (\n\t\t\t\tpendingSegmentGroup === undefined ||\n\t\t\t\tpendingSegmentGroup !== localOpMetadata ||\n\t\t\t\t(op.type === MergeTreeDeltaType.ANNOTATE && !pendingSegmentGroup.previousProps)\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Rollback op doesn't match last edit\");\n\t\t\t}\n\t\t\tlet i = 0;\n\t\t\tfor (const segment of pendingSegmentGroup.segments) {\n\t\t\t\tconst segmentSegmentGroup = segment?.segmentGroups?.pop();\n\t\t\t\tassert(\n\t\t\t\t\tsegmentSegmentGroup === pendingSegmentGroup,\n\t\t\t\t\t0x3ef /* Unexpected segmentGroup in segment */,\n\t\t\t\t);\n\n\t\t\t\tconst start = this.findRollbackPosition(segment);\n\t\t\t\tif (op.type === MergeTreeDeltaType.INSERT) {\n\t\t\t\t\tsegment.insert = {\n\t\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\t\t...rollbackStamp,\n\t\t\t\t\t};\n\t\t\t\t\tconst removeOp = createRemoveRangeOp(start, start + segment.cachedLength);\n\t\t\t\t\tconst removeStamp: SetRemoveOperationStamp = {\n\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\t...rollbackStamp,\n\t\t\t\t\t};\n\t\t\t\t\tthis.markRangeRemoved(\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tstart + segment.cachedLength,\n\t\t\t\t\t\tthis.localPerspective,\n\t\t\t\t\t\tremoveStamp,\n\t\t\t\t\t\t{ op: removeOp, rollback: true },\n\t\t\t\t\t);\n\t\t\t\t} /* op.type === MergeTreeDeltaType.ANNOTATE */ else {\n\t\t\t\t\tconst props = pendingSegmentGroup.previousProps![i];\n\t\t\t\t\tconst annotateOp = createAnnotateRangeOp(start, start + segment.cachedLength, props);\n\n\t\t\t\t\tthis.annotateRange(\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tstart + segment.cachedLength,\n\t\t\t\t\t\t{ props },\n\t\t\t\t\t\tthis.localPerspective,\n\t\t\t\t\t\trollbackStamp,\n\t\t\t\t\t\t{ op: annotateOp, rollback: true },\n\t\t\t\t\t);\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(\"Unsupported op type for rollback\");\n\t\t}\n\t}\n\n\t/**\n\t * Walk the segments up to the current segment and calculate its position\n\t */\n\tprivate findRollbackPosition(segment: ISegmentLeaf): number {\n\t\tlet segmentPosition = 0;\n\t\twalkAllChildSegments(this.root, (seg) => {\n\t\t\t// If we've found the desired segment, terminate the walk and return 'segmentPosition'.\n\t\t\tif (seg === segment) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// If not removed, increase position\n\t\t\tif (!isRemoved(seg)) {\n\t\t\t\tsegmentPosition += seg.cachedLength;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\treturn segmentPosition;\n\t}\n\n\tpublic nodeUpdateLengthNewStructure(node: MergeBlock, recur = false): void {\n\t\tthis.blockUpdate(node);\n\t\tif (this.collabWindow.collaborating) {\n\t\t\tthis.localPartialsComputed = false;\n\t\t\tnode.partialLengths = PartialSequenceLengths.combine(node, this.collabWindow, recur);\n\t\t}\n\t}\n\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\tconst segment: ISegmentPrivate | undefined = lref.getSegment();\n\t\treturn segment?.localRefs?.removeLocalRef(lref);\n\t}\n\n\tstartOfTree = new StartOfTreeSegment(this);\n\tendOfTree = new EndOfTreeSegment(this);\n\n\tpublic createLocalReferencePosition(\n\t\t_segment: ISegmentPrivate | \"start\" | \"end\",\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\tif (\n\t\t\t_segment !== \"start\" &&\n\t\t\t_segment !== \"end\" &&\n\t\t\tisRemovedAndAcked(_segment) &&\n\t\t\t!refTypeIncludesFlag(\n\t\t\t\trefType,\n\t\t\t\tReferenceType.SlideOnRemove | ReferenceType.Transient | ReferenceType.StayOnRemove,\n\t\t\t) &&\n\t\t\t_segment.endpointType === undefined\n\t\t) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Can only create SlideOnRemove or Transient local reference position on a removed or obliterated segment\",\n\t\t\t);\n\t\t}\n\t\tlet segment: ISegmentLeaf;\n\n\t\tif (_segment === \"start\") {\n\t\t\tsegment = this.startOfTree;\n\t\t} else if (_segment === \"end\") {\n\t\t\tsegment = this.endOfTree;\n\t\t} else {\n\t\t\tassertSegmentLeaf(_segment);\n\t\t\tsegment = _segment;\n\t\t}\n\n\t\tconst localRefs = LocalReferenceCollection.setOrGet(segment);\n\n\t\tconst segRef = localRefs.createLocalRef(\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\n\t\treturn segRef;\n\t}\n\n\t/**\n\t * Segments should either be removed remotely, removed locally, or inserted locally\n\t *\n\t * See description of {@link normalizeSegmentsOnRebase}.\n\t *\n\t * This normalizes a block of adjacent segments whose positions have collapsed between the time of the original submission and now\n\t * such that removed segments come after ones that still exist.\n\t *\n\t * TODO:AB#34898: It looks like this method has some bugs, search code for this tag for an example test that demonstrates\n\t * segment normalization yielding an order that remote clients wouldn't have seen.\n\t */\n\tprivate normalizeAdjacentSegments(affectedSegments: DoublyLinkedList<ISegmentLeaf>): void {\n\t\t// Eagerly demand this since we're about to shift elements in the list around\n\t\tconst currentOrder = Array.from(affectedSegments, ({ data: seg }) => ({\n\t\t\tparent: seg.parent,\n\t\t\tindex: seg.index,\n\t\t\tordinal: seg.ordinal,\n\t\t}));\n\n\t\t// Last segment which was not affected locally.\n\t\tlet lastLocalSegment = affectedSegments.last;\n\t\twhile (lastLocalSegment !== undefined && isRemovedAndAcked(lastLocalSegment.data)) {\n\t\t\tlastLocalSegment = lastLocalSegment.prev;\n\t\t}\n\n\t\tif (!lastLocalSegment) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (\n\t\t\tlet segmentToSlide: ListNode<ISegmentLeaf> | undefined = lastLocalSegment,\n\t\t\t\tnearerSegment = lastLocalSegment?.prev;\n\t\t\tsegmentToSlide !== undefined;\n\t\t\tsegmentToSlide = nearerSegment, nearerSegment = nearerSegment?.prev\n\t\t) {\n\t\t\t// Slide iterCur forward as far as possible\n\t\t\tif (isRemovedAndAcked(segmentToSlide.data)) {\n\t\t\t\t// Slide past all segments that are not also remotely removed\n\t\t\t\taffectedSegments.remove(segmentToSlide);\n\t\t\t\taffectedSegments.insertAfter(lastLocalSegment, segmentToSlide.data);\n\t\t\t} else if (isRemoved(segmentToSlide.data)) {\n\t\t\t\tassert(\n\t\t\t\t\tsegmentToSlide.data.removes[0].seq !== undefined,\n\t\t\t\t\t0x54d /* Removed segment that hasnt had its removal acked should be locally removed */,\n\t\t\t\t);\n\t\t\t\t// Slide each locally removed item past all segments that have localSeq > lremoveItem.localSeq\n\t\t\t\t// but not past remotely removed segments;\n\t\t\t\tlet cur = segmentToSlide;\n\t\t\t\tlet scan = cur.next;\n\t\t\t\twhile (\n\t\t\t\t\tscan !== undefined &&\n\t\t\t\t\t!isRemovedAndAcked(scan.data) &&\n\t\t\t\t\tscan.data.insert.localSeq !== undefined &&\n\t\t\t\t\topstampUtils.greaterThan(scan.data.insert, segmentToSlide.data.removes[0])\n\t\t\t\t) {\n\t\t\t\t\tcur = scan;\n\t\t\t\t\tscan = scan.next;\n\t\t\t\t}\n\t\t\t\tif (cur !== segmentToSlide) {\n\t\t\t\t\taffectedSegments.remove(segmentToSlide);\n\t\t\t\t\taffectedSegments.insertAfter(cur, segmentToSlide.data);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst newOrder = Array.from(affectedSegments, ({ data }) => data);\n\t\tfor (const seg of newOrder)\n\t\t\tseg.localRefs?.walkReferences((lref) => lref.callbacks?.beforeSlide?.(lref));\n\t\tconst perSegmentTrackingGroups = new Map<ISegmentLeaf, TrackingGroup[]>();\n\t\tfor (const segment of newOrder) {\n\t\t\tconst { trackingCollection } = segment;\n\t\t\tconst trackingGroups = [...trackingCollection.trackingGroups];\n\t\t\tperSegmentTrackingGroups.set(segment, trackingGroups);\n\t\t\tfor (const group of trackingCollection.trackingGroups) {\n\t\t\t\ttrackingCollection.unlink(group);\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = 0; i < newOrder.length; i++) {\n\t\t\tconst seg = newOrder[i];\n\t\t\tconst { parent, index, ordinal } = currentOrder[i];\n\t\t\tassignChild(parent, seg, index, false);\n\t\t\tseg.ordinal = ordinal;\n\t\t}\n\n\t\tfor (const [segment, groups] of perSegmentTrackingGroups.entries()) {\n\t\t\tfor (const group of groups) {\n\t\t\t\tsegment.trackingCollection.link(group);\n\t\t\t}\n\t\t}\n\n\t\t// Finally, update internal node bookkeeping on ancestors of the swapped nodes.\n\t\t// Toposort would improve this by a log factor, but probably not worth the added code size\n\t\tconst depths = new Map<IMergeNode, number>();\n\t\tconst computeDepth = (block: IMergeNode): number => {\n\t\t\tif (!depths.has(block)) {\n\t\t\t\tdepths.set(block, block.parent === undefined ? 0 : 1 + computeDepth(block.parent));\n\t\t\t}\n\t\t\treturn depths.get(block)!;\n\t\t};\n\t\tfor (const element of newOrder) {\n\t\t\tcomputeDepth(element);\n\t\t}\n\t\tfor (const [node] of [...depths.entries()].sort((a, b) => b[1] - a[1])) {\n\t\t\tif (!node.isLeaf()) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t}\n\t\t}\n\t\tfor (const seg of newOrder)\n\t\t\tseg.localRefs?.walkReferences((lref) => lref.callbacks?.afterSlide?.(lref));\n\t}\n\n\t/**\n\t * Normalizes the segments nearby `segmentGroup` to be ordered as they would if the op submitting `segmentGroup`\n\t * is rebased to the current sequence number.\n\t * This primarily affects the ordering of adjacent segments that were removed between the original submission of\n\t * the local ops and now.\n\t * Consider the following sequence of events:\n\t * Initial state: \"hi my friend\" (seq: 0)\n\t * - Client 1 inserts \"good \" to make \"hi my good friend\" (op1, refSeq: 0)\n\t * - Client 2 deletes \"my \" to make \"hi friend\" (op2, refSeq: 0)\n\t * - op2 is sequenced giving seq 1\n\t * - Client 1 disconnects and reconnects at seq: 1.\n\t *\n\t * At this point in time, client 1 will have segments [\"hi \", Removed\"my \", Local\"good \", \"friend\"].\n\t * However, the rebased op that it submits will cause client 2 to have segments\n\t * [\"hi \", Local\"good \", Removed\"my \", \"friend\"].\n\t *\n\t * The difference in ordering can be problematic for tie-breaking concurrently inserted segments in some scenarios.\n\t * Rather than incur extra work tie-breaking these scenarios for all clients, when client 1 rebases its operation,\n\t * it can fix up its local state to align with what would be expected of the op it resubmits.\n\t */\n\tpublic normalizeSegmentsOnRebase(): void {\n\t\tlet currentRangeToNormalize = new DoublyLinkedList<ISegmentLeaf>();\n\t\tlet rangeContainsLocalSegs = false;\n\t\tlet rangeContainsRemoteRemovedSegs = false;\n\t\tconst normalize = (): void => {\n\t\t\tif (\n\t\t\t\trangeContainsLocalSegs &&\n\t\t\t\trangeContainsRemoteRemovedSegs &&\n\t\t\t\tcurrentRangeToNormalize.length > 1\n\t\t\t) {\n\t\t\t\tthis.normalizeAdjacentSegments(currentRangeToNormalize);\n\t\t\t}\n\t\t};\n\t\twalkAllChildSegments(this.root, (seg) => {\n\t\t\tif (isRemoved(seg) || opstampUtils.isLocal(seg.insert)) {\n\t\t\t\tif (isRemovedAndAcked(seg)) {\n\t\t\t\t\trangeContainsRemoteRemovedSegs = true;\n\t\t\t\t}\n\t\t\t\tif (opstampUtils.isLocal(seg.insert)) {\n\t\t\t\t\trangeContainsLocalSegs = true;\n\t\t\t\t}\n\t\t\t\tcurrentRangeToNormalize.push(seg);\n\t\t\t} else {\n\t\t\t\tnormalize();\n\t\t\t\tcurrentRangeToNormalize = new DoublyLinkedList<ISegmentLeaf>();\n\t\t\t\trangeContainsLocalSegs = false;\n\t\t\t\trangeContainsRemoteRemovedSegs = false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\tnormalize();\n\t\tthis.obliterates.onNormalize();\n\t\tconst segmentTiebreakChanges = new Set<{\n\t\t\tsegment: ISegmentLeaf;\n\t\t\told: ObliterateInfo;\n\t\t\tnew: ObliterateInfo | undefined;\n\t\t}>();\n\t\tfor (const info of this.obliterates) {\n\t\t\tif (info.tiebreakTrackingGroup !== undefined) {\n\t\t\t\tfor (const segment of info.tiebreakTrackingGroup.tracked) {\n\t\t\t\t\t// Recompute previous obliterate\n\t\t\t\t\tassert(\n\t\t\t\t\t\tisSegmentLeaf(segment) &&\n\t\t\t\t\t\t\tisInsideObliterate(segment) &&\n\t\t\t\t\t\t\tsegment.insertionRefSeqStamp !== undefined,\n\t\t\t\t\t\t0xb74 /* Expected segment leaf inside obliterate with insertionRefSeqStamp */,\n\t\t\t\t\t);\n\t\t\t\t\t// This may have changed as a result of segments shuffling: outstanding local obliterates that previously surrounded a segment may no longer surround it.\n\t\t\t\t\tconst newObliteratePrecedingInsertion = this.computeObliteratePrecedingInsertion(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tsegment.insertionRefSeqStamp,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (newObliteratePrecedingInsertion !== info) {\n\t\t\t\t\t\tsegmentTiebreakChanges.add({\n\t\t\t\t\t\t\tsegment,\n\t\t\t\t\t\t\told: info,\n\t\t\t\t\t\t\tnew: newObliteratePrecedingInsertion,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const { segment, old, new: newInfo } of segmentTiebreakChanges) {\n\t\t\t// Update tiebreak tracking groups on old/new segment as well as `ISegmentInsideObliterateInfo` state\n\t\t\t// which we only keep around as long as obliterates are in flight.\n\t\t\told.tiebreakTrackingGroup?.unlink(segment);\n\t\t\tif (newInfo?.tiebreakTrackingGroup === undefined) {\n\t\t\t\t// Segment is either no longer inside any obliterate or only inside acked obliterates.\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(segment, {\n\t\t\t\t\tobliteratePrecedingInsertion: newInfo,\n\t\t\t\t\tinsertionRefSeqStamp: undefined,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(segment, {\n\t\t\t\t\tobliteratePrecedingInsertion: newInfo,\n\t\t\t\t});\n\n\t\t\t\tnewInfo.tiebreakTrackingGroup.link(segment);\n\t\t\t}\n\t\t}\n\t}\n\tprivate blockUpdate(block: MergeBlock): void {\n\t\tlet len: number | undefined;\n\n\t\tconst rightmostTiles = createMap<Marker>();\n\t\tconst leftmostTiles = createMap<Marker>();\n\n\t\tfor (let i = 0; i < block.childCount; i++) {\n\t\t\tconst node = block.children[i];\n\t\t\tconst nodeLength = nodeTotalLength(this, node);\n\t\t\tif (nodeLength !== undefined) {\n\t\t\t\tlen ??= 0;\n\t\t\t\tlen += nodeLength;\n\t\t\t}\n\t\t\tif (node.isLeaf()) {\n\t\t\t\tconst segment = node;\n\t\t\t\tif ((this.leafLength(segment) ?? 0) > 0 && Marker.is(segment)) {\n\t\t\t\t\tconst markerId = segment.getId();\n\t\t\t\t\t// Also in insertMarker but need for reload segs case\n\t\t\t\t\t// can add option for this only from reload segs\n\t\t\t\t\tif (markerId) {\n\t\t\t\t\t\tthis.idToMarker.set(markerId, segment);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (refTypeIncludesFlag(segment, ReferenceType.Tile)) {\n\t\t\t\t\t\tconst tileLabels = refGetTileLabels(segment);\n\t\t\t\t\t\tif (tileLabels) {\n\t\t\t\t\t\t\tfor (const tileLabel of tileLabels) {\n\t\t\t\t\t\t\t\t// this depends on walking children in order\n\t\t\t\t\t\t\t\t// The later, and right most children overwrite\n\t\t\t\t\t\t\t\t// whereas early, and left most do not overwrite\n\t\t\t\t\t\t\t\trightmostTiles[tileLabel] = segment;\n\t\t\t\t\t\t\t\tleftmostTiles[tileLabel] ??= segment;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\textend(rightmostTiles, node.rightmostTiles);\n\t\t\t\textendIfUndefined(leftmostTiles, node.leftmostTiles);\n\t\t\t}\n\t\t}\n\t\tblock.leftmostTiles = leftmostTiles;\n\t\tblock.rightmostTiles = rightmostTiles;\n\t\tblock.cachedLength = len;\n\t}\n\n\tpublic blockUpdatePathLengths(\n\t\tstartBlock: MergeBlock | undefined,\n\t\tstamp: OperationStamp,\n\t\tnewStructure = false,\n\t): void {\n\t\tlet block: MergeBlock | undefined = startBlock;\n\t\twhile (block !== undefined) {\n\t\t\tif (newStructure) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(block);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t}\n\t\t\tblock = block.parent;\n\t\t}\n\t}\n\n\tprivate blockUpdateLength(node: MergeBlock, stamp: OperationStamp): void {\n\t\tthis.blockUpdate(node);\n\t\tthis.localPartialsComputed = false;\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tstamp.seq !== TreeMaintenanceSequenceNumber\n\t\t) {\n\t\t\tif (\n\t\t\t\tnode.partialLengths !== undefined &&\n\t\t\t\tMergeTree.options.incrementalUpdate &&\n\t\t\t\tstamp.clientId !== NonCollabClient\n\t\t\t) {\n\t\t\t\tnode.partialLengths.update(node, stamp.seq, stamp.clientId, this.collabWindow);\n\t\t\t} else {\n\t\t\t\tnode.partialLengths = PartialSequenceLengths.combine(node, this.collabWindow);\n\t\t\t}\n\n\t\t\tPartialSequenceLengths.options.verifyExpected?.(this, node, stamp.seq, stamp.clientId);\n\t\t}\n\t}\n\n\t/**\n\t * Map over all visible segments in a given range\n\t *\n\t * A segment is visible if its length is greater than 0\n\t *\n\t * See `this.nodeMap` for additional documentation\n\t */\n\tpublic mapRange<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tperspective: Perspective,\n\t\taccum: TClientData,\n\t\tstart?: number,\n\t\tend?: number,\n\t\tsplitRange: boolean = false,\n\t\tvisibilityPerspective: Perspective = perspective,\n\t): void {\n\t\tif (splitRange) {\n\t\t\tif (start) {\n\t\t\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\t\t}\n\t\t\tif (end) {\n\t\t\t\tthis.ensureIntervalBoundary(end, perspective);\n\t\t\t}\n\t\t}\n\t\tthis.nodeMap(\n\t\t\tperspective,\n\t\t\t(seg, pos, _start, _end) =>\n\t\t\t\thandler(seg, pos, perspective.refSeq, perspective.clientId, _start, _end, accum),\n\t\t\tundefined,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tvisibilityPerspective,\n\t\t);\n\t}\n\n\t/**\n\t * Map over all visible segments in a given range\n\t *\n\t * A segment is visible if its length is greater than 0\n\t *\n\t * @param refSeq - The sequence number used to determine the range (start\n\t * and end positions) of segments to iterate over.\n\t *\n\t * @param visibilitySeq - An additional sequence number to further configure\n\t * segment visibility during traversal. This is the same as refSeq, except\n\t * in the case of obliterate.\n\t *\n\t * In the case where `refSeq == visibilitySeq`, mapping is done on all\n\t * visible segments from `start` to `end`.\n\t *\n\t * If a segment is invisible at both `visibilitySeq` and `refSeq`, then it\n\t * will not be traversed and mapped. Otherwise, if the segment is visible at\n\t * either seq, it will be mapped.\n\t *\n\t * If a segment is only visible at `visibilitySeq`, it will still be mapped,\n\t * but it will not count as a segment within the range. That is, it will be\n\t * ignored for the purposes of tracking when traversal should end.\n\t */\n\tprivate nodeMap(\n\t\tperspective: Perspective,\n\t\tleaf: (segment: ISegmentLeaf, pos: number, start: number, end: number) => boolean,\n\t\tpost?: (block: MergeBlock) => boolean,\n\t\tstart: number = 0,\n\t\tend?: number,\n\t\tvisibilityPerspective: Perspective = perspective,\n\t): void {\n\t\tconst endPos = end ?? this.nodeLength(this.root, perspective) ?? 0;\n\t\tif (endPos === start) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet pos = 0;\n\n\t\tdepthFirstNodeWalk(\n\t\t\tthis.root,\n\t\t\tthis.root.children[0],\n\t\t\t(node) => {\n\t\t\t\tif (endPos <= pos) {\n\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t}\n\n\t\t\t\tconst len = this.nodeLength(node, visibilityPerspective);\n\t\t\t\tconst lenAtRefSeq =\n\t\t\t\t\t(visibilityPerspective === perspective ? len : this.nodeLength(node, perspective)) ??\n\t\t\t\t\t0;\n\n\t\t\t\t// NOTE: This code ensures that obliterates have a chance to mark segments which have been inserted locally\n\t\t\t\t// as also having been obliterated on the local client. With the introduction of RemoteObliteratePerspective,\n\t\t\t\t// it's feasible we could remove it if the `nodeLength` calculation also respects that perspective for blocks\n\t\t\t\t// and not just leaves.\n\t\t\t\tconst isUnackedAndInObliterate =\n\t\t\t\t\tvisibilityPerspective !== perspective &&\n\t\t\t\t\t(!node.isLeaf() || opstampUtils.isLocal(node.insert));\n\t\t\t\tif (\n\t\t\t\t\t(len === undefined && lenAtRefSeq === 0) ||\n\t\t\t\t\t(len === 0 && !isUnackedAndInObliterate && lenAtRefSeq === 0)\n\t\t\t\t) {\n\t\t\t\t\treturn NodeAction.Skip;\n\t\t\t\t}\n\n\t\t\t\tconst nextPos = pos + lenAtRefSeq;\n\t\t\t\t// start is beyond the current node, so we can skip it\n\t\t\t\tif (start >= nextPos) {\n\t\t\t\t\tpos = nextPos;\n\t\t\t\t\treturn NodeAction.Skip;\n\t\t\t\t}\n\n\t\t\t\tif (node.isLeaf()) {\n\t\t\t\t\tif (leaf(node, pos, start - pos, endPos - pos) === false) {\n\t\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t\t}\n\t\t\t\t\tpos = nextPos;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tpost,\n\t\t);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mergeTree.js","sourceRoot":"","sources":["../src/mergeTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAC7D,+BAA+B;AAE/B,OAAO,EACN,MAAM,EACN,IAAI,EAEJ,gBAAgB,GAEhB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAI3F,OAAO,EACN,eAAe,EACf,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC7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BAAqB,KAAK,WAAW;gBACrC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACvD,IACC,CAAC,GAAG,KAAK,SAAS,IAAI,WAAW,KAAK,CAAC,CAAC;gBACxC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,wBAAwB,IAAI,WAAW,KAAK,CAAC,CAAC,EAC5D,CAAC;gBACF,OAAO,UAAU,CAAC,IAAI,CAAC;YACxB,CAAC;YAED,MAAM,OAAO,GAAG,GAAG,GAAG,WAAW,CAAC;YAClC,sDAAsD;YACtD,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACtB,GAAG,GAAG,OAAO,CAAC;gBACd,OAAO,UAAU,CAAC,IAAI,CAAC;YACxB,CAAC;YAED,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBACnB,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC1D,OAAO,UAAU,CAAC,IAAI,CAAC;gBACxB,CAAC;gBACD,GAAG,GAAG,OAAO,CAAC;YACf,CAAC;QACF,CAAC,EACD,SAAS,EACT,IAAI,CACJ,CAAC;IACH,CAAC;;AA10EsB,iBAAO,GAAG;IAChC,iBAAiB,EAAE,IAAI;IACvB,sBAAsB,EAAE,IAAI;IAC5B,eAAe,EAAE,IAAI;CACrB,AAJ6B,CAI5B;AAEF;;;;GAIG;AACqB,2BAAiB,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC,EAA2B,AAA9C,CAA+C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable no-bitwise */\n\nimport {\n\tassert,\n\tHeap,\n\ttype IComparer,\n\tDoublyLinkedList,\n\ttype ListNode,\n} from \"@fluidframework/core-utils/internal\";\nimport { DataProcessingError, UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IAttributionCollectionSerializer } from \"./attributionCollection.js\";\nimport type { Client } from \"./client.js\";\nimport {\n\tNonCollabClient,\n\tTreeMaintenanceSequenceNumber,\n\tUnassignedSequenceNumber,\n} from \"./constants.js\";\nimport { EndOfTreeSegment, StartOfTreeSegment } from \"./endOfTreeSegment.js\";\nimport {\n\tLocalReferenceCollection,\n\ttype LocalReferencePosition,\n\tSlidingPreference,\n\tanyLocalReferencePosition,\n\tfilterLocalReferencePositions,\n} from \"./localReference.js\";\nimport {\n\ttype IMergeTreeDeltaOpArgs,\n\ttype IMergeTreeSegmentDelta,\n\ttype MergeTreeDeltaCallback,\n\ttype MergeTreeMaintenanceCallback,\n\tMergeTreeMaintenanceType,\n} from \"./mergeTreeDeltaCallback.js\";\nimport {\n\tLeafAction,\n\tNodeAction,\n\tbackwardExcursion,\n\tdepthFirstNodeWalk,\n\tforwardExcursion,\n\twalkAllChildSegments,\n} from \"./mergeTreeNodeWalk.js\";\nimport {\n\tCollaborationWindow,\n\ttype IMergeNode,\n\ttype ISegmentAction,\n\ttype ISegmentChanges,\n\ttype InsertContext,\n\tMarker,\n\tMaxNodesInBlock,\n\tMergeBlock,\n\ttype SegmentGroup,\n\tassertSegmentLeaf,\n\tassignChild,\n\tgetMinSeqPerspective,\n\tgetMinSeqStamp,\n\tisSegmentLeaf,\n\treservedMarkerIdKey,\n\ttype IMergeNodeBuilder,\n\ttype ISegmentInternal,\n\ttype ISegmentLeaf,\n\ttype ISegmentPrivate,\n\ttype ObliterateInfo,\n} from \"./mergeTreeNodes.js\";\nimport { UnorderedTrackingGroup, type TrackingGroup } from \"./mergeTreeTracking.js\";\nimport {\n\tcreateAnnotateRangeOp,\n\tcreateInsertSegmentOp,\n\tcreateRemoveRangeOp,\n} from \"./opBuilder.js\";\nimport {\n\ttype IRelativePosition,\n\tMergeTreeDeltaType,\n\tReferenceType,\n\ttype IMergeTreeOp,\n} from \"./ops.js\";\nimport { PartialSequenceLengths } from \"./partialLengths.js\";\nimport {\n\tPriorPerspective,\n\tLocalReconnectingPerspective,\n\ttype Perspective,\n\tLocalDefaultPerspective,\n\tRemoteObliteratePerspective,\n\tallAckedChangesPerspective,\n} from \"./perspective.js\";\nimport { type PropertySet, createMap, extend, extendIfUndefined } from \"./properties.js\";\nimport {\n\tDetachedReferencePosition,\n\ttype ReferencePosition,\n\trefGetTileLabels,\n\trefHasTileLabel,\n\trefTypeIncludesFlag,\n} from \"./referencePositions.js\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\tassertRemoved,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n\tisMergeNodeInfo,\n\tisRemoved,\n\toverwriteInfo,\n\tremoveRemovalInfo,\n\ttoRemovalInfo,\n\ttype IHasInsertionInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tcopyPropertiesAndManager,\n\tPropertiesManager,\n\ttype PropsOrAdjust,\n} from \"./segmentPropertiesManager.js\";\nimport { Side, type InteriorSequencePlace } from \"./sequencePlace.js\";\nimport { SortedSegmentSet } from \"./sortedSegmentSet.js\";\nimport type {\n\tOperationStamp,\n\tInsertOperationStamp,\n\tRemoveOperationStamp,\n\tSetRemoveOperationStamp,\n\tSliceRemoveOperationStamp,\n} from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\nimport { zamboniSegments } from \"./zamboni.js\";\n\nexport function isRemovedAndAcked(\n\tsegment: ISegmentPrivate,\n): segment is ISegmentLeaf & IHasRemovalInfo {\n\tconst removalInfo = toRemovalInfo(segment);\n\treturn removalInfo !== undefined && opstampUtils.isAcked(removalInfo.removes[0]);\n}\n\nfunction nodeTotalLength(mergeTree: MergeTree, node: IMergeNode): number | undefined {\n\tif (!node.isLeaf()) {\n\t\treturn node.cachedLength;\n\t}\n\treturn mergeTree.leafLength(node);\n}\n\nconst LRUSegmentComparer: IComparer<LRUSegment> = {\n\tmin: { maxSeq: -2 },\n\tcompare: (a, b) => a.maxSeq - b.maxSeq,\n};\n\nfunction ackSegment(\n\tsegment: ISegmentLeaf,\n\tsegmentGroup: SegmentGroup,\n\topArgs: IMergeTreeDeltaOpArgs,\n\tstamp: OperationStamp,\n): boolean {\n\tconst currentSegmentGroup = segment.segmentGroups?.dequeue();\n\tassert(currentSegmentGroup === segmentGroup, 0x043 /* \"On ack, unexpected segmentGroup!\" */);\n\tassert(opArgs.sequencedMessage !== undefined, 0xa6e /* must have sequencedMessage */);\n\tconst {\n\t\top,\n\t\tsequencedMessage: { sequenceNumber, minimumSequenceNumber },\n\t} = opArgs;\n\tlet allowIncrementalPartialLengthsUpdate = true;\n\tswitch (op.type) {\n\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\tassert(\n\t\t\t\t!!segment.propertyManager,\n\t\t\t\t0x044 /* \"On annotate ack, missing segment property manager!\" */,\n\t\t\t);\n\t\t\tsegment.propertyManager.ack(sequenceNumber, minimumSequenceNumber, op);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\tassert(\n\t\t\t\topstampUtils.isLocal(segment.insert),\n\t\t\t\t0x045 /* \"On insert, seq number already assigned!\" */,\n\t\t\t);\n\n\t\t\tsegment.insert = {\n\t\t\t\t...stamp,\n\t\t\t\ttype: \"insert\",\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase MergeTreeDeltaType.REMOVE:\n\t\tcase MergeTreeDeltaType.OBLITERATE:\n\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED: {\n\t\t\tassertRemoved(segment);\n\t\t\tconst latestRemove = segment.removes[segment.removes.length - 1];\n\t\t\tassert(\n\t\t\t\topstampUtils.isLocal(latestRemove),\n\t\t\t\t0xb5d /* Expected last remove to be unacked */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tsegment.removes.length === 1 ||\n\t\t\t\t\topstampUtils.isAcked(segment.removes[segment.removes.length - 2]),\n\t\t\t\t0xb5e /* Expected prior remove to be acked */,\n\t\t\t);\n\n\t\t\tallowIncrementalPartialLengthsUpdate = segment.removes.length === 1;\n\t\t\tconst removeStamp: RemoveOperationStamp = {\n\t\t\t\t...stamp,\n\t\t\t\ttype: op.type === MergeTreeDeltaType.REMOVE ? \"setRemove\" : \"sliceRemove\",\n\t\t\t};\n\t\t\tsegment.removes[segment.removes.length - 1] = removeStamp;\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new Error(`${op.type} is in unrecognized operation type`);\n\t\t}\n\t}\n\n\treturn allowIncrementalPartialLengthsUpdate;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeOptions {\n\tcatchUpBlobName?: string;\n\t/**\n\t * Whether or not reference positions can slide to special endpoint segments\n\t * denoting the positions immediately before the start and immediately after\n\t * the end of the string.\n\t *\n\t * This is primarily useful in the case of interval stickiness.\n\t */\n\tmergeTreeReferencesCanSlideToEndpoint?: boolean;\n\tmergeTreeSnapshotChunkSize?: number;\n\t/**\n\t * Whether to use the SnapshotV1 format over SnapshotLegacy.\n\t *\n\t * SnapshotV1 stores a view of the merge-tree at the current sequence number, preserving merge metadata\n\t * (e.g. clientId, seq, etc.) only for segment changes within the collab window.\n\t *\n\t * SnapshotLegacy stores a view of the merge-tree at the minimum sequence number along with the ops between\n\t * the minimum sequence number and the current sequence number.\n\t *\n\t * Both formats merge segments where possible (see {@link ISegment.canAppend})\n\t *\n\t * default: false\n\t *\n\t * @remarks\n\t * Despite the \"legacy\"/\"V1\" naming, both formats are actively used at the time of writing. SharedString\n\t * uses legacy and Matrix uses V1.\n\t */\n\tnewMergeTreeSnapshotFormat?: boolean;\n\n\t/**\n\t * Enables support for the obliterate operation -- a stronger form of remove\n\t * which deletes concurrently inserted segments\n\t *\n\t * Obliterate is currently experimental and may not work in all scenarios.\n\t *\n\t * Default value: false\n\t */\n\tmergeTreeEnableObliterate?: boolean;\n\n\t/**\n\t * Enables support for reconnecting when obliterate operations are present\n\t *\n\t * Obliterate is currently experimental and may not work in all scenarios.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableObliterateReconnect?: boolean;\n\n\t/**\n\t * Enables support for obliterate endpoint expansion.\n\t * When enabled, obliterate operations can have sidedness specified for their endpoints.\n\t * If an endpoint is externally anchored\n\t * (aka the start is after a given position, or the end is before a given position),\n\t * then concurrent inserts adjacent to the exclusive endpoint of an obliterated range will be included in the obliteration\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableSidedObliterate?: boolean;\n\n\t/**\n\t * Enables support for annotate adjust operations, which allow for specifying\n\t * a summand which is summed with the current value to compute the new value.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmergeTreeEnableAnnotateAdjust?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IMergeTreeOptionsInternal extends IMergeTreeOptions {\n\t/**\n\t * Options related to attribution\n\t */\n\tattribution?: IMergeTreeAttributionOptions;\n}\n\nexport function errorIfOptionNotTrue(\n\toptions: IMergeTreeOptions | undefined,\n\toption: keyof IMergeTreeOptions,\n): void {\n\tif (options?.[option] !== true) {\n\t\tthrow new Error(`${option} is not enabled.`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface IMergeTreeAttributionOptions {\n\t/**\n\t * If enabled, segments will store attribution keys which can be used with the runtime to determine\n\t * attribution information (i.e. who created the content and when it was created).\n\t *\n\t * This flag only applied to new documents: if a snapshot is loaded, whether or not attribution keys\n\t * are tracked is determined by the presence of existing attribution keys in the snapshot.\n\t *\n\t * default: false\n\t */\n\ttrack?: boolean;\n\n\t/**\n\t * Provides a policy for how to track attribution data on segments.\n\t * This option must be provided if either:\n\t * - `track` is set to true\n\t * - a document containing existing attribution information is loaded\n\t */\n\tpolicyFactory?: () => AttributionPolicy;\n}\n\n/**\n * Implements policy dictating which kinds of operations should be attributed and how.\n * @sealed\n * @internal\n */\nexport interface AttributionPolicy {\n\t/**\n\t * Enables tracking attribution information for operations on this merge-tree.\n\t * This function is expected to subscribe to appropriate change events in order\n\t * to manage any attribution data it stores on segments.\n\t *\n\t * This must be done in an eventually consistent fashion.\n\t */\n\tattach: (client: Client) => void;\n\t/**\n\t * Disables tracking attribution information on segments.\n\t */\n\tdetach: () => void;\n\t/***/\n\tisAttached: boolean;\n\t/**\n\t * Serializer capable of serializing any attribution data this policy stores on segments.\n\t */\n\tserializer: IAttributionCollectionSerializer;\n}\n\n/**\n * @internal\n */\nexport interface LRUSegment {\n\tsegment?: ISegmentLeaf;\n\tmaxSeq: number;\n}\n\nexport interface IRootMergeBlock extends MergeBlock {\n\tmergeTree?: MergeTree;\n}\n\nexport function findRootMergeBlock(\n\tsegmentOrNode: IMergeNode | undefined,\n): IRootMergeBlock | undefined {\n\tif (segmentOrNode === undefined) {\n\t\treturn undefined;\n\t}\n\tlet maybeRoot: IRootMergeBlock | undefined = segmentOrNode.isLeaf()\n\t\t? segmentOrNode.parent\n\t\t: segmentOrNode;\n\twhile (maybeRoot?.parent !== undefined) {\n\t\tmaybeRoot = maybeRoot.parent;\n\t}\n\n\treturn maybeRoot?.mergeTree === undefined ? undefined : maybeRoot;\n}\n\n/**\n * Find the segment to which a reference will slide if it needs to slide, or undefined if there\n * is no valid segment (i.e. the tree is empty).\n *\n * @param segment - The segment to slide from.\n * @param cache - Optional cache mapping segments to their sliding destinations.\n * Excursions will be avoided for segments in the cache, and the cache will be populated with\n * entries for all segments visited during excursion.\n * This can reduce the number of times the tree needs to be scanned if a range containing many\n * SlideOnRemove references is removed.\n */\nfunction getSlideToSegment(\n\tsegment: ISegmentLeaf | undefined,\n\tslidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\tperspective: Perspective,\n\tcache?: Map<ISegmentLeaf, { seg?: ISegmentLeaf }>,\n\tcanSlideToEndpoint: boolean = false,\n): [ISegmentLeaf | undefined, \"start\" | \"end\" | undefined] {\n\tif (\n\t\t!segment ||\n\t\tperspective.isSegmentPresent(segment) ||\n\t\tsegment.endpointType !== undefined\n\t) {\n\t\treturn [segment, undefined];\n\t}\n\n\tconst cachedSegment = cache?.get(segment);\n\tif (cachedSegment !== undefined) {\n\t\treturn [cachedSegment.seg, undefined];\n\t}\n\tconst result: { seg?: ISegmentLeaf } = {};\n\tcache?.set(segment, result);\n\tconst goFurtherToFindSlideToSegment = (seg: ISegmentLeaf): boolean => {\n\t\tif (perspective.isSegmentPresent(seg)) {\n\t\t\tresult.seg = seg;\n\t\t\treturn false;\n\t\t}\n\t\tif (\n\t\t\tcache !== undefined &&\n\t\t\ttoRemovalInfo(seg)?.removes[0].seq === toRemovalInfo(segment)?.removes[0].seq\n\t\t) {\n\t\t\tcache.set(seg, result);\n\t\t}\n\t\treturn true;\n\t};\n\n\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\tbackwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t} else {\n\t\tforwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t}\n\tif (result.seg !== undefined) {\n\t\treturn [result.seg, undefined];\n\t}\n\n\t// in the new sliding behavior, we don't look in the opposite direction\n\t// if we fail to find a segment to slide to in the right direction.\n\t//\n\t// in other words, rather than going `forward ?? backward ?? detached` (or\n\t// `backward ?? forward ?? detached`), we would slide `forward ?? detached`\n\t// or `backward ?? detached`\n\t//\n\t// in both of these cases detached may be substituted for one of the special\n\t// endpoint segments, if such behavior is enabled\n\tif (!canSlideToEndpoint) {\n\t\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\t\tforwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t\t} else {\n\t\t\tbackwardExcursion(segment, goFurtherToFindSlideToSegment);\n\t\t}\n\t}\n\n\tlet maybeEndpoint: \"start\" | \"end\" | undefined;\n\n\tif (slidingPreference === SlidingPreference.BACKWARD) {\n\t\tmaybeEndpoint = \"start\";\n\t} else if (slidingPreference === SlidingPreference.FORWARD) {\n\t\tmaybeEndpoint = \"end\";\n\t}\n\n\treturn [result.seg, maybeEndpoint];\n}\n\n/**\n * Returns the position to slide a reference to if a slide is required.\n * @param segoff - The segment and offset to slide from\n * @returns segment and offset to slide the reference to\n * @internal\n */\nexport function getSlideToSegoff(\n\tsegoff: { segment: ISegmentInternal; offset: number } | undefined,\n\tslidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\tperspective: Perspective = allAckedChangesPerspective,\n\tcanSlideToEndpoint: boolean = false,\n):\n\t| {\n\t\t\tsegment: ISegmentInternal;\n\t\t\toffset: number;\n\t }\n\t| undefined {\n\tif (!isSegmentLeaf(segoff?.segment)) {\n\t\treturn segoff;\n\t}\n\tconst [segment, _] = getSlideToSegment(\n\t\tsegoff.segment,\n\t\tslidingPreference,\n\t\tperspective,\n\t\tundefined,\n\t\tcanSlideToEndpoint,\n\t);\n\tif (segment === segoff.segment) {\n\t\treturn segoff;\n\t}\n\tif (segment === undefined) {\n\t\treturn undefined;\n\t}\n\n\tconst offset = segment.ordinal < segoff.segment.ordinal ? segment.cachedLength - 1 : 0;\n\treturn {\n\t\tsegment,\n\t\toffset,\n\t};\n}\n\nconst forwardPred = (ref: LocalReferencePosition): boolean =>\n\tref.slidingPreference !== SlidingPreference.BACKWARD;\nconst backwardPred = (ref: LocalReferencePosition): boolean =>\n\tref.slidingPreference === SlidingPreference.BACKWARD;\n\nclass Obliterates {\n\t/**\n\t * Array containing the all obliterate operations within the\n\t * collab window.\n\t *\n\t * The obliterates are stored in sequence order which accelerates clean up in setMinSeq\n\t *\n\t * See https://github.com/microsoft/FluidFramework/blob/main/packages/dds/merge-tree/docs/Obliterate.md#remote-perspective\n\t * for additional context\n\t */\n\n\tprivate readonly seqOrdered = new DoublyLinkedList<ObliterateInfo>();\n\n\t/**\n\t * This contains a sorted lists of all obliterate starts\n\t * and is used to accelerate finding overlapping obliterates\n\t * as well as determining if there are any obliterates at all.\n\t */\n\tprivate readonly startOrdered = new SortedSegmentSet<LocalReferencePosition>();\n\n\tconstructor(private readonly mergeTree: MergeTree) {}\n\n\tpublic setMinSeq(minSeq: number): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\twhile (!this.seqOrdered.empty && this.seqOrdered.first?.data.stamp.seq! <= minSeq) {\n\t\t\tconst ob = this.seqOrdered.shift()!;\n\t\t\tthis.startOrdered.remove(ob.data.start);\n\t\t\tthis.mergeTree.removeLocalReferencePosition(ob.data.start);\n\t\t\tthis.mergeTree.removeLocalReferencePosition(ob.data.end);\n\t\t}\n\t}\n\n\tpublic onNormalize(): void {\n\t\tthis.startOrdered.onSortOrderChange();\n\t}\n\n\tpublic addOrUpdate(obliterateInfo: ObliterateInfo): void {\n\t\tconst {\n\t\t\tstamp: { seq },\n\t\t\tstart,\n\t\t} = obliterateInfo;\n\t\tif (seq !== UnassignedSequenceNumber) {\n\t\t\tthis.seqOrdered.push(obliterateInfo);\n\t\t}\n\t\tthis.startOrdered.addOrUpdate(start);\n\t}\n\n\tpublic empty(): boolean {\n\t\treturn this.startOrdered.size === 0;\n\t}\n\n\tpublic findOverlapping(seg: ISegmentLeaf): Iterable<ObliterateInfo> {\n\t\tconst overlapping: ObliterateInfo[] = [];\n\t\tfor (const start of this.startOrdered.items) {\n\t\t\tconst startSeg = start.getSegment();\n\t\t\tif (isMergeNodeInfo(startSeg) && startSeg.ordinal <= seg.ordinal) {\n\t\t\t\tconst ob = start.properties?.obliterate as ObliterateInfo;\n\t\t\t\tconst endSeg = ob.end.getSegment();\n\t\t\t\tif (isMergeNodeInfo(endSeg) && endSeg.ordinal >= seg.ordinal) {\n\t\t\t\t\toverlapping.push(ob);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// the start is past the seg, so exit\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn overlapping;\n\t}\n\n\t/**\n\t * Remove a local obliterate from this data structure.\n\t * @privateRemarks\n\t * This data structure could support removing non-local obliterates if we wanted it to, but when adding support for that\n\t * we should reconsider the indexing structure for seq ordered obliterates (right now it would be an O(# obliterates) operation)\n\t */\n\tpublic removeLocalObliterate(obliterateInfo: ObliterateInfo): void {\n\t\tassert(\n\t\t\tobliterateInfo.stamp.seq === UnassignedSequenceNumber,\n\t\t\t0xb6e /* Expected local obliterate */,\n\t\t);\n\t\tthis.startOrdered.remove(obliterateInfo.start);\n\t}\n\n\t/**\n\t * Returns an iterator over the `ObliterateInfo` for all obliterates in the collab window. Obliterates are not guaranteed to be ordered.\n\t * The iterator is not guaranteed to be valid over edits to the set of obliterates.\n\t */\n\tpublic [Symbol.iterator](): IterableIterator<ObliterateInfo> {\n\t\tlet index = 0;\n\t\tconst { items: starts } = this.startOrdered;\n\t\tconst iterator: IterableIterator<ObliterateInfo> = {\n\t\t\tnext(): IteratorResult<ObliterateInfo> {\n\t\t\t\tif (index < starts.length) {\n\t\t\t\t\tconst start = starts[index++];\n\t\t\t\t\tconst info = start.properties?.obliterate as ObliterateInfo;\n\t\t\t\t\tassert(\n\t\t\t\t\t\tinfo?.start !== undefined && info?.end !== undefined,\n\t\t\t\t\t\t0xb6f /* Expected obliterateInfo endpoint to map to its obliterate */,\n\t\t\t\t\t);\n\t\t\t\t\treturn { value: info, done: false };\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\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n}\n\ninterface InsertResult {\n\t/**\n\t * If the insertion necessitated rebalancing, this field contains a `MergeBlock` that should be inserted after the block that `insertRecursive` was called on.\n\t */\n\tremainder: MergeBlock | undefined;\n\t/**\n\t * Whether the insert changed anything (including recursive changes) in the subtree of the block that `insertRecursive` was called on.\n\t */\n\thadChanges: boolean;\n}\n\n/**\n * @internal\n */\nexport class MergeTree {\n\tpublic static readonly options = {\n\t\tincrementalUpdate: true,\n\t\tinsertAfterRemovedSegs: true,\n\t\tzamboniSegments: true,\n\t};\n\n\t/**\n\t * A sentinel value that indicates an inserting walk should continue to the next block sibling.\n\t * This can occur for example when tie-break forces insertion of a segment past an entire block (and\n\t * the inserting walk first recurses into the block before realizing that).\n\t */\n\tprivate static readonly theUnfinishedNode = { childCount: -1 } as unknown as MergeBlock;\n\n\tpublic readonly collabWindow = new CollaborationWindow();\n\n\tpublic readonly pendingSegments = new DoublyLinkedList<SegmentGroup>();\n\n\tpublic readonly segmentsToScour = new Heap<LRUSegment>(LRUSegmentComparer);\n\n\tpublic readonly attributionPolicy: AttributionPolicy | undefined;\n\n\tpublic get localPerspective(): Perspective {\n\t\treturn this.collabWindow.localPerspective;\n\t}\n\n\t/**\n\t * Whether or not all blocks in the mergeTree currently have information about local partial lengths computed.\n\t * This information is only necessary on reconnect, and otherwise costly to bookkeep.\n\t * This field enables tracking whether partials need to be recomputed using localSeq information.\n\t */\n\tprivate localPartialsComputed = false;\n\t// for now assume only markers have ids and so point directly at the Segment\n\t// if we need to have pointers to non-markers, we can change to point at local refs\n\tprivate readonly idToMarker = new Map<string, Marker>();\n\tpublic mergeTreeDeltaCallback?: MergeTreeDeltaCallback;\n\tpublic mergeTreeMaintenanceCallback?: MergeTreeMaintenanceCallback;\n\n\t// TODO:AB#29553: This property doesn't seem to be adequately round-tripped through summarization.\n\t// Specifically, it seems like we drop information about obliterates within the collab window for at least V1 summaries.\n\tprivate readonly obliterates = new Obliterates(this);\n\n\tpublic constructor(public options?: IMergeTreeOptionsInternal) {\n\t\tthis._root = this.makeBlock(0);\n\t\tthis._root.mergeTree = this;\n\t\tthis.attributionPolicy = options?.attribution?.policyFactory?.();\n\t}\n\n\tpublic rebaseObliterateTo(\n\t\texisting: ObliterateInfo,\n\t\tnewObliterate: ObliterateInfo | undefined,\n\t): void {\n\t\tthis.obliterates.removeLocalObliterate(existing);\n\t\tif (newObliterate !== undefined) {\n\t\t\tthis.obliterates.addOrUpdate(newObliterate);\n\t\t}\n\t}\n\n\tprivate _root: IRootMergeBlock;\n\tpublic get root(): IRootMergeBlock {\n\t\treturn this._root;\n\t}\n\n\tpublic set root(value: IRootMergeBlock) {\n\t\tthis._root = value;\n\t\tvalue.mergeTree = this;\n\t}\n\n\tpublic makeBlock(childCount: number): MergeBlock {\n\t\tconst block = new MergeBlock(childCount);\n\t\tblock.ordinal = \"\";\n\t\treturn block;\n\t}\n\n\t/**\n\t * Compute the net length of this segment leaf from some perspective.\n\t * @returns Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore\n\t * may not even be present on clients that have loaded from a summary beyond this point). Otherwise, the length of the segment.\n\t */\n\tpublic leafLength(\n\t\tsegment: ISegmentLeaf,\n\t\tperspective: Perspective = this.localPerspective,\n\t): number | undefined {\n\t\tconst removalInfo = toRemovalInfo(segment);\n\t\tif (\n\t\t\tremovalInfo &&\n\t\t\tgetMinSeqPerspective(this.collabWindow).hasOccurred(removalInfo.removes[0])\n\t\t) {\n\t\t\t// this segment's removal has already moved outside the collab window which means it is zamboni eligible\n\t\t\t// this also means the segment could be completely absent from other client's in-memory merge trees,\n\t\t\t// so we should not consider it when making decisions about conflict resolutions\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn perspective.isSegmentPresent(segment) ? segment.cachedLength : 0;\n\t}\n\n\tpublic unlinkMarker(marker: Marker): void {\n\t\tconst id = marker.getId();\n\t\tif (id) {\n\t\t\tthis.idToMarker.delete(id);\n\t\t}\n\t}\n\n\tprivate addNode(block: MergeBlock, node: IMergeNodeBuilder): number {\n\t\tconst index = block.childCount++;\n\t\tassignChild(block, node, index, false);\n\t\treturn index;\n\t}\n\n\tpublic reloadFromSegments(segments: SegmentWithInfo<IHasInsertionInfo>[]): void {\n\t\t// This code assumes that a later call to `startCollaboration()` will initialize partial lengths.\n\t\tassert(\n\t\t\t!this.collabWindow.collaborating,\n\t\t\t0x049 /* \"Trying to reload from segments while collaborating!\" */,\n\t\t);\n\n\t\tconst maxChildren = MaxNodesInBlock - 1;\n\n\t\t// Starting with the leaf segments, recursively builds the B-Tree layer by layer from the bottom up.\n\t\tconst buildMergeBlock = (nodes: IMergeNodeBuilder[]): IRootMergeBlock => {\n\t\t\tconst blockCount = Math.ceil(nodes.length / maxChildren); // Compute # blocks require for this level of B-Tree\n\t\t\tconst blocks: MergeBlock[] = Array.from({ length: blockCount }); // Pre-alloc array to collect nodes\n\n\t\t\t// For each block in this level of the B-Tree...\n\t\t\tfor (\n\t\t\t\tlet nodeIndex = 0, blockIndex = 0; // Start with the first block and first node\n\t\t\t\tblockIndex < blockCount; // If we have more blocks, we also have more nodes to insert\n\t\t\t\tblockIndex++ // Advance to next block in this layer.\n\t\t\t) {\n\t\t\t\tconst block = (blocks[blockIndex] = this.makeBlock(0));\n\n\t\t\t\t// For each child of the current block, insert a node (while we have nodes left)\n\t\t\t\t// and update the block's info.\n\t\t\t\tfor (\n\t\t\t\t\tlet childIndex = 0;\n\t\t\t\t\tchildIndex < maxChildren && nodeIndex < nodes.length; // While we still have children & nodes left\n\t\t\t\t\tchildIndex++, nodeIndex++ // Advance to next child & node\n\t\t\t\t) {\n\t\t\t\t\t// Insert the next node into the current block\n\t\t\t\t\tthis.addNode(block, nodes[nodeIndex]);\n\t\t\t\t}\n\n\t\t\t\t// Calculate this block's info. Previously this was inlined into the above loop as a micro-optimization,\n\t\t\t\t// but it turns out to be negligible in practice since `reloadFromSegments()` is only invoked for the\n\t\t\t\t// snapshot header. The bulk of the segments in long documents are inserted via `insertSegments()`.\n\t\t\t\tthis.blockUpdate(block);\n\t\t\t}\n\n\t\t\treturn blocks.length === 1 // If there is only one block at this layer...\n\t\t\t\t? blocks[0] // ...then we're done. Return the root.\n\t\t\t\t: buildMergeBlock(blocks); // ...otherwise recursively build the next layer above blocks.\n\t\t};\n\t\tif (segments.length > 0) {\n\t\t\tthis.root = buildMergeBlock(segments);\n\t\t\tthis.nodeUpdateOrdinals(this.root);\n\t\t} else {\n\t\t\tthis.root = this.makeBlock(0);\n\t\t}\n\t}\n\n\t// For now assume min starts at zero\n\tpublic startCollaboration(localClientId: number, minSeq: number, currentSeq: number): void {\n\t\tthis.collabWindow.clientId = localClientId;\n\t\tthis.collabWindow.minSeq = minSeq;\n\t\tthis.collabWindow.collaborating = true;\n\t\tthis.collabWindow.currentSeq = currentSeq;\n\t\tthis.collabWindow.localPerspective = new LocalDefaultPerspective(localClientId);\n\t\tthis.nodeUpdateLengthNewStructure(this.root, true);\n\t}\n\n\tprivate addToLRUSet(leaf: ISegmentLeaf, seq: number): void {\n\t\t// If the parent node has not yet been marked for scour (i.e., needsScour is not false or undefined),\n\t\t// add the segment and mark the mark the node now.\n\n\t\t// TODO: 'seq' may be less than the current sequence number when inserting pre-ACKed\n\t\t// segments from a snapshot. We currently skip these for now.\n\t\tif (leaf.parent.needsScour !== true && seq > this.collabWindow.currentSeq) {\n\t\t\tleaf.parent.needsScour = true;\n\t\t\tthis.segmentsToScour.add({ segment: leaf, maxSeq: seq });\n\t\t}\n\t}\n\n\tpublic getLength(perspective: Perspective): number {\n\t\treturn this.nodeLength(this.root, perspective) ?? 0;\n\t}\n\n\t/**\n\t * Returns the current length of the MergeTree for the local client.\n\t */\n\tpublic get length(): number | undefined {\n\t\treturn this.root.cachedLength;\n\t}\n\n\tpublic getPosition(node: IMergeNode, perspective: Perspective): number {\n\t\tif (node.isLeaf() && node.endpointType === \"start\") {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlet totalOffset = 0;\n\t\tlet parent = node.parent;\n\t\tlet prevParent: MergeBlock | undefined;\n\t\twhile (parent) {\n\t\t\tconst children = parent.children;\n\t\t\tfor (let childIndex = 0; childIndex < parent.childCount; childIndex++) {\n\t\t\t\tconst child = children[childIndex];\n\t\t\t\tif ((!!prevParent && child === prevParent) || child === node) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ttotalOffset += this.nodeLength(child, perspective) ?? 0;\n\t\t\t}\n\t\t\tprevParent = parent;\n\t\t\tparent = parent.parent;\n\t\t}\n\t\treturn totalOffset;\n\t}\n\n\tpublic getContainingSegment(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t):\n\t\t| {\n\t\t\t\tsegment: ISegmentLeaf;\n\t\t\t\toffset: number;\n\t\t }\n\t\t| undefined {\n\t\tassert(\n\t\t\tperspective.localSeq === undefined ||\n\t\t\t\tperspective.clientId === this.collabWindow.clientId,\n\t\t\t0x39b /* localSeq provided for non-local client */,\n\t\t);\n\n\t\tlet segment: ISegmentLeaf | undefined;\n\t\tlet offset: number | undefined;\n\n\t\tconst leaf = (leafSeg: ISegmentLeaf, _: number, start: number): boolean => {\n\t\t\tsegment = leafSeg;\n\t\t\toffset = start;\n\t\t\treturn false;\n\t\t};\n\t\tthis.nodeMap(perspective, leaf, undefined, pos, pos + 1);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { segment, offset };\n\t}\n\n\t/**\n\t * Slides or removes references from the provided list of segments.\n\t *\n\t * The order of the references is preserved for references of the same sliding\n\t * preference. Relative order between references that slide backward and those\n\t * that slide forward is not preserved, even in the case when they slide to\n\t * the same segment.\n\t *\n\t * @remarks\n\t *\n\t * 1. Preserving the order of the references is a useful property for reference-based undo/redo\n\t * (see revertibles.ts).\n\t *\n\t * 2. For use cases which necessitate eventual consistency across clients,\n\t * this method should only be called with segments for which the current client sequence number is\n\t * max(remove segment sequence number, add reference sequence number).\n\t * See `packages\\dds\\merge-tree\\REFERENCEPOSITIONS.md`\n\t *\n\t * @param segments - An array of (not necessarily contiguous) segments with increasing ordinals.\n\t */\n\tprivate slideAckedRemovedSegmentReferences(segments: ISegmentLeaf[]): void {\n\t\t// References are slid in groups to preserve their order.\n\t\tlet currentForwardSlideGroup: LocalReferenceCollection[] = [];\n\t\tlet currentBackwardSlideGroup: LocalReferenceCollection[] = [];\n\n\t\tlet currentForwardMaybeEndpoint: \"start\" | \"end\" | undefined;\n\t\tlet currentForwardSlideDestination: ISegmentLeaf | undefined;\n\t\tlet currentForwardSlideIsForward: boolean | undefined;\n\n\t\tlet currentBackwardMaybeEndpoint: \"start\" | \"end\" | undefined;\n\t\tlet currentBackwardSlideDestination: ISegmentLeaf | undefined;\n\t\tlet currentBackwardSlideIsForward: boolean | undefined;\n\n\t\tconst slideGroup = (\n\t\t\tcurrentSlideDestination: ISegmentLeaf | undefined,\n\t\t\tcurrentSlideIsForward: boolean | undefined,\n\t\t\tcurrentSlideGroup: LocalReferenceCollection[],\n\t\t\tpred: (ref: LocalReferencePosition) => boolean,\n\t\t\tmaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t): void => {\n\t\t\tif (currentSlideIsForward === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nonEndpointRefsToAdd = currentSlideGroup.map((collection) =>\n\t\t\t\tfilterLocalReferencePositions(\n\t\t\t\t\tcollection,\n\t\t\t\t\t(ref) => pred(ref) && (maybeEndpoint ? !ref.canSlideToEndpoint : true),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tconst endpointRefsToAdd = currentSlideGroup.map((collection) =>\n\t\t\t\tfilterLocalReferencePositions(\n\t\t\t\t\tcollection,\n\t\t\t\t\t(ref) => pred(ref) && !!ref.canSlideToEndpoint,\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tif (maybeEndpoint) {\n\t\t\t\tconst endpoint = maybeEndpoint === \"start\" ? this.startOfTree : this.endOfTree;\n\t\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(endpoint);\n\t\t\t\tif (currentSlideIsForward) {\n\t\t\t\t\tlocalRefs.addBeforeTombstones(...endpointRefsToAdd);\n\t\t\t\t} else {\n\t\t\t\t\tlocalRefs.addAfterTombstones(...endpointRefsToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentSlideDestination === undefined) {\n\t\t\t\tfor (const collection of currentSlideGroup) {\n\t\t\t\t\tfor (const ref of collection) {\n\t\t\t\t\t\tif (pred(ref) && !refTypeIncludesFlag(ref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\t\t\tref.callbacks?.beforeSlide?.(ref);\n\t\t\t\t\t\t\tcollection.removeLocalRef(ref);\n\t\t\t\t\t\t\tref.callbacks?.afterSlide?.(ref);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(currentSlideDestination);\n\t\t\t\tif (currentSlideIsForward) {\n\t\t\t\t\tlocalRefs.addBeforeTombstones(...nonEndpointRefsToAdd);\n\t\t\t\t} else {\n\t\t\t\t\tlocalRefs.addAfterTombstones(...nonEndpointRefsToAdd);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst trySlideSegment = (\n\t\t\tsegment: ISegmentLeaf,\n\t\t\tcurrentSlideDestination: ISegmentLeaf | undefined,\n\t\t\tcurrentSlideIsForward: boolean | undefined,\n\t\t\tcurrentSlideGroup: LocalReferenceCollection[],\n\t\t\tpred: (ref: LocalReferencePosition) => boolean,\n\t\t\tslidingPreference: SlidingPreference,\n\t\t\tcurrentMaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t\treassign: (\n\t\t\t\tlocalRefs: LocalReferenceCollection,\n\t\t\t\tslideToSegment: ISegmentLeaf | undefined,\n\t\t\t\tslideIsForward: boolean,\n\t\t\t\tmaybeEndpoint: \"start\" | \"end\" | undefined,\n\t\t\t) => void,\n\t\t): void => {\n\t\t\t// avoid sliding logic if this segment doesn't have any references\n\t\t\t// with the given sliding preference\n\t\t\tif (!segment.localRefs || !anyLocalReferencePosition(segment.localRefs, pred)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst [slideToSegment, maybeEndpoint] = getSlideToSegment(\n\t\t\t\tsegment,\n\t\t\t\tslidingPreference,\n\t\t\t\tallAckedChangesPerspective,\n\t\t\t\tslidingPreference === SlidingPreference.FORWARD\n\t\t\t\t\t? forwardSegmentCache\n\t\t\t\t\t: backwardSegmentCache,\n\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint,\n\t\t\t);\n\t\t\tconst slideIsForward =\n\t\t\t\tslideToSegment === undefined ? false : slideToSegment.ordinal > segment.ordinal;\n\n\t\t\tif (\n\t\t\t\tslideToSegment !== currentSlideDestination ||\n\t\t\t\tslideIsForward !== currentSlideIsForward ||\n\t\t\t\tmaybeEndpoint !== currentMaybeEndpoint\n\t\t\t) {\n\t\t\t\tslideGroup(\n\t\t\t\t\tcurrentSlideDestination,\n\t\t\t\t\tcurrentSlideIsForward,\n\t\t\t\t\tcurrentSlideGroup,\n\t\t\t\t\tpred,\n\t\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint ? maybeEndpoint : undefined,\n\t\t\t\t);\n\t\t\t\treassign(\n\t\t\t\t\tsegment.localRefs,\n\t\t\t\t\tslideToSegment,\n\t\t\t\t\tslideIsForward,\n\t\t\t\t\tthis.options?.mergeTreeReferencesCanSlideToEndpoint ? maybeEndpoint : undefined,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tcurrentSlideGroup.push(segment.localRefs);\n\t\t\t}\n\t\t};\n\n\t\tconst forwardSegmentCache = new Map<ISegmentLeaf, { seg?: ISegmentLeaf }>();\n\t\tconst backwardSegmentCache = new Map<ISegmentLeaf, { seg?: ISegmentLeaf }>();\n\t\tfor (const segment of segments) {\n\t\t\tassert(\n\t\t\t\tisRemovedAndAcked(segment),\n\t\t\t\t0x2f1 /* slideReferences from a segment which has not been removed and acked */,\n\t\t\t);\n\t\t\tif (segment.localRefs === undefined || segment.localRefs.empty) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttrySlideSegment(\n\t\t\t\tsegment,\n\t\t\t\tcurrentForwardSlideDestination,\n\t\t\t\tcurrentForwardSlideIsForward,\n\t\t\t\tcurrentForwardSlideGroup,\n\t\t\t\tforwardPred,\n\t\t\t\tSlidingPreference.FORWARD,\n\t\t\t\tcurrentForwardMaybeEndpoint,\n\t\t\t\t(localRefs, slideToSegment, slideIsForward, maybeEndpoint) => {\n\t\t\t\t\tcurrentForwardSlideGroup = [localRefs];\n\t\t\t\t\tcurrentForwardSlideDestination = slideToSegment;\n\t\t\t\t\tcurrentForwardSlideIsForward = slideIsForward;\n\t\t\t\t\tcurrentForwardMaybeEndpoint = maybeEndpoint;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\ttrySlideSegment(\n\t\t\t\tsegment,\n\t\t\t\tcurrentBackwardSlideDestination,\n\t\t\t\tcurrentBackwardSlideIsForward,\n\t\t\t\tcurrentBackwardSlideGroup,\n\t\t\t\tbackwardPred,\n\t\t\t\tSlidingPreference.BACKWARD,\n\t\t\t\tcurrentBackwardMaybeEndpoint,\n\t\t\t\t(localRefs, slideToSegment, slideIsForward, maybeEndpoint) => {\n\t\t\t\t\tcurrentBackwardSlideGroup = [localRefs];\n\t\t\t\t\tcurrentBackwardSlideDestination = slideToSegment;\n\t\t\t\t\tcurrentBackwardSlideIsForward = slideIsForward;\n\t\t\t\t\tcurrentBackwardMaybeEndpoint = maybeEndpoint;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tslideGroup(\n\t\t\tcurrentForwardSlideDestination,\n\t\t\tcurrentForwardSlideIsForward,\n\t\t\tcurrentForwardSlideGroup,\n\t\t\tforwardPred,\n\t\t\tcurrentForwardMaybeEndpoint,\n\t\t);\n\t\tslideGroup(\n\t\t\tcurrentBackwardSlideDestination,\n\t\t\tcurrentBackwardSlideIsForward,\n\t\t\tcurrentBackwardSlideGroup,\n\t\t\tbackwardPred,\n\t\t\tcurrentBackwardMaybeEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Compute local partial length information\n\t *\n\t * Public only for use by internal tests\n\t */\n\tpublic computeLocalPartials(refSeq: number): void {\n\t\tif (this.localPartialsComputed) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rebaseCollabWindow = new CollaborationWindow();\n\t\trebaseCollabWindow.loadFrom(this.collabWindow);\n\t\tif (refSeq < this.collabWindow.minSeq) {\n\t\t\trebaseCollabWindow.minSeq = refSeq;\n\t\t}\n\t\tthis.root.partialLengths = PartialSequenceLengths.combine(\n\t\t\tthis.root,\n\t\t\trebaseCollabWindow,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t\tthis.localPartialsComputed = true;\n\t}\n\n\tprivate nodeLength(node: IMergeNode, perspective: Perspective): number | undefined {\n\t\tif (node.isLeaf()) {\n\t\t\treturn this.leafLength(node, perspective);\n\t\t}\n\n\t\tconst { refSeq, clientId, localSeq } = perspective;\n\n\t\tconst isLocalPerspective =\n\t\t\t!this.collabWindow.collaborating || this.collabWindow.clientId === clientId;\n\t\tif (\n\t\t\tisLocalPerspective &&\n\t\t\t(localSeq === undefined ||\n\t\t\t\t(localSeq === this.collabWindow.localSeq && refSeq >= this.collabWindow.currentSeq))\n\t\t) {\n\t\t\t// All changes are visible. Small note on why we allow refSeq >= this.collabWindow.currentSeq rather than just equality:\n\t\t\t// merge-tree eventing occurs before the collab window is updated to account for whatever op it is processing, and we want\n\t\t\t// to support resolving positions from within the event handler which account for that op. e.g. undo-redo relies on this\n\t\t\t// behavior with local references.\n\t\t\treturn node.cachedLength;\n\t\t}\n\n\t\tif (localSeq !== undefined) {\n\t\t\tthis.computeLocalPartials(refSeq);\n\t\t}\n\n\t\tconst length = node.partialLengths!.getPartialLength(refSeq, clientId, localSeq);\n\n\t\tPartialSequenceLengths.options.verifyExpected?.(this, node, refSeq, clientId, localSeq);\n\t\treturn length;\n\t}\n\n\tpublic setMinSeq(minSeq: number): void {\n\t\tassert(\n\t\t\tminSeq <= this.collabWindow.currentSeq,\n\t\t\t0x04e /* \"Trying to set minSeq above currentSeq of collab window!\" */,\n\t\t);\n\n\t\t// Only move forward\n\t\tassert(\n\t\t\tthis.collabWindow.minSeq <= minSeq,\n\t\t\t0x04f /* \"minSeq of collab window > target minSeq!\" */,\n\t\t);\n\n\t\tif (minSeq > this.collabWindow.minSeq) {\n\t\t\tthis.collabWindow.minSeq = minSeq;\n\t\t\tthis.obliterates.setMinSeq(minSeq);\n\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\tzamboniSegments(this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the count of elements before the given reference position from the given perspective.\n\t *\n\t * @param refPos - The reference position to resolve.\n\t * @param refSeq - The number of the latest sequenced change to consider.\n\t * Defaults to including all edits which have been applied.\n\t * @param clientId - The ID of the client from whose perspective to resolve this reference. Defaults to the current client.\n\t * @param localSeq - The local sequence number to consider. Defaults to including all local edits.\n\t */\n\tpublic referencePositionToLocalPosition(\n\t\trefPos: ReferencePosition,\n\t\t// Note: this is not `this.collabWindow.currentSeq` because we want to support resolving local reference positions to positions\n\t\t// from within event handlers, and the collab window's sequence numbers are not updated in time in all of those cases.\n\t\trefSeq = Number.MAX_SAFE_INTEGER,\n\t\tclientId = this.collabWindow.clientId,\n\t\tlocalSeq: number | undefined = undefined,\n\t): number {\n\t\tconst perspective =\n\t\t\tclientId === this.collabWindow.clientId\n\t\t\t\t? localSeq === undefined\n\t\t\t\t\t? this.localPerspective\n\t\t\t\t\t: new LocalReconnectingPerspective(refSeq, clientId, localSeq)\n\t\t\t\t: new PriorPerspective(refSeq, clientId);\n\t\tconst seg = refPos.getSegment();\n\t\tif (seg === undefined || !isSegmentLeaf(seg)) {\n\t\t\t// We have no idea where this reference is, because it refers to a segment which is not in the tree.\n\t\t\treturn DetachedReferencePosition;\n\t\t}\n\t\tif (refPos.isLeaf()) {\n\t\t\treturn this.getPosition(seg, perspective);\n\t\t}\n\t\tif (refTypeIncludesFlag(refPos, ReferenceType.Transient) || seg.localRefs?.has(refPos)) {\n\t\t\tif (\n\t\t\t\tseg !== this.startOfTree &&\n\t\t\t\tseg !== this.endOfTree &&\n\t\t\t\t!perspective.isSegmentPresent(seg)\n\t\t\t) {\n\t\t\t\tconst forward = refPos.slidingPreference === SlidingPreference.FORWARD;\n\t\t\t\tconst removeInfo = toRemovalInfo(seg);\n\t\t\t\tconst firstRemove = removeInfo?.removes[0];\n\t\t\t\tconst slideSeq =\n\t\t\t\t\tfirstRemove !== undefined && opstampUtils.isAcked(firstRemove)\n\t\t\t\t\t\t? firstRemove.seq\n\t\t\t\t\t\t: refSeq;\n\n\t\t\t\tconst slidePerspective =\n\t\t\t\t\tfirstRemove?.localSeq === undefined\n\t\t\t\t\t\t? new PriorPerspective(slideSeq, this.collabWindow.clientId)\n\t\t\t\t\t\t: new LocalReconnectingPerspective(\n\t\t\t\t\t\t\t\tslideSeq,\n\t\t\t\t\t\t\t\tthis.collabWindow.clientId,\n\t\t\t\t\t\t\t\tfirstRemove.localSeq,\n\t\t\t\t\t\t\t);\n\n\t\t\t\tconst slidSegment = this.nextSegment(slidePerspective, seg, forward);\n\t\t\t\treturn (\n\t\t\t\t\tthis.getPosition(slidSegment, perspective) +\n\t\t\t\t\t(forward ? 0 : slidSegment.cachedLength === 0 ? 0 : slidSegment.cachedLength - 1)\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.getPosition(seg, perspective) + refPos.getOffset();\n\t\t}\n\t\treturn DetachedReferencePosition;\n\t}\n\n\t/**\n\t * Returns the immediately adjacent segment in the specified direction from this perspective.\n\t * There may actually be multiple segments between the given segment and the returned segment,\n\t * but they were either inserted after this perspective, or have been removed before this perspective.\n\t *\n\t * @param segment - The segment to start from.\n\t * @param forward - The direction to search.\n\t * @returns the next segment in the specified direction, or the start or end of the tree if there is no next segment.\n\t */\n\tprivate nextSegment(\n\t\tperspective: Perspective,\n\t\tsegment: ISegmentLeaf,\n\t\tforward: boolean = true,\n\t): ISegmentLeaf {\n\t\tlet next: ISegmentLeaf | undefined;\n\t\tconst action = (seg: ISegmentLeaf): boolean | undefined => {\n\t\t\tif (perspective.isSegmentPresent(seg)) {\n\t\t\t\tnext = seg;\n\t\t\t\treturn LeafAction.Exit;\n\t\t\t}\n\t\t};\n\t\t(forward ? forwardExcursion : backwardExcursion)(segment, action);\n\t\treturn next ?? (forward ? this.endOfTree : this.startOfTree);\n\t}\n\n\t/**\n\t * Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `forwards`.\n\t * Uses depthFirstNodeWalk in addition to block-accelerated functionality. The search position will be included in\n\t * the nodes to walk, so searching on all positions, including the endpoints, can be considered inclusive.\n\t * Any out of bound search positions will return undefined, so in order to search the whole string, a forward\n\t * search can begin at 0, or a backward search can begin at length-1.\n\t *\n\t * @param startPos - Position at which to start the search\n\t * @param clientId - clientId dictating the perspective to search from\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the string should be searched in the forward or backward direction\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\tlet foundMarker: Marker | undefined;\n\n\t\tconst segoff = this.getContainingSegment(startPos, this.localPerspective);\n\t\tif (!isSegmentLeaf(segoff?.segment)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst { segment } = segoff;\n\n\t\tdepthFirstNodeWalk(\n\t\t\tsegment.parent,\n\t\t\tsegment,\n\t\t\t(node) => {\n\t\t\t\tif (node.isLeaf()) {\n\t\t\t\t\tif (!isRemoved(node) && Marker.is(node) && refHasTileLabel(node, markerLabel)) {\n\t\t\t\t\t\tfoundMarker = node;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst marker = forwards\n\t\t\t\t\t\t? node.leftmostTiles[markerLabel]\n\t\t\t\t\t\t: node.rightmostTiles[markerLabel];\n\t\t\t\t\tif (marker !== undefined) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tmarker.isLeaf() && Marker.is(marker),\n\t\t\t\t\t\t\t0x751 /* Object returned is not a valid marker */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tfoundMarker = marker;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn foundMarker === undefined ? NodeAction.Skip : NodeAction.Exit;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tforwards,\n\t\t);\n\n\t\treturn foundMarker;\n\t}\n\n\tprivate updateRoot(splitNode: MergeBlock): void {\n\t\tconst newRoot = this.makeBlock(2);\n\t\tassignChild(newRoot, this.root, 0, false);\n\t\tassignChild(newRoot, splitNode, 1, false);\n\t\tthis.root = newRoot;\n\t\tthis.nodeUpdateOrdinals(this.root);\n\t\tthis.nodeUpdateLengthNewStructure(this.root);\n\t}\n\n\t/**\n\t * Assign sequence number to existing segments affected by an op; update partial lengths to reflect the change\n\t */\n\tpublic ackOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tconst seq = opArgs.sequencedMessage!.sequenceNumber;\n\t\tconst stamp: OperationStamp = {\n\t\t\tseq,\n\t\t\tclientId: this.collabWindow.clientId,\n\t\t};\n\t\tconst pendingSegmentGroup = this.pendingSegments.shift()?.data;\n\t\tconst nodesToUpdate: MergeBlock[] = [];\n\t\tlet overwrite = false;\n\t\tif (pendingSegmentGroup !== undefined) {\n\t\t\tconst { obliterateInfo, segments } = pendingSegmentGroup;\n\t\t\tconst hasObliterateInfo = obliterateInfo !== undefined;\n\t\t\tconst isObliterate =\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED;\n\t\t\tassert(hasObliterateInfo === isObliterate, 0xa40 /* must have obliterate info */);\n\t\t\tif (hasObliterateInfo) {\n\t\t\t\tobliterateInfo.stamp = { ...stamp, type: \"sliceRemove\" };\n\t\t\t\tthis.obliterates.addOrUpdate(obliterateInfo);\n\t\t\t\tassert(\n\t\t\t\t\tobliterateInfo.tiebreakTrackingGroup !== undefined,\n\t\t\t\t\t0xb70 /* obliterateInfo should have a tiebreak tracking group on ack */,\n\t\t\t\t);\n\t\t\t\tfor (const segment of obliterateInfo.tiebreakTrackingGroup.tracked) {\n\t\t\t\t\tsegment.trackingCollection.unlink(obliterateInfo.tiebreakTrackingGroup);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tisSegmentLeaf(segment) && isInsideObliterate(segment),\n\t\t\t\t\t\t0xb71 /* Expected segment leaf inside obliterate */,\n\t\t\t\t\t);\n\t\t\t\t\tsegment.insertionRefSeqStamp = undefined;\n\t\t\t\t}\n\t\t\t\tobliterateInfo.tiebreakTrackingGroup = undefined;\n\t\t\t}\n\n\t\t\tconst deltaSegments: IMergeTreeSegmentDelta[] = [];\n\t\t\tconst overlappingRemoves: boolean[] = [];\n\t\t\tsegments.map((pendingSegment: ISegmentLeaf) => {\n\t\t\t\tconst overlappingRemove = !ackSegment(\n\t\t\t\t\tpendingSegment,\n\t\t\t\t\tpendingSegmentGroup,\n\t\t\t\t\topArgs,\n\t\t\t\t\tstamp,\n\t\t\t\t);\n\n\t\t\t\toverwrite ||= overlappingRemove;\n\n\t\t\t\toverlappingRemoves.push(overlappingRemove);\n\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\tthis.addToLRUSet(pendingSegment, seq);\n\t\t\t\t}\n\t\t\t\tif (!nodesToUpdate.includes(pendingSegment.parent)) {\n\t\t\t\t\tnodesToUpdate.push(pendingSegment.parent);\n\t\t\t\t}\n\t\t\t\tdeltaSegments.push({\n\t\t\t\t\tsegment: pendingSegment,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// Perform slides after all segments have been acked, so that\n\t\t\t// positions after slide are final\n\t\t\tif (\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.REMOVE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED\n\t\t\t) {\n\t\t\t\tthis.slideAckedRemovedSegmentReferences(segments);\n\t\t\t}\n\n\t\t\tthis.mergeTreeMaintenanceCallback?.(\n\t\t\t\t{\n\t\t\t\t\tdeltaSegments,\n\t\t\t\t\toperation: MergeTreeMaintenanceType.ACKNOWLEDGED,\n\t\t\t\t},\n\t\t\t\topArgs,\n\t\t\t);\n\n\t\t\tfor (const node of nodesToUpdate) {\n\t\t\t\tthis.blockUpdatePathLengths(node, stamp, overwrite);\n\t\t\t}\n\t\t}\n\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tprivate addToPendingList(\n\t\tsegment: ISegmentLeaf,\n\n\t\tsegmentGroup?: SegmentGroup,\n\t\tlocalSeq?: number,\n\t\tpreviousProps?: PropertySet,\n\t): SegmentGroup {\n\t\tlet _segmentGroup = segmentGroup;\n\t\tif (_segmentGroup === undefined) {\n\t\t\tassert(\n\t\t\t\tlocalSeq !== undefined,\n\t\t\t\t0xb72 /* Local seq should be passed when creating new segment group */,\n\t\t\t);\n\t\t\t_segmentGroup = {\n\t\t\t\tsegments: [],\n\t\t\t\tlocalSeq,\n\t\t\t\trefSeq: this.collabWindow.currentSeq,\n\t\t\t};\n\t\t\tif (previousProps) {\n\t\t\t\t_segmentGroup.previousProps = [];\n\t\t\t}\n\t\t\tthis.pendingSegments.push(_segmentGroup);\n\t\t}\n\n\t\tif (\n\t\t\t(!_segmentGroup.previousProps && !!previousProps) ||\n\t\t\t(!!_segmentGroup.previousProps && !previousProps)\n\t\t) {\n\t\t\tthrow new Error(\"All segments in group should have previousProps or none\");\n\t\t}\n\t\tif (previousProps) {\n\t\t\t_segmentGroup.previousProps!.push(previousProps);\n\t\t}\n\n\t\tconst segmentGroups = (segment.segmentGroups ??= new SegmentGroupCollection(segment));\n\t\tsegmentGroups.enqueue(_segmentGroup);\n\t\treturn _segmentGroup;\n\t}\n\n\t// TODO: error checking\n\tpublic getMarkerFromId(id: string): Marker | undefined {\n\t\tconst marker = this.idToMarker.get(id);\n\t\treturn marker === undefined || isRemoved(marker) ? undefined : marker;\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t * @param refseq - The reference sequence number at which to compute the position.\n\t * @param clientId - The client id with which to compute the position.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition, perspective: Perspective): number {\n\t\tlet pos = -1;\n\t\tlet marker: Marker | undefined;\n\t\tif (relativePos.id) {\n\t\t\tmarker = this.getMarkerFromId(relativePos.id);\n\t\t}\n\t\tif (isSegmentLeaf(marker)) {\n\t\t\tpos = this.getPosition(marker, perspective);\n\t\t\tif (relativePos.before) {\n\t\t\t\tif (relativePos.offset !== undefined) {\n\t\t\t\t\tpos -= relativePos.offset;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpos += marker.cachedLength;\n\t\t\t\tif (relativePos.offset !== undefined) {\n\t\t\t\t\tpos += relativePos.offset;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn pos;\n\t}\n\n\tpublic insertSegments(\n\t\tpos: number,\n\t\tsegments: ISegmentPrivate[],\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs | undefined,\n\t): void {\n\t\tconst stamp: InsertOperationStamp = { ...stampArg, type: \"insert\" };\n\t\tthis.ensureIntervalBoundary(pos, perspective);\n\n\t\tthis.blockInsert(pos, perspective, stamp, segments);\n\n\t\t// opArgs == undefined => loading snapshot or test code\n\t\tif (opArgs !== undefined) {\n\t\t\tconst deltaSegments = segments\n\t\t\t\t.filter((segment) => !isRemoved(segment))\n\t\t\t\t.map((segment) => ({ segment }));\n\n\t\t\tif (deltaSegments.length > 0) {\n\t\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\t\t\tdeltaSegments,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\tMergeTree.options.zamboniSegments &&\n\t\t\topstampUtils.isAcked(stamp)\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: number,\n\t): number | undefined {\n\t\tif (remoteClientRefSeq < this.collabWindow.minSeq) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst remotePerspective = new PriorPerspective(remoteClientRefSeq, remoteClientId);\n\t\tconst segmentInfo = this.getContainingSegment(remoteClientPosition, remotePerspective);\n\n\t\tif (isSegmentLeaf(segmentInfo?.segment)) {\n\t\t\tconst segmentPosition = this.getPosition(segmentInfo.segment, this.localPerspective);\n\t\t\treturn segmentPosition + segmentInfo.offset;\n\t\t} else {\n\t\t\tif (remoteClientPosition === this.getLength(remotePerspective)) {\n\t\t\t\treturn this.getLength(this.localPerspective);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate blockInsert<T extends ISegmentPrivate>(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: InsertOperationStamp,\n\t\tnewSegments: T[],\n\t): void {\n\t\t// Keeping this function within the scope of blockInsert for readability.\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst continueFrom = (node: MergeBlock): boolean => {\n\t\t\tlet siblingExists = false;\n\t\t\tforwardExcursion(node, () => {\n\t\t\t\tsiblingExists = true;\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\treturn siblingExists;\n\t\t};\n\n\t\tlet segmentGroup: SegmentGroup;\n\t\tconst saveIfLocal = (locSegment: ISegmentLeaf): void => {\n\t\t\t// Save segment so we can assign sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(locSegment.insert) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(locSegment, segmentGroup, stamp.localSeq);\n\t\t\t\t}\n\t\t\t\t// LocSegment.seq === 0 when coming from SharedSegmentSequence.loadBody()\n\t\t\t\t// In all other cases this has to be true (checked by addToLRUSet):\n\t\t\t\t// locSegment.seq > this.collabWindow.currentSeq\n\t\t\t\telse if (\n\t\t\t\t\tMergeTree.options.zamboniSegments &&\n\t\t\t\t\topstampUtils.greaterThan(locSegment.insert, getMinSeqStamp(this.collabWindow))\n\t\t\t\t) {\n\t\t\t\t\tthis.addToLRUSet(locSegment, locSegment.insert.seq);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst onLeaf = (\n\t\t\tsegment: ISegmentLeaf | undefined,\n\t\t\t_pos: number,\n\t\t\tcontext: InsertContext,\n\t\t\t// Keeping this function within the scope of blockInsert for readability.\n\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\t): ISegmentChanges => {\n\t\t\tconst segmentChanges: ISegmentChanges = {};\n\t\t\tif (segment) {\n\t\t\t\t// Insert before segment\n\t\t\t\tsegmentChanges.replaceCurrent = context.candidateSegment;\n\t\t\t\tsegmentChanges.next = segment;\n\t\t\t} else {\n\t\t\t\tsegmentChanges.next = context.candidateSegment;\n\t\t\t}\n\t\t\treturn segmentChanges;\n\t\t};\n\n\t\t// TODO: build tree from segs and insert all at once\n\t\tlet insertPos = pos;\n\t\tfor (const newSegment of newSegments\n\t\t\t.filter((s) => s.cachedLength > 0)\n\t\t\t.map((s) => overwriteInfo(s, { insert: stamp }))) {\n\t\t\tif (Marker.is(newSegment)) {\n\t\t\t\tconst markerId = newSegment.getId();\n\t\t\t\tif (markerId) {\n\t\t\t\t\tthis.idToMarker.set(markerId, newSegment);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.insertingWalk(insertPos, perspective, stamp, {\n\t\t\t\tleaf: onLeaf,\n\t\t\t\tcandidateSegment: newSegment,\n\t\t\t\tcontinuePredicate: continueFrom,\n\t\t\t});\n\n\t\t\tif (!isSegmentLeaf(newSegment)) {\n\t\t\t\t// Indicates an attempt to insert past the end of the merge-tree's content.\n\t\t\t\tconst errorConstructor =\n\t\t\t\t\tstamp.localSeq === undefined ? DataProcessingError : UsageError;\n\t\t\t\tthrow new errorConstructor(\"MergeTree insert failed\", {\n\t\t\t\t\tcurrentSeq: this.collabWindow.currentSeq,\n\t\t\t\t\tminSeq: this.collabWindow.minSeq,\n\t\t\t\t\tsegSeq: stamp.seq,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tinsertPos += newSegment.cachedLength;\n\n\t\t\tif (!this.options?.mergeTreeEnableObliterate || this.obliterates.empty()) {\n\t\t\t\tsaveIfLocal(newSegment);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst refSeqStamp: OperationStamp = {\n\t\t\t\tseq: perspective.refSeq,\n\t\t\t\tclientId: stamp.clientId,\n\t\t\t};\n\n\t\t\tconst overlappingAckedObliterates: RemoveOperationStamp[] = [];\n\t\t\tlet oldest: ObliterateInfo | undefined;\n\t\t\tlet newest: ObliterateInfo | undefined;\n\t\t\tlet newestAcked: ObliterateInfo | undefined;\n\t\t\tlet oldestUnacked: ObliterateInfo | undefined;\n\n\t\t\tfor (const ob of this.obliterates.findOverlapping(newSegment)) {\n\t\t\t\tif (opstampUtils.greaterThan(ob.stamp, refSeqStamp)) {\n\t\t\t\t\t// Any obliterate from the same client that's inserting this segment cannot cause the segment to be marked as\n\t\t\t\t\t// obliterated (since that client must have performed the obliterate before this insertion).\n\t\t\t\t\t// We still need to consider such obliterates when determining the winning obliterate for the insertion point,\n\t\t\t\t\t// see `obliteratePrecedingInsertion` docs.\n\t\t\t\t\tif (stamp.clientId !== ob.stamp.clientId) {\n\t\t\t\t\t\tif (opstampUtils.isAcked(ob.stamp)) {\n\t\t\t\t\t\t\toverlappingAckedObliterates.push(ob.stamp);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (oldest === undefined || opstampUtils.lessThan(ob.stamp, oldest.stamp)) {\n\t\t\t\t\t\t\toldest = ob;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (newest === undefined || opstampUtils.greaterThan(ob.stamp, newest.stamp)) {\n\t\t\t\t\t\tnewest = ob;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\topstampUtils.isAcked(ob.stamp) &&\n\t\t\t\t\t\t(newestAcked === undefined ||\n\t\t\t\t\t\t\topstampUtils.greaterThan(ob.stamp, newestAcked.stamp))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewestAcked = ob;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\topstampUtils.isLocal(ob.stamp) &&\n\t\t\t\t\t\t(oldestUnacked === undefined ||\n\t\t\t\t\t\t\topstampUtils.greaterThan(oldestUnacked.stamp, ob.stamp))\n\t\t\t\t\t) {\n\t\t\t\t\t\t// There can be one local obliterate surrounding a segment if a client repeatedly obliterates\n\t\t\t\t\t\t// a region (ex: in the text ABCDEFG, obliterate D, then obliterate CE, then BF). In this case,\n\t\t\t\t\t\t// the first one that's applied will be the one that actually removes the segment.\n\t\t\t\t\t\toldestUnacked = ob;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(newSegment, {\n\t\t\t\tobliteratePrecedingInsertion: newest,\n\t\t\t});\n\t\t\tif (newest !== undefined && opstampUtils.isLocal(newest.stamp)) {\n\t\t\t\tassert(\n\t\t\t\t\tnewest?.tiebreakTrackingGroup !== undefined,\n\t\t\t\t\t0xb73 /* Expected local obliterateinfo to have tiebreak group */,\n\t\t\t\t);\n\t\t\t\tnewest.tiebreakTrackingGroup.link(newSegment);\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(newSegment, {\n\t\t\t\t\tinsertionRefSeqStamp: refSeqStamp,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// See doc comment on obliteratePrecedingInsertion for more details: if the newest obliterate was performed\n\t\t\t// by the same client that's inserting this segment, we let them insert into this range and therefore don't\n\t\t\t// mark it obliterated.\n\t\t\tif (oldest && newest?.stamp.clientId !== stamp.clientId) {\n\t\t\t\tconst removeInfo: IHasRemovalInfo = { removes: [] };\n\t\t\t\tif (newestAcked === newest || newestAcked?.stamp.clientId !== stamp.clientId) {\n\t\t\t\t\tremoveInfo.removes = overlappingAckedObliterates;\n\t\t\t\t\t// Because we found these by looking at overlapping obliterates, they are not necessarily currently sorted by seq.\n\t\t\t\t\t// Address that now.\n\t\t\t\t\tremoveInfo.removes.sort(opstampUtils.compare);\n\t\t\t\t}\n\n\t\t\t\t// Note that we don't need to worry about preserving any existing remove information since the segment is new.\n\t\t\t\toverwriteInfo(newSegment, removeInfo);\n\n\t\t\t\tif (oldestUnacked !== undefined) {\n\t\t\t\t\tremoveInfo.removes.push(oldestUnacked.stamp);\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\toldestUnacked.segmentGroup !== undefined,\n\t\t\t\t\t\t0x86c /* expected segment group to exist */,\n\t\t\t\t\t);\n\n\t\t\t\t\tthis.addToPendingList(newSegment, oldestUnacked.segmentGroup);\n\t\t\t\t}\n\n\t\t\t\tif (newSegment.parent) {\n\t\t\t\t\t// The incremental update codepath in theory can handle most cases where segments are obliterated upon insertion,\n\t\t\t\t\t// but it's not idempotent with respect to segment insertion in the first place. Since we already update partial\n\t\t\t\t\t// lengths inside the inserting walk, we'd be at risk of double-counting the insertion in any case if we allow\n\t\t\t\t\t// incremental updates here.\n\t\t\t\t\tconst newStructure = true;\n\t\t\t\t\tthis.blockUpdatePathLengths(newSegment.parent, removeInfo.removes[0], newStructure);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsaveIfLocal(newSegment);\n\t\t}\n\t}\n\n\tprivate computeObliteratePrecedingInsertion(\n\t\tsegment: ISegmentLeaf,\n\t\trefSeqStamp: OperationStamp,\n\t): ObliterateInfo | undefined {\n\t\tlet newest: ObliterateInfo | undefined;\n\t\tfor (const ob of this.obliterates.findOverlapping(segment)) {\n\t\t\tif (\n\t\t\t\topstampUtils.greaterThan(ob.stamp, refSeqStamp) &&\n\t\t\t\t(newest === undefined || opstampUtils.greaterThan(ob.stamp, newest.stamp))\n\t\t\t) {\n\t\t\t\tnewest = ob;\n\t\t\t}\n\t\t}\n\t\treturn newest;\n\t}\n\n\tprivate readonly splitLeafSegment = (\n\t\tsegment: ISegmentLeaf | undefined,\n\t\tpos: number,\n\t): ISegmentChanges => {\n\t\tif (!(pos > 0 && segment)) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst next = segment.splitAt(pos)!;\n\t\tassertSegmentLeaf(next);\n\n\t\tif (segment?.segmentGroups) {\n\t\t\tnext.segmentGroups ??= new SegmentGroupCollection(next);\n\t\t\tsegment.segmentGroups.copyTo(next.segmentGroups);\n\t\t}\n\n\t\tcopyPropertiesAndManager(segment, next);\n\t\tsegment.localRefs?.split(pos, next);\n\n\t\tthis.mergeTreeMaintenanceCallback?.(\n\t\t\t{\n\t\t\t\toperation: MergeTreeMaintenanceType.SPLIT,\n\t\t\t\tdeltaSegments: [{ segment }, { segment: next }],\n\t\t\t},\n\t\t\tundefined,\n\t\t);\n\n\t\treturn { next };\n\t};\n\n\tprivate ensureIntervalBoundary(pos: number, perspective: Perspective): void {\n\t\tthis.insertingWalk(\n\t\t\tpos,\n\t\t\tperspective,\n\t\t\t{\n\t\t\t\tseq: TreeMaintenanceSequenceNumber,\n\t\t\t\tclientId: perspective.clientId,\n\t\t\t},\n\t\t\t{ leaf: this.splitLeafSegment },\n\t\t);\n\t}\n\n\t// Assume called only when pos == len\n\tprivate breakTie(pos: number, node: IMergeNode, insertStamp: OperationStamp): boolean {\n\t\tif (node.isLeaf()) {\n\t\t\tif (pos !== 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\topstampUtils.greaterThan(insertStamp, node.insert) ||\n\t\t\t\t(isRemoved(node) &&\n\t\t\t\t\topstampUtils.isAcked(node.removes[0]) &&\n\t\t\t\t\topstampUtils.greaterThan(node.removes[0], insertStamp))\n\t\t\t);\n\t\t} else {\n\t\t\treturn true;\n\t\t}\n\t}\n\tprivate insertingWalk(\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\tcontext: InsertContext,\n\t): void {\n\t\tconst { remainder } = this.insertRecursive(\n\t\t\tthis.root,\n\t\t\tpos,\n\t\t\tperspective,\n\t\t\tstamp,\n\t\t\tcontext,\n\t\t\ttrue,\n\t\t);\n\t\tif (remainder !== undefined) {\n\t\t\tthis.updateRoot(remainder);\n\t\t}\n\t}\n\n\tprivate insertRecursive(\n\t\tblock: MergeBlock,\n\t\tpos: number,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\tcontext: InsertContext,\n\t\tisLastBlock: boolean,\n\t): InsertResult {\n\t\tlet _pos: number = pos;\n\n\t\tconst children = block.children;\n\t\tlet childIndex: number;\n\t\tlet child: IMergeNode;\n\t\tlet newNode: IMergeNodeBuilder | undefined;\n\t\tlet fromSplit: MergeBlock | undefined;\n\t\tlet hadChanges = false;\n\t\tfor (childIndex = 0; childIndex < block.childCount; childIndex++) {\n\t\t\tchild = children[childIndex];\n\t\t\t// removed blocks below the min seq will have an undefined length, and be skipped\n\t\t\t// however if it is the last block in the layer of the tree we don't want to skip it, so we correctly\n\t\t\t// walk down the far edge of the tree.\n\t\t\tconst isLastChildOfLastBlock = isLastBlock && childIndex === block.childCount - 1;\n\t\t\tconst len =\n\t\t\t\tthis.nodeLength(child, perspective) ?? (isLastChildOfLastBlock ? 0 : undefined);\n\n\t\t\tif (len === undefined) {\n\t\t\t\t// if the seg len is undefined, the segment\n\t\t\t\t// will be removed, so should just be skipped for now\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tassert(len >= 0, 0x4bc /* Length should not be negative */);\n\n\t\t\tif (_pos < len || (_pos === len && this.breakTie(_pos, child, stamp))) {\n\t\t\t\t// Found entry containing pos\n\t\t\t\tif (child.isLeaf()) {\n\t\t\t\t\tconst segment = child;\n\t\t\t\t\tconst segmentChanges = context.leaf(segment, _pos, context);\n\t\t\t\t\tif (segmentChanges.replaceCurrent) {\n\t\t\t\t\t\thadChanges = true;\n\t\t\t\t\t\tassignChild(block, segmentChanges.replaceCurrent, childIndex, false);\n\t\t\t\t\t\tsegmentChanges.replaceCurrent.ordinal = child.ordinal;\n\t\t\t\t\t}\n\t\t\t\t\tif (segmentChanges.next) {\n\t\t\t\t\t\thadChanges = true;\n\t\t\t\t\t\tnewNode = segmentChanges.next;\n\t\t\t\t\t\tchildIndex++; // Insert after\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { remainder: undefined, hadChanges };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Internal node\n\t\t\t\t\tconst insertResult = this.insertRecursive(\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\t_pos,\n\t\t\t\t\t\tperspective,\n\t\t\t\t\t\tstamp,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tisLastChildOfLastBlock,\n\t\t\t\t\t);\n\t\t\t\t\thadChanges ||= insertResult.hadChanges;\n\t\t\t\t\tif (insertResult.remainder === undefined) {\n\t\t\t\t\t\tif (insertResult.hadChanges) {\n\t\t\t\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn insertResult;\n\t\t\t\t\t} else if (insertResult.remainder === MergeTree.theUnfinishedNode) {\n\t\t\t\t\t\t_pos -= len; // Act as if shifted segment\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewNode = insertResult.remainder;\n\t\t\t\t\t\tfromSplit = insertResult.remainder;\n\t\t\t\t\t\tchildIndex++; // Insert after\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t_pos -= len;\n\t\t\t}\n\t\t}\n\t\tif (!newNode && _pos === 0) {\n\t\t\tif (context.continuePredicate?.(block)) {\n\t\t\t\treturn { remainder: MergeTree.theUnfinishedNode, hadChanges };\n\t\t\t} else {\n\t\t\t\tconst segmentChanges = context.leaf(undefined, _pos, context);\n\t\t\t\tnewNode = segmentChanges.next;\n\t\t\t\t// Assert segmentChanges.replaceCurrent === undefined\n\t\t\t}\n\t\t}\n\t\tif (newNode) {\n\t\t\thadChanges = true;\n\t\t\tfor (let i = block.childCount; i > childIndex; i--) {\n\t\t\t\tblock.children[i] = block.children[i - 1];\n\t\t\t\tblock.children[i].index = i;\n\t\t\t}\n\t\t\tassignChild(block, newNode, childIndex, false);\n\t\t\tblock.childCount++;\n\t\t\tblock.setOrdinal(newNode, childIndex);\n\t\t\tif (block.childCount < MaxNodesInBlock) {\n\t\t\t\tif (fromSplit) {\n\t\t\t\t\tthis.nodeUpdateOrdinals(fromSplit);\n\t\t\t\t}\n\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t\treturn { remainder: undefined, hadChanges };\n\t\t\t} else {\n\t\t\t\t// Don't update ordinals because higher block will do it\n\t\t\t\tconst newNodeFromSplit = this.split(block);\n\n\t\t\t\tPartialSequenceLengths.options.verifyExpected?.(\n\t\t\t\t\tthis,\n\t\t\t\t\tblock,\n\t\t\t\t\tperspective.refSeq,\n\t\t\t\t\tstamp.clientId,\n\t\t\t\t);\n\t\t\t\tPartialSequenceLengths.options.verifyExpected?.(\n\t\t\t\t\tthis,\n\t\t\t\t\tnewNodeFromSplit,\n\t\t\t\t\tperspective.refSeq,\n\t\t\t\t\tstamp.clientId,\n\t\t\t\t);\n\n\t\t\t\treturn { remainder: newNodeFromSplit, hadChanges };\n\t\t\t}\n\t\t} else {\n\t\t\treturn { remainder: undefined, hadChanges };\n\t\t}\n\t}\n\n\tprivate split(node: MergeBlock): MergeBlock {\n\t\tconst halfCount = MaxNodesInBlock / 2;\n\t\tconst newNode = this.makeBlock(halfCount);\n\t\tnode.childCount = halfCount;\n\t\t// Update ordinals to reflect lowered child count\n\t\tthis.nodeUpdateOrdinals(node);\n\t\tfor (let i = 0; i < halfCount; i++) {\n\t\t\tassignChild(newNode, node.children[halfCount + i], i, false);\n\t\t\tnode.children[halfCount + i] = undefined!;\n\t\t}\n\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\tthis.nodeUpdateLengthNewStructure(newNode);\n\t\treturn newNode;\n\t}\n\n\tpublic nodeUpdateOrdinals(block: MergeBlock): void {\n\t\tfor (let i = 0; i < block.childCount; i++) {\n\t\t\tconst child = block.children[i];\n\t\t\tblock.setOrdinal(child, i);\n\t\t\tif (!child.isLeaf()) {\n\t\t\t\tthis.nodeUpdateOrdinals(child);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Annotate a range with properties\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param propsOrAdjust - The properties or adjustments to annotate the range with\n\t * @param refSeq - The reference sequence number to use to apply the annotate\n\t * @param clientId - The id of the client making the annotate\n\t * @param seq - The sequence number of the annotate operation\n\t * @param opArgs - The op args for the annotate op. this is passed to the merge tree callback if there is one\n\t */\n\tpublic annotateRange(\n\t\tstart: number,\n\t\tend: number,\n\t\tpropsOrAdjust: PropsOrAdjust,\n\t\tperspective: Perspective,\n\t\tstamp: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tif (propsOrAdjust.adjust !== undefined) {\n\t\t\terrorIfOptionNotTrue(this.options, \"mergeTreeEnableAnnotateAdjust\");\n\t\t}\n\n\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\tthis.ensureIntervalBoundary(end, perspective);\n\t\tconst deltaSegments: IMergeTreeSegmentDelta[] = [];\n\n\t\tlet segmentGroup: SegmentGroup | undefined;\n\t\tconst opObj = propsOrAdjust.props ?? propsOrAdjust.adjust;\n\t\tconst annotateSegment = (segment: ISegmentLeaf): boolean => {\n\t\t\tassert(\n\t\t\t\t!Marker.is(segment) ||\n\t\t\t\t\t!(reservedMarkerIdKey in opObj) ||\n\t\t\t\t\topObj.markerId === segment.properties?.markerId,\n\t\t\t\t0x5ad /* Cannot change the markerId of an existing marker */,\n\t\t\t);\n\n\t\t\tconst propertyManager = (segment.propertyManager ??= new PropertiesManager());\n\t\t\tconst propertyDeltas = propertyManager.handleProperties(\n\t\t\t\tpropsOrAdjust,\n\t\t\t\tsegment,\n\t\t\t\tstamp.seq,\n\t\t\t\tthis.collabWindow.minSeq,\n\t\t\t\tthis.collabWindow.collaborating,\n\t\t\t\topArgs?.rollback === true,\n\t\t\t);\n\n\t\t\tif (!isRemoved(segment)) {\n\t\t\t\tdeltaSegments.push({ segment, propertyDeltas });\n\t\t\t}\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (opstampUtils.isLocal(stamp)) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tsegmentGroup,\n\t\t\t\t\t\tstamp.localSeq,\n\t\t\t\t\t\tpropertyDeltas,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.nodeMap(perspective, annotateSegment, undefined, start, end);\n\n\t\t// OpArgs == undefined => test code\n\t\tif (deltaSegments.length > 0) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\tdeltaSegments,\n\t\t\t});\n\t\t}\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tprivate obliterateRangeSided(\n\t\tstart: InteriorSequencePlace,\n\t\tend: InteriorSequencePlace,\n\t\tperspective: Perspective,\n\t\tstamp: SliceRemoveOperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tconst startPos = start.side === Side.Before ? start.pos : start.pos + 1;\n\t\tconst endPos = end.side === Side.Before ? end.pos : end.pos + 1;\n\n\t\tthis.ensureIntervalBoundary(startPos, perspective);\n\t\tthis.ensureIntervalBoundary(endPos, perspective);\n\n\t\tlet _overwrite = false;\n\t\tconst localOverlapWithRefs: ISegmentLeaf[] = [];\n\t\tconst removedSegments: SegmentWithInfo<IHasRemovalInfo, ISegmentLeaf>[] = [];\n\n\t\tconst createRefFromSequencePlace = (\n\t\t\tplace: InteriorSequencePlace,\n\t\t): LocalReferencePosition => {\n\t\t\tconst segOff = this.getContainingSegment(place.pos, perspective);\n\t\t\tassert(isSegmentLeaf(segOff?.segment), 0xa3f /* segments cannot be undefined */);\n\t\t\tconst { segment: placeSeg, offset: placeOffset } = segOff;\n\t\t\treturn this.createLocalReferencePosition(\n\t\t\t\tplaceSeg,\n\t\t\t\tplaceOffset,\n\t\t\t\tReferenceType.StayOnRemove,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\tconst obliterate: ObliterateInfo = {\n\t\t\tstart: createRefFromSequencePlace(start),\n\t\t\tstartSide: start.side,\n\t\t\tend: createRefFromSequencePlace(end),\n\t\t\tendSide: end.side,\n\t\t\trefSeq: perspective.refSeq,\n\t\t\tstamp,\n\t\t\tsegmentGroup: undefined,\n\t\t\ttiebreakTrackingGroup: undefined,\n\t\t};\n\t\t// Link references back to this obliterate info\n\t\tobliterate.start.addProperties({ obliterate });\n\t\tobliterate.end.addProperties({ obliterate });\n\n\t\tif (this.collabWindow.collaborating && stamp.clientId === this.collabWindow.clientId) {\n\t\t\t// Always create a segment group for local obliterates,\n\t\t\t// even if there are no segments currently in the obliteration range.\n\t\t\t// Segments may be concurrently inserted into the obliteration range,\n\t\t\t// at which point they are added to the segment group.\n\t\t\tobliterate.segmentGroup = {\n\t\t\t\tsegments: [],\n\t\t\t\tlocalSeq: stamp.localSeq,\n\t\t\t\trefSeq: this.collabWindow.currentSeq,\n\t\t\t\tobliterateInfo: obliterate,\n\t\t\t};\n\t\t\tobliterate.tiebreakTrackingGroup = new UnorderedTrackingGroup();\n\t\t\tthis.pendingSegments.push(obliterate.segmentGroup);\n\t\t}\n\t\tthis.obliterates.addOrUpdate(obliterate);\n\n\t\tconst markRemoved = (segment: ISegmentLeaf, pos: number): boolean => {\n\t\t\tif (\n\t\t\t\t(start.side === Side.After && startPos === pos + segment.cachedLength) || // exclusive start segment\n\t\t\t\t(end.side === Side.Before && endPos === pos && perspective.isSegmentPresent(segment)) // exclusive end segment\n\t\t\t) {\n\t\t\t\t// We walk these segments because we want to also walk any concurrently inserted segments between here and the obliterated segments.\n\t\t\t\t// These segments are outside of the obliteration range though, so return true to keep walking.\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst existingRemoveInfo = toRemovalInfo(segment);\n\n\t\t\t// The \"last-to-obliterate-gets-to-insert\" policy described by the doc comment on `obliteratePrecedingInsertion`\n\t\t\t// is mostly handled by logic at insertion time, but we need a small bit of handling here.\n\t\t\t// Specifically, we want to avoid marking a local-only segment as obliterated when we know one of our own local obliterates\n\t\t\t// will win against the obliterate we're processing, hence the early exit.\n\t\t\tif (\n\t\t\t\topstampUtils.isLocal(segment.insert) &&\n\t\t\t\tisInsideObliterate(segment) &&\n\t\t\t\tsegment.obliteratePrecedingInsertion?.stamp.seq === UnassignedSequenceNumber &&\n\t\t\t\topstampUtils.isAcked(stamp)\n\t\t\t) {\n\t\t\t\t// We chose to not obliterate this segment because we are aware of an unacked local obliteration.\n\t\t\t\t// The local obliterate has not been sequenced yet, so it is still the newest obliterate we are aware of.\n\t\t\t\t// Other clients will also choose not to obliterate this segment because the most recent obliteration has the same clientId\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Partial lengths incrementality is not supported for overlapping obliterate/removes.\n\t\t\t_overwrite ||= existingRemoveInfo !== undefined;\n\n\t\t\t// - Record the segment as removed\n\t\t\t// - If this was the first thing to remove the segment from the local view, add it to removedSegments\n\t\t\t// - Otherwise, if it was the first thing to remove the segment from the acked view, add it to localOverlapWithRefs (so we can slide them)\n\t\t\tif (existingRemoveInfo === undefined) {\n\t\t\t\tconst removed = overwriteInfo<IHasRemovalInfo, ISegmentLeaf>(segment, {\n\t\t\t\t\tremoves: [stamp],\n\t\t\t\t});\n\n\t\t\t\tremovedSegments.push(removed);\n\t\t\t} else {\n\t\t\t\t// The segment has already been removed, so we don't need to add it to removedSegments. However,\n\t\t\t\t// if it's only been removed locally, we still need to slide any references that may exist on it.\n\t\t\t\tif (\n\t\t\t\t\t!opstampUtils.hasAnyAckedOperation(existingRemoveInfo.removes) &&\n\t\t\t\t\tsegment.localRefs?.empty === false\n\t\t\t\t) {\n\t\t\t\t\tlocalOverlapWithRefs.push(segment);\n\t\t\t\t}\n\t\t\t\topstampUtils.spliceIntoList(existingRemoveInfo.removes, stamp);\n\t\t\t}\n\t\t\tassertRemoved(segment);\n\t\t\t// Save segment so can assign sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(segment.removes[0]) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tobliterate.segmentGroup = this.addToPendingList(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tobliterate.segmentGroup,\n\t\t\t\t\t\tstamp.localSeq,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tconst afterMarkRemoved = (node: MergeBlock): boolean => {\n\t\t\tif (_overwrite) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(node, stamp);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.nodeMap(\n\t\t\tperspective,\n\t\t\tmarkRemoved,\n\t\t\tafterMarkRemoved,\n\t\t\tstart.pos,\n\t\t\tend.pos + 1, // include the segment containing the end reference\n\t\t\t// Use a visibilityPerspective which includes all segments (including local ones) which are in the obliteration range.\n\t\t\t// This ensures that concurrently inserted segments will also be marked obliterated.\n\t\t\topstampUtils.isLocal(stamp)\n\t\t\t\t? perspective\n\t\t\t\t: new RemoteObliteratePerspective(stamp.clientId),\n\t\t);\n\n\t\tthis.slideAckedRemovedSegmentReferences(localOverlapWithRefs);\n\t\t// opArgs == undefined => test code\n\t\tif (start.pos !== end.pos || start.side !== end.side) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.OBLITERATE,\n\t\t\t\tdeltaSegments: removedSegments.map((segment) => ({ segment })),\n\t\t\t});\n\t\t}\n\n\t\t// these events are newly removed\n\t\t// so we slide after eventing in case the consumer wants to make reference\n\t\t// changes at remove time, like add a ref to track undo redo.\n\t\tif (!this.collabWindow.collaborating || stamp.clientId !== this.collabWindow.clientId) {\n\t\t\tthis.slideAckedRemovedSegmentReferences(removedSegments);\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\tpublic obliterateRange(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\terrorIfOptionNotTrue(this.options, \"mergeTreeEnableObliterate\");\n\t\tconst stamp: SliceRemoveOperationStamp = { ...stampArg, type: \"sliceRemove\" };\n\t\tif (this.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"object\" && typeof end === \"object\",\n\t\t\t\t0xa45 /* Start and end must be of type InteriorSequencePlace if mergeTreeEnableSidedObliterate is enabled. */,\n\t\t\t);\n\t\t\tthis.obliterateRangeSided(start, end, perspective, stamp, opArgs);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"number\" && typeof end === \"number\",\n\t\t\t\t0xa46 /* Start and end must be numbers if mergeTreeEnableSidedObliterate is not enabled. */,\n\t\t\t);\n\t\t\tthis.obliterateRangeSided(\n\t\t\t\t{ pos: start, side: Side.Before },\n\t\t\t\t{ pos: end - 1, side: Side.After },\n\t\t\t\tperspective,\n\t\t\t\tstamp,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic markRangeRemoved(\n\t\tstart: number,\n\t\tend: number,\n\t\tperspective: Perspective,\n\t\tstampArg: OperationStamp,\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t): void {\n\t\tlet _overwrite = false;\n\t\tconst stamp: SetRemoveOperationStamp = { ...stampArg, type: \"setRemove\" };\n\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\tthis.ensureIntervalBoundary(end, perspective);\n\n\t\tlet segmentGroup: SegmentGroup;\n\t\tconst removedSegments: SegmentWithInfo<IHasRemovalInfo, ISegmentLeaf>[] = [];\n\t\tconst localOverlapWithRefs: ISegmentLeaf[] = [];\n\n\t\tconst markRemoved = (\n\t\t\tsegment: ISegmentLeaf,\n\t\t\tpos: number,\n\t\t\t_start: number,\n\t\t\t_end: number,\n\t\t): boolean => {\n\t\t\tconst existingRemovalInfo = toRemovalInfo(segment);\n\n\t\t\t// Partial lengths incrementality is not supported for overlapping obliterate/removes.\n\t\t\t_overwrite ||= existingRemovalInfo !== undefined;\n\t\t\tif (existingRemovalInfo === undefined) {\n\t\t\t\tconst removed = overwriteInfo<IHasRemovalInfo, ISegmentLeaf>(segment, {\n\t\t\t\t\tremoves: [stamp],\n\t\t\t\t});\n\n\t\t\t\tremovedSegments.push(removed);\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\t!opstampUtils.hasAnyAckedOperation(existingRemovalInfo.removes) &&\n\t\t\t\t\tsegment.localRefs?.empty === false\n\t\t\t\t) {\n\t\t\t\t\tlocalOverlapWithRefs.push(segment);\n\t\t\t\t}\n\t\t\t\topstampUtils.spliceIntoList(existingRemovalInfo.removes, stamp);\n\t\t\t}\n\t\t\tassertRemoved(segment);\n\n\t\t\t// Save segment so we can assign removed sequence number when acked by server\n\t\t\tif (this.collabWindow.collaborating) {\n\t\t\t\tif (\n\t\t\t\t\topstampUtils.isLocal(segment.removes[0]) &&\n\t\t\t\t\tstamp.clientId === this.collabWindow.clientId\n\t\t\t\t) {\n\t\t\t\t\tsegmentGroup = this.addToPendingList(segment, segmentGroup, stamp.localSeq);\n\t\t\t\t} else {\n\t\t\t\t\tif (MergeTree.options.zamboniSegments) {\n\t\t\t\t\t\tthis.addToLRUSet(segment, stamp.seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tconst afterMarkRemoved = (node: MergeBlock): boolean => {\n\t\t\tif (_overwrite) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(node, stamp);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tthis.nodeMap(perspective, markRemoved, afterMarkRemoved, start, end);\n\t\t// these segments are already viewed as being removed locally and are not event-ed\n\t\t// so can slide non-StayOnRemove refs immediately\n\t\tthis.slideAckedRemovedSegmentReferences(localOverlapWithRefs);\n\t\t// opArgs == undefined => test code\n\t\tif (removedSegments.length > 0) {\n\t\t\tthis.mergeTreeDeltaCallback?.(opArgs, {\n\t\t\t\toperation: MergeTreeDeltaType.REMOVE,\n\t\t\t\tdeltaSegments: removedSegments.map((segment) => ({ segment })),\n\t\t\t});\n\t\t}\n\t\t// these events are newly removed\n\t\t// so we slide after eventing in case the consumer wants to make reference\n\t\t// changes at remove time, like add a ref to track undo redo.\n\t\tif (!this.collabWindow.collaborating || stamp.clientId !== this.collabWindow.clientId) {\n\t\t\tthis.slideAckedRemovedSegmentReferences(removedSegments);\n\t\t}\n\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tMergeTree.options.zamboniSegments\n\t\t) {\n\t\t\tzamboniSegments(this);\n\t\t}\n\t}\n\n\t/**\n\t * Revert an unacked local op\n\t */\n\tpublic rollback(op: IMergeTreeOp, localOpMetadata: SegmentGroup | SegmentGroup[]): void {\n\t\tif (op.type === MergeTreeDeltaType.GROUP) {\n\t\t\tassert(Array.isArray(localOpMetadata), 0xbe2 /* metadata must be array for group ops */);\n\t\t\tfor (let i = op.ops.length - 1; i >= 0; i--) {\n\t\t\t\tthis.rollback(op.ops[i], localOpMetadata[i]);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst rollbackStamp: OperationStamp = {\n\t\t\tseq: TreeMaintenanceSequenceNumber,\n\t\t\tclientId: NonCollabClient,\n\t\t};\n\t\tif (op.type === MergeTreeDeltaType.REMOVE) {\n\t\t\tconst pendingSegmentGroup = this.pendingSegments.pop()?.data;\n\t\t\tif (pendingSegmentGroup === undefined || pendingSegmentGroup !== localOpMetadata) {\n\t\t\t\tthrow new Error(\"Rollback op doesn't match last edit\");\n\t\t\t}\n\t\t\t// Disabling because a for of loop causes the type of segment to be ISegmentLeaf, which does not have parent information stored\n\t\t\t// eslint-disable-next-line unicorn/no-array-for-each\n\t\t\tpendingSegmentGroup.segments.forEach((segment: ISegmentLeaf) => {\n\t\t\t\tconst segmentSegmentGroup = segment?.segmentGroups?.pop();\n\t\t\t\tassert(\n\t\t\t\t\tsegmentSegmentGroup === pendingSegmentGroup,\n\t\t\t\t\t0x3ee /* Unexpected segmentGroup in segment */,\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tisRemoved(segment) && segment.removes[0].type === \"setRemove\",\n\t\t\t\t\t0x39d /* Rollback segment removedClientId does not match local client */,\n\t\t\t\t);\n\t\t\t\t// if a peer client concurrently deleted the segment, don't revive it on rollback\n\t\t\t\tif (segment.removes[0].clientId === this.collabWindow.clientId) {\n\t\t\t\t\t// This also removes obliterates, but that should be ok as we can only remove a segment once.\n\t\t\t\t\t// If we were able to remove it locally, that also means there are no remote removals (since rollback is synchronous).\n\t\t\t\t\tremoveRemovalInfo(segment);\n\n\t\t\t\t\tthis.blockUpdatePathLengths(segment.parent, rollbackStamp);\n\n\t\t\t\t\t// Note: optional chaining short-circuits:\n\t\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#short-circuiting\n\t\t\t\t\tthis.mergeTreeDeltaCallback?.(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\top: createInsertSegmentOp(this.findRollbackPosition(segment), segment),\n\t\t\t\t\t\t\trollback: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\t\t\t\t\tdeltaSegments: [{ segment }],\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (\n\t\t\top.type === MergeTreeDeltaType.INSERT ||\n\t\t\top.type === MergeTreeDeltaType.ANNOTATE\n\t\t) {\n\t\t\tconst pendingSegmentGroup = this.pendingSegments.pop()?.data;\n\t\t\tif (\n\t\t\t\tpendingSegmentGroup === undefined ||\n\t\t\t\tpendingSegmentGroup !== localOpMetadata ||\n\t\t\t\t(op.type === MergeTreeDeltaType.ANNOTATE && !pendingSegmentGroup.previousProps)\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Rollback op doesn't match last edit\");\n\t\t\t}\n\t\t\tlet i = 0;\n\t\t\tfor (const segment of pendingSegmentGroup.segments) {\n\t\t\t\tconst segmentSegmentGroup = segment?.segmentGroups?.pop();\n\t\t\t\tassert(\n\t\t\t\t\tsegmentSegmentGroup === pendingSegmentGroup,\n\t\t\t\t\t0x3ef /* Unexpected segmentGroup in segment */,\n\t\t\t\t);\n\n\t\t\t\tconst start = this.findRollbackPosition(segment);\n\t\t\t\tif (op.type === MergeTreeDeltaType.INSERT) {\n\t\t\t\t\tsegment.insert = {\n\t\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\t\t...rollbackStamp,\n\t\t\t\t\t};\n\t\t\t\t\tconst removeOp = createRemoveRangeOp(start, start + segment.cachedLength);\n\t\t\t\t\tconst removeStamp: SetRemoveOperationStamp = {\n\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\t...rollbackStamp,\n\t\t\t\t\t};\n\t\t\t\t\tthis.markRangeRemoved(\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tstart + segment.cachedLength,\n\t\t\t\t\t\tthis.localPerspective,\n\t\t\t\t\t\tremoveStamp,\n\t\t\t\t\t\t{ op: removeOp, rollback: true },\n\t\t\t\t\t);\n\t\t\t\t} /* op.type === MergeTreeDeltaType.ANNOTATE */ else {\n\t\t\t\t\tconst props = pendingSegmentGroup.previousProps![i];\n\n\t\t\t\t\t// If the segment has been removed by a concurrent operation, we can't use\n\t\t\t\t\t// position-based annotateRange because findRollbackPosition returns a position\n\t\t\t\t\t// that doesn't account for the removed segment, causing the rollback to target\n\t\t\t\t\t// the wrong segment. Instead, directly roll back the properties on the segment.\n\t\t\t\t\tif (isRemoved(segment)) {\n\t\t\t\t\t\tconst propertyManager = (segment.propertyManager ??= new PropertiesManager());\n\t\t\t\t\t\tpropertyManager.rollbackProperties(\n\t\t\t\t\t\t\t{ props },\n\t\t\t\t\t\t\tsegment,\n\t\t\t\t\t\t\tthis.collabWindow.collaborating,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst annotateOp = createAnnotateRangeOp(\n\t\t\t\t\t\t\tstart,\n\t\t\t\t\t\t\tstart + segment.cachedLength,\n\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tthis.annotateRange(\n\t\t\t\t\t\t\tstart,\n\t\t\t\t\t\t\tstart + segment.cachedLength,\n\t\t\t\t\t\t\t{ props },\n\t\t\t\t\t\t\tthis.localPerspective,\n\t\t\t\t\t\t\trollbackStamp,\n\t\t\t\t\t\t\t{ op: annotateOp, rollback: true },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(\"Unsupported op type for rollback\");\n\t\t}\n\t}\n\n\t/**\n\t * Walk the segments up to the current segment and calculate its position\n\t */\n\tprivate findRollbackPosition(segment: ISegmentLeaf): number {\n\t\tlet segmentPosition = 0;\n\t\twalkAllChildSegments(this.root, (seg) => {\n\t\t\t// If we've found the desired segment, terminate the walk and return 'segmentPosition'.\n\t\t\tif (seg === segment) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// If not removed, increase position\n\t\t\tif (!isRemoved(seg)) {\n\t\t\t\tsegmentPosition += seg.cachedLength;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\treturn segmentPosition;\n\t}\n\n\tpublic nodeUpdateLengthNewStructure(node: MergeBlock, recur = false): void {\n\t\tthis.blockUpdate(node);\n\t\tif (this.collabWindow.collaborating) {\n\t\t\tthis.localPartialsComputed = false;\n\t\t\tnode.partialLengths = PartialSequenceLengths.combine(node, this.collabWindow, recur);\n\t\t}\n\t}\n\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\tconst segment: ISegmentPrivate | undefined = lref.getSegment();\n\t\treturn segment?.localRefs?.removeLocalRef(lref);\n\t}\n\n\tstartOfTree = new StartOfTreeSegment(this);\n\tendOfTree = new EndOfTreeSegment(this);\n\n\tpublic createLocalReferencePosition(\n\t\t_segment: ISegmentPrivate | \"start\" | \"end\",\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\tif (\n\t\t\t_segment !== \"start\" &&\n\t\t\t_segment !== \"end\" &&\n\t\t\tisRemovedAndAcked(_segment) &&\n\t\t\t!refTypeIncludesFlag(\n\t\t\t\trefType,\n\t\t\t\tReferenceType.SlideOnRemove | ReferenceType.Transient | ReferenceType.StayOnRemove,\n\t\t\t) &&\n\t\t\t_segment.endpointType === undefined\n\t\t) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Can only create SlideOnRemove or Transient local reference position on a removed or obliterated segment\",\n\t\t\t);\n\t\t}\n\t\tlet segment: ISegmentLeaf;\n\n\t\tif (_segment === \"start\") {\n\t\t\tsegment = this.startOfTree;\n\t\t} else if (_segment === \"end\") {\n\t\t\tsegment = this.endOfTree;\n\t\t} else {\n\t\t\tassertSegmentLeaf(_segment);\n\t\t\tsegment = _segment;\n\t\t}\n\n\t\tconst localRefs = LocalReferenceCollection.setOrGet(segment);\n\n\t\tconst segRef = localRefs.createLocalRef(\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\n\t\treturn segRef;\n\t}\n\n\t/**\n\t * Segments should either be removed remotely, removed locally, or inserted locally\n\t *\n\t * See description of {@link normalizeSegmentsOnRebase}.\n\t *\n\t * This normalizes a block of adjacent segments whose positions have collapsed between the time of the original submission and now\n\t * such that removed segments come after ones that still exist.\n\t *\n\t * TODO:AB#34898: It looks like this method has some bugs, search code for this tag for an example test that demonstrates\n\t * segment normalization yielding an order that remote clients wouldn't have seen.\n\t */\n\tprivate normalizeAdjacentSegments(affectedSegments: DoublyLinkedList<ISegmentLeaf>): void {\n\t\t// Eagerly demand this since we're about to shift elements in the list around\n\t\tconst currentOrder = Array.from(affectedSegments, ({ data: seg }) => ({\n\t\t\tparent: seg.parent,\n\t\t\tindex: seg.index,\n\t\t\tordinal: seg.ordinal,\n\t\t}));\n\n\t\t// Last segment which was not affected locally.\n\t\tlet lastLocalSegment = affectedSegments.last;\n\t\twhile (lastLocalSegment !== undefined && isRemovedAndAcked(lastLocalSegment.data)) {\n\t\t\tlastLocalSegment = lastLocalSegment.prev;\n\t\t}\n\n\t\tif (!lastLocalSegment) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (\n\t\t\tlet segmentToSlide: ListNode<ISegmentLeaf> | undefined = lastLocalSegment,\n\t\t\t\tnearerSegment = lastLocalSegment?.prev;\n\t\t\tsegmentToSlide !== undefined;\n\t\t\tsegmentToSlide = nearerSegment, nearerSegment = nearerSegment?.prev\n\t\t) {\n\t\t\t// Slide iterCur forward as far as possible\n\t\t\tif (isRemovedAndAcked(segmentToSlide.data)) {\n\t\t\t\t// Slide past all segments that are not also remotely removed\n\t\t\t\taffectedSegments.remove(segmentToSlide);\n\t\t\t\taffectedSegments.insertAfter(lastLocalSegment, segmentToSlide.data);\n\t\t\t} else if (isRemoved(segmentToSlide.data)) {\n\t\t\t\tassert(\n\t\t\t\t\tsegmentToSlide.data.removes[0].seq !== undefined,\n\t\t\t\t\t0x54d /* Removed segment that hasnt had its removal acked should be locally removed */,\n\t\t\t\t);\n\t\t\t\t// Slide each locally removed item past all segments that have localSeq > lremoveItem.localSeq\n\t\t\t\t// but not past remotely removed segments;\n\t\t\t\tlet cur = segmentToSlide;\n\t\t\t\tlet scan = cur.next;\n\t\t\t\twhile (\n\t\t\t\t\tscan !== undefined &&\n\t\t\t\t\t!isRemovedAndAcked(scan.data) &&\n\t\t\t\t\tscan.data.insert.localSeq !== undefined &&\n\t\t\t\t\topstampUtils.greaterThan(scan.data.insert, segmentToSlide.data.removes[0])\n\t\t\t\t) {\n\t\t\t\t\tcur = scan;\n\t\t\t\t\tscan = scan.next;\n\t\t\t\t}\n\t\t\t\tif (cur !== segmentToSlide) {\n\t\t\t\t\taffectedSegments.remove(segmentToSlide);\n\t\t\t\t\taffectedSegments.insertAfter(cur, segmentToSlide.data);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst newOrder = Array.from(affectedSegments, ({ data }) => data);\n\t\tfor (const seg of newOrder)\n\t\t\tseg.localRefs?.walkReferences((lref) => lref.callbacks?.beforeSlide?.(lref));\n\t\tconst perSegmentTrackingGroups = new Map<ISegmentLeaf, TrackingGroup[]>();\n\t\tfor (const segment of newOrder) {\n\t\t\tconst { trackingCollection } = segment;\n\t\t\tconst trackingGroups = [...trackingCollection.trackingGroups];\n\t\t\tperSegmentTrackingGroups.set(segment, trackingGroups);\n\t\t\tfor (const group of trackingCollection.trackingGroups) {\n\t\t\t\ttrackingCollection.unlink(group);\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = 0; i < newOrder.length; i++) {\n\t\t\tconst seg = newOrder[i];\n\t\t\tconst { parent, index, ordinal } = currentOrder[i];\n\t\t\tassignChild(parent, seg, index, false);\n\t\t\tseg.ordinal = ordinal;\n\t\t}\n\n\t\tfor (const [segment, groups] of perSegmentTrackingGroups.entries()) {\n\t\t\tfor (const group of groups) {\n\t\t\t\tsegment.trackingCollection.link(group);\n\t\t\t}\n\t\t}\n\n\t\t// Finally, update internal node bookkeeping on ancestors of the swapped nodes.\n\t\t// Toposort would improve this by a log factor, but probably not worth the added code size\n\t\tconst depths = new Map<IMergeNode, number>();\n\t\tconst computeDepth = (block: IMergeNode): number => {\n\t\t\tif (!depths.has(block)) {\n\t\t\t\tdepths.set(block, block.parent === undefined ? 0 : 1 + computeDepth(block.parent));\n\t\t\t}\n\t\t\treturn depths.get(block)!;\n\t\t};\n\t\tfor (const element of newOrder) {\n\t\t\tcomputeDepth(element);\n\t\t}\n\t\tfor (const [node] of [...depths.entries()].sort((a, b) => b[1] - a[1])) {\n\t\t\tif (!node.isLeaf()) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(node);\n\t\t\t}\n\t\t}\n\t\tfor (const seg of newOrder)\n\t\t\tseg.localRefs?.walkReferences((lref) => lref.callbacks?.afterSlide?.(lref));\n\t}\n\n\t/**\n\t * Normalizes the segments nearby `segmentGroup` to be ordered as they would if the op submitting `segmentGroup`\n\t * is rebased to the current sequence number.\n\t * This primarily affects the ordering of adjacent segments that were removed between the original submission of\n\t * the local ops and now.\n\t * Consider the following sequence of events:\n\t * Initial state: \"hi my friend\" (seq: 0)\n\t * - Client 1 inserts \"good \" to make \"hi my good friend\" (op1, refSeq: 0)\n\t * - Client 2 deletes \"my \" to make \"hi friend\" (op2, refSeq: 0)\n\t * - op2 is sequenced giving seq 1\n\t * - Client 1 disconnects and reconnects at seq: 1.\n\t *\n\t * At this point in time, client 1 will have segments [\"hi \", Removed\"my \", Local\"good \", \"friend\"].\n\t * However, the rebased op that it submits will cause client 2 to have segments\n\t * [\"hi \", Local\"good \", Removed\"my \", \"friend\"].\n\t *\n\t * The difference in ordering can be problematic for tie-breaking concurrently inserted segments in some scenarios.\n\t * Rather than incur extra work tie-breaking these scenarios for all clients, when client 1 rebases its operation,\n\t * it can fix up its local state to align with what would be expected of the op it resubmits.\n\t */\n\tpublic normalizeSegmentsOnRebase(): void {\n\t\tlet currentRangeToNormalize = new DoublyLinkedList<ISegmentLeaf>();\n\t\tlet rangeContainsLocalSegs = false;\n\t\tlet rangeContainsRemoteRemovedSegs = false;\n\t\tconst normalize = (): void => {\n\t\t\tif (\n\t\t\t\trangeContainsLocalSegs &&\n\t\t\t\trangeContainsRemoteRemovedSegs &&\n\t\t\t\tcurrentRangeToNormalize.length > 1\n\t\t\t) {\n\t\t\t\tthis.normalizeAdjacentSegments(currentRangeToNormalize);\n\t\t\t}\n\t\t};\n\t\twalkAllChildSegments(this.root, (seg) => {\n\t\t\tif (isRemoved(seg) || opstampUtils.isLocal(seg.insert)) {\n\t\t\t\tif (isRemovedAndAcked(seg)) {\n\t\t\t\t\trangeContainsRemoteRemovedSegs = true;\n\t\t\t\t}\n\t\t\t\tif (opstampUtils.isLocal(seg.insert)) {\n\t\t\t\t\trangeContainsLocalSegs = true;\n\t\t\t\t}\n\t\t\t\tcurrentRangeToNormalize.push(seg);\n\t\t\t} else {\n\t\t\t\tnormalize();\n\t\t\t\tcurrentRangeToNormalize = new DoublyLinkedList<ISegmentLeaf>();\n\t\t\t\trangeContainsLocalSegs = false;\n\t\t\t\trangeContainsRemoteRemovedSegs = false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\tnormalize();\n\t\tthis.obliterates.onNormalize();\n\t\tconst segmentTiebreakChanges = new Set<{\n\t\t\tsegment: ISegmentLeaf;\n\t\t\told: ObliterateInfo;\n\t\t\tnew: ObliterateInfo | undefined;\n\t\t}>();\n\t\tfor (const info of this.obliterates) {\n\t\t\tif (info.tiebreakTrackingGroup !== undefined) {\n\t\t\t\tfor (const segment of info.tiebreakTrackingGroup.tracked) {\n\t\t\t\t\t// Recompute previous obliterate\n\t\t\t\t\tassert(\n\t\t\t\t\t\tisSegmentLeaf(segment) &&\n\t\t\t\t\t\t\tisInsideObliterate(segment) &&\n\t\t\t\t\t\t\tsegment.insertionRefSeqStamp !== undefined,\n\t\t\t\t\t\t0xb74 /* Expected segment leaf inside obliterate with insertionRefSeqStamp */,\n\t\t\t\t\t);\n\t\t\t\t\t// This may have changed as a result of segments shuffling: outstanding local obliterates that previously surrounded a segment may no longer surround it.\n\t\t\t\t\tconst newObliteratePrecedingInsertion = this.computeObliteratePrecedingInsertion(\n\t\t\t\t\t\tsegment,\n\t\t\t\t\t\tsegment.insertionRefSeqStamp,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (newObliteratePrecedingInsertion !== info) {\n\t\t\t\t\t\tsegmentTiebreakChanges.add({\n\t\t\t\t\t\t\tsegment,\n\t\t\t\t\t\t\told: info,\n\t\t\t\t\t\t\tnew: newObliteratePrecedingInsertion,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const { segment, old, new: newInfo } of segmentTiebreakChanges) {\n\t\t\t// Update tiebreak tracking groups on old/new segment as well as `ISegmentInsideObliterateInfo` state\n\t\t\t// which we only keep around as long as obliterates are in flight.\n\t\t\told.tiebreakTrackingGroup?.unlink(segment);\n\t\t\tif (newInfo?.tiebreakTrackingGroup === undefined) {\n\t\t\t\t// Segment is either no longer inside any obliterate or only inside acked obliterates.\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(segment, {\n\t\t\t\t\tobliteratePrecedingInsertion: newInfo,\n\t\t\t\t\tinsertionRefSeqStamp: undefined,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(segment, {\n\t\t\t\t\tobliteratePrecedingInsertion: newInfo,\n\t\t\t\t});\n\n\t\t\t\tnewInfo.tiebreakTrackingGroup.link(segment);\n\t\t\t}\n\t\t}\n\t}\n\tprivate blockUpdate(block: MergeBlock): void {\n\t\tlet len: number | undefined;\n\n\t\tconst rightmostTiles = createMap<Marker>();\n\t\tconst leftmostTiles = createMap<Marker>();\n\n\t\tfor (let i = 0; i < block.childCount; i++) {\n\t\t\tconst node = block.children[i];\n\t\t\tconst nodeLength = nodeTotalLength(this, node);\n\t\t\tif (nodeLength !== undefined) {\n\t\t\t\tlen ??= 0;\n\t\t\t\tlen += nodeLength;\n\t\t\t}\n\t\t\tif (node.isLeaf()) {\n\t\t\t\tconst segment = node;\n\t\t\t\tif ((this.leafLength(segment) ?? 0) > 0 && Marker.is(segment)) {\n\t\t\t\t\tconst markerId = segment.getId();\n\t\t\t\t\t// Also in insertMarker but need for reload segs case\n\t\t\t\t\t// can add option for this only from reload segs\n\t\t\t\t\tif (markerId) {\n\t\t\t\t\t\tthis.idToMarker.set(markerId, segment);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (refTypeIncludesFlag(segment, ReferenceType.Tile)) {\n\t\t\t\t\t\tconst tileLabels = refGetTileLabels(segment);\n\t\t\t\t\t\tif (tileLabels) {\n\t\t\t\t\t\t\tfor (const tileLabel of tileLabels) {\n\t\t\t\t\t\t\t\t// this depends on walking children in order\n\t\t\t\t\t\t\t\t// The later, and right most children overwrite\n\t\t\t\t\t\t\t\t// whereas early, and left most do not overwrite\n\t\t\t\t\t\t\t\trightmostTiles[tileLabel] = segment;\n\t\t\t\t\t\t\t\tleftmostTiles[tileLabel] ??= segment;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\textend(rightmostTiles, node.rightmostTiles);\n\t\t\t\textendIfUndefined(leftmostTiles, node.leftmostTiles);\n\t\t\t}\n\t\t}\n\t\tblock.leftmostTiles = leftmostTiles;\n\t\tblock.rightmostTiles = rightmostTiles;\n\t\tblock.cachedLength = len;\n\t}\n\n\tpublic blockUpdatePathLengths(\n\t\tstartBlock: MergeBlock | undefined,\n\t\tstamp: OperationStamp,\n\t\tnewStructure = false,\n\t): void {\n\t\tlet block: MergeBlock | undefined = startBlock;\n\t\twhile (block !== undefined) {\n\t\t\tif (newStructure) {\n\t\t\t\tthis.nodeUpdateLengthNewStructure(block);\n\t\t\t} else {\n\t\t\t\tthis.blockUpdateLength(block, stamp);\n\t\t\t}\n\t\t\tblock = block.parent;\n\t\t}\n\t}\n\n\tprivate blockUpdateLength(node: MergeBlock, stamp: OperationStamp): void {\n\t\tthis.blockUpdate(node);\n\t\tthis.localPartialsComputed = false;\n\t\tif (\n\t\t\tthis.collabWindow.collaborating &&\n\t\t\topstampUtils.isAcked(stamp) &&\n\t\t\tstamp.seq !== TreeMaintenanceSequenceNumber\n\t\t) {\n\t\t\tif (\n\t\t\t\tnode.partialLengths !== undefined &&\n\t\t\t\tMergeTree.options.incrementalUpdate &&\n\t\t\t\tstamp.clientId !== NonCollabClient\n\t\t\t) {\n\t\t\t\tnode.partialLengths.update(node, stamp.seq, stamp.clientId, this.collabWindow);\n\t\t\t} else {\n\t\t\t\tnode.partialLengths = PartialSequenceLengths.combine(node, this.collabWindow);\n\t\t\t}\n\n\t\t\tPartialSequenceLengths.options.verifyExpected?.(this, node, stamp.seq, stamp.clientId);\n\t\t}\n\t}\n\n\t/**\n\t * Map over all visible segments in a given range\n\t *\n\t * A segment is visible if its length is greater than 0\n\t *\n\t * See `this.nodeMap` for additional documentation\n\t */\n\tpublic mapRange<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tperspective: Perspective,\n\t\taccum: TClientData,\n\t\tstart?: number,\n\t\tend?: number,\n\t\tsplitRange: boolean = false,\n\t\tvisibilityPerspective: Perspective = perspective,\n\t): void {\n\t\tif (splitRange) {\n\t\t\tif (start) {\n\t\t\t\tthis.ensureIntervalBoundary(start, perspective);\n\t\t\t}\n\t\t\tif (end) {\n\t\t\t\tthis.ensureIntervalBoundary(end, perspective);\n\t\t\t}\n\t\t}\n\t\tthis.nodeMap(\n\t\t\tperspective,\n\t\t\t(seg, pos, _start, _end) =>\n\t\t\t\thandler(seg, pos, perspective.refSeq, perspective.clientId, _start, _end, accum),\n\t\t\tundefined,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tvisibilityPerspective,\n\t\t);\n\t}\n\n\t/**\n\t * Map over all visible segments in a given range\n\t *\n\t * A segment is visible if its length is greater than 0\n\t *\n\t * @param refSeq - The sequence number used to determine the range (start\n\t * and end positions) of segments to iterate over.\n\t *\n\t * @param visibilitySeq - An additional sequence number to further configure\n\t * segment visibility during traversal. This is the same as refSeq, except\n\t * in the case of obliterate.\n\t *\n\t * In the case where `refSeq == visibilitySeq`, mapping is done on all\n\t * visible segments from `start` to `end`.\n\t *\n\t * If a segment is invisible at both `visibilitySeq` and `refSeq`, then it\n\t * will not be traversed and mapped. Otherwise, if the segment is visible at\n\t * either seq, it will be mapped.\n\t *\n\t * If a segment is only visible at `visibilitySeq`, it will still be mapped,\n\t * but it will not count as a segment within the range. That is, it will be\n\t * ignored for the purposes of tracking when traversal should end.\n\t */\n\tprivate nodeMap(\n\t\tperspective: Perspective,\n\t\tleaf: (segment: ISegmentLeaf, pos: number, start: number, end: number) => boolean,\n\t\tpost?: (block: MergeBlock) => boolean,\n\t\tstart: number = 0,\n\t\tend?: number,\n\t\tvisibilityPerspective: Perspective = perspective,\n\t): void {\n\t\tconst endPos = end ?? this.nodeLength(this.root, perspective) ?? 0;\n\t\tif (endPos === start) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet pos = 0;\n\n\t\tdepthFirstNodeWalk(\n\t\t\tthis.root,\n\t\t\tthis.root.children[0],\n\t\t\t(node) => {\n\t\t\t\tif (endPos <= pos) {\n\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t}\n\n\t\t\t\tconst len = this.nodeLength(node, visibilityPerspective);\n\t\t\t\tconst lenAtRefSeq =\n\t\t\t\t\t(visibilityPerspective === perspective ? len : this.nodeLength(node, perspective)) ??\n\t\t\t\t\t0;\n\n\t\t\t\t// NOTE: This code ensures that obliterates have a chance to mark segments which have been inserted locally\n\t\t\t\t// as also having been obliterated on the local client. With the introduction of RemoteObliteratePerspective,\n\t\t\t\t// it's feasible we could remove it if the `nodeLength` calculation also respects that perspective for blocks\n\t\t\t\t// and not just leaves.\n\t\t\t\tconst isUnackedAndInObliterate =\n\t\t\t\t\tvisibilityPerspective !== perspective &&\n\t\t\t\t\t(!node.isLeaf() || opstampUtils.isLocal(node.insert));\n\t\t\t\tif (\n\t\t\t\t\t(len === undefined && lenAtRefSeq === 0) ||\n\t\t\t\t\t(len === 0 && !isUnackedAndInObliterate && lenAtRefSeq === 0)\n\t\t\t\t) {\n\t\t\t\t\treturn NodeAction.Skip;\n\t\t\t\t}\n\n\t\t\t\tconst nextPos = pos + lenAtRefSeq;\n\t\t\t\t// start is beyond the current node, so we can skip it\n\t\t\t\tif (start >= nextPos) {\n\t\t\t\t\tpos = nextPos;\n\t\t\t\t\treturn NodeAction.Skip;\n\t\t\t\t}\n\n\t\t\t\tif (node.isLeaf()) {\n\t\t\t\t\tif (leaf(node, pos, start - pos, endPos - pos) === false) {\n\t\t\t\t\t\treturn NodeAction.Exit;\n\t\t\t\t\t}\n\t\t\t\t\tpos = nextPos;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tpost,\n\t\t);\n\t}\n}\n"]}
|