@fluidframework/matrix 2.0.0-internal.5.4.2 → 2.0.0-internal.6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAKpE,OAAO,EACN,WAAW,EAEX,MAAM,EAGN,kBAAkB,EAElB,wBAAwB,GAExB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAWlD,YAAY,MAAc,EAAE,KAAK,gCAAqB;QACrD,KAAK,EAAE,CAAC;QAVD,WAAM,iCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC5B,CAAC;IAXM,MAAM,CAAC,cAAc,CAAC,IAAS;QACrC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAUD,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,IAAW,KAAK,CAAC,KAAa;QAC7B,MAAM,CACL,IAAI,CAAC,MAAM,kC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AI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;CACD;AAED,MAAM,UAAU,yBAAyB,CACxC,MAAyB,EACzB,GAAW,EACX,IAAkB;IAElB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,OAA6B,CAAC;IAEhF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAClC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;KAChC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tBaseSegment,\n\tISegment,\n\tClient,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tMergeTreeDeltaType,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tMergeTreeMaintenanceType,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { ITelemetryBaseLogger, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: any) {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start() {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset() {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject() {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength) {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment) {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString() {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n\t\t\t\tmergeTreeUseNewLengthCalculations: true,\n\t\t\t},\n\t\t); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number) {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number) {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(pos: number, op: ISequencedDocumentMessage) {\n\t\tconst { segment, offset } = this.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\t// Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n\t\t// a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n\t\t// by checking for the presence of 'removedSeq'.\n\t\tif (segment === undefined || segment.removedSeq !== undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.getPosition(segment) + offset!;\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq) {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t) {\n\t\tconst handleTableData = await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t);\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t) => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t// processing remote ops.\n\t\t\t\t\tsegment.reset();\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tnew Array(asPerm.cachedLength)\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString() {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n) {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos).segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\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AAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,OAA6B,CAAC;IAEhF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAClC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;KAChC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tBaseSegment,\n\tISegment,\n\tClient,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tMergeTreeDeltaType,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tMergeTreeMaintenanceType,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { ITelemetryBaseLogger, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: any) {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start() {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset() {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject() {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength) {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment) {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString() {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n\t\t\t},\n\t\t); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number) {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number) {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(pos: number, op: ISequencedDocumentMessage) {\n\t\tconst { segment, offset } = this.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\t// Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n\t\t// a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n\t\t// by checking for the presence of 'removedSeq'.\n\t\tif (segment === undefined || segment.removedSeq !== undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.getPosition(segment) + offset!;\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq) {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t) {\n\t\tconst handleTableData = await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t);\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t) => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t// processing remote ops.\n\t\t\t\t\tsegment.reset();\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tnew Array(asPerm.cachedLength)\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString() {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n) {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos).segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\n\t);\n\treturn { op, inserted };\n}\n"]}
package/lib/productSet.js CHANGED
@@ -2,17 +2,6 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- var __rest = (this && this.__rest) || function (s, e) {
6
- var t = {};
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
8
- t[p] = s[p];
9
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
10
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
12
- t[p[i]] = s[p[i]];
13
- }
14
- return t;
15
- };
16
5
  import { empty, dense, combineCmp, intersectUntyped, compareUntyped, unionUntyped, exceptUntyped, lazy, fromUntyped, meetsUntyped, } from "./bspSet";
17
6
  const tops = {};
18
7
  const top = (productOperations) => {
@@ -205,10 +194,13 @@ const tryUnionSubspaces = (() => {
205
194
  if (newDim === dense) {
206
195
  // we are actually deleting the `differentDimension`, so the variable
207
196
  // `deleted` must be there. Hence disabling the rule here.
208
- const _a = left.bounds, _b = differentDimension, deleted = _a[_b], leftBoundsWithoutDifferentDimension = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
197
+ const { [differentDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;
209
198
  return (cache.res = subspace(leftBoundsWithoutDifferentDimension));
210
199
  }
211
- const newBounds = Object.assign(Object.assign({}, left.bounds), { [differentDimension]: newDim });
200
+ const newBounds = {
201
+ ...left.bounds,
202
+ [differentDimension]: newDim,
203
+ };
212
204
  return (cache.res = subspace(newBounds));
213
205
  }
214
206
  return (cache.res = undefined);
@@ -306,13 +298,19 @@ function splitBox(productOperations, currentBox) {
306
298
  const [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);
307
299
  const res = [
308
300
  {
309
- box: Object.assign(Object.assign({}, box), { [biggestDim]: lazy(setOperations, setOperations.top, leftDim) }),
310
- probabilities: Object.assign(Object.assign({}, probabilities), { [biggestDim]: leftProb }),
301
+ box: {
302
+ ...box,
303
+ [biggestDim]: lazy(setOperations, setOperations.top, leftDim),
304
+ },
305
+ probabilities: { ...probabilities, [biggestDim]: leftProb },
311
306
  depth: currentBox.depth + 1,
312
307
  },
313
308
  {
314
- box: Object.assign(Object.assign({}, box), { [biggestDim]: lazy(setOperations, setOperations.top, rightDim) }),
315
- probabilities: Object.assign(Object.assign({}, probabilities), { [biggestDim]: rightProb }),
309
+ box: {
310
+ ...box,
311
+ [biggestDim]: lazy(setOperations, setOperations.top, rightDim),
312
+ },
313
+ probabilities: { ...probabilities, [biggestDim]: rightProb },
316
314
  depth: currentBox.depth + 1,
317
315
  },
318
316
  ];
@@ -397,7 +395,7 @@ export function unionProduct(left, right) {
397
395
  if (left === dense) {
398
396
  return left;
399
397
  }
400
- const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
398
+ const productOperations = { ...left.productOperations, ...right.productOperations };
401
399
  const res = unionUntypedProduct(productOperations, left.root, right.root, top(productOperations));
402
400
  if (res === empty) {
403
401
  return res;
@@ -436,7 +434,7 @@ export function intersectProduct(left, right) {
436
434
  if (right === dense) {
437
435
  return left;
438
436
  }
439
- const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
437
+ const productOperations = { ...left.productOperations, ...right.productOperations };
440
438
  const res = intersectUntypedProduct(productOperations, left.root, right.root, top(productOperations));
441
439
  if (res === empty) {
442
440
  return res;
@@ -470,10 +468,13 @@ function tryExceptSubspaces(productOperations, left, right) {
470
468
  if (newDim === dense) {
471
469
  // we are actually deleting the `differentDimension`, so the variable
472
470
  // `deleted` must be there. Hence disabling the rule here.
473
- const _a = left.bounds, _b = notContainedDimension, deleted = _a[_b], leftBoundsWithoutDifferentDimension = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
471
+ const { [notContainedDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;
474
472
  return subspace(leftBoundsWithoutDifferentDimension);
475
473
  }
476
- const newBounds = Object.assign(Object.assign({}, left.bounds), { [notContainedDimension]: newDim });
474
+ const newBounds = {
475
+ ...left.bounds,
476
+ [notContainedDimension]: newDim,
477
+ };
477
478
  return subspace(newBounds);
478
479
  }
479
480
  return undefined;
@@ -516,7 +517,7 @@ export function exceptProduct(left, right) {
516
517
  }
517
518
  return sparseProduct(right.productOperations, res_inner);
518
519
  }
519
- const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
520
+ const productOperations = { ...left.productOperations, ...right.productOperations };
520
521
  const res = exceptUntypedProduct(productOperations, left.root, right.root, top(productOperations));
521
522
  if (res === empty) {
522
523
  return res;
@@ -575,7 +576,7 @@ export function compareProduct(left, right) {
575
576
  if (right === dense) {
576
577
  return -1;
577
578
  }
578
- const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
579
+ const productOperations = { ...left.productOperations, ...right.productOperations };
579
580
  return compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));
580
581
  }
581
582
  function meetsSubspace(productOperations, left, right) {
@@ -618,7 +619,7 @@ export function meetsProduct(left, right) {
618
619
  if (left === dense || right === dense) {
619
620
  return true;
620
621
  }
621
- const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
622
+ const productOperations = { ...left.productOperations, ...right.productOperations };
622
623
  return meetsUntypedProduct(productOperations, left.root, right.root, top(productOperations));
623
624
  }
624
625
  export const complementProduct = (set) => exceptProduct(dense, set);
@@ -1 +1 @@
1
- {"version":3,"file":"productSet.js","sourceRoot":"","sources":["../src/productSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;AAEH,OAAO,EAEN,KAAK,EACL,KAAK,EAGL,UAAU,EAEV,gBAAgB,EAChB,cAAc,EAGd,YAAY,EACZ,aAAa,EACb,IAAI,EAEJ,WAAW,EACX,YAAY,GAEZ,MAAM,UAAU,CAAC;AAmElB,MAAM,IAAI,GAAyC,EAAE,CAAC;AACtD,MAAM,GAAG,GAAG,CAAI,iBAAuC,EAAU,EAAE;IAClE,MAAM,IAAI,GAAqD,EAAE,CAAC;IAClE,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,iBA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AK,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,GAAkB;IACrD,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,EAAE;QACnC,OAAO,CAAC,CAAC;KACT;IACD,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tBspSet,\n\tempty,\n\tdense,\n\tEmpty,\n\tDense,\n\tcombineCmp,\n\tSetOperations,\n\tintersectUntyped,\n\tcompareUntyped,\n\tCachable,\n\tUntypedBspSet,\n\tunionUntyped,\n\texceptUntyped,\n\tlazy,\n\tUntypedSparse,\n\tfromUntyped,\n\tmeetsUntyped,\n\tPair,\n} from \"./bspSet\";\n\ntype Restrict<T, Props extends (keyof T)[]> = { [Prop in Props[number]]: T[Prop] };\n\nexport type Product<T> = {\n\treadonly [dim in keyof T]: T[dim] extends BspSet<infer _TKey, infer _TId> ? T[dim] : never;\n};\n\ntype UntypedProduct<T> = {\n\treadonly [dim in keyof T]?: T[dim] extends BspSet<infer TKey, infer _TId>\n\t\t? UntypedSparse<TKey>\n\t\t: never;\n};\n\ntype Probabilities<T> = { readonly [dim in keyof T]?: number };\n\ntype ProductOperations<T> = {\n\treadonly [dim in keyof T]: T[dim] extends BspSet<infer TKey, infer TId>\n\t\t? SetOperations<TKey, TId>\n\t\t: never;\n};\n\n/** Given a cartesian product, a subspace is a subset of said space, such that it is also a cartesian product\n * and all the dimensions form subsets of the original cartesian product.\n *\n * This is a generalized notion of something like hyper-rectangles. Examples include:\n * - Rectangles\n * - Individual cells in a grid\n * - Rectangular ranges with missing rows and/or columns\n *\n * For the actual definition and properties, please read the document about *Operations on Cartesian Products*.\n */\ninterface Subspace<T> {\n\treadonly isSubspace: true;\n\t// isCoSubspace: boolean;\n\treadonly bounds: UntypedProduct<T>;\n}\n\n// type CoSubspace<T> = {\n// isSubspace: boolean;\n// isCoSubspace: true;\n// subspace: Product<T>;\n// };\n\ninterface Union<T> {\n\treadonly isSubspace: false;\n\t// readonly isCoSubspace: false;\n\treadonly left: UntypedSparseProduct<T>;\n\treadonly right: UntypedSparseProduct<T>;\n\treadonly bounds: UntypedProduct<T>;\n\treadonly subspaceCount: number;\n}\n\ntype UntypedSparseProduct<T> = Subspace<T> | Union<T>; // | CoSubspace<T>;\n\ninterface SparseProduct<T> {\n\treadonly productOperations: ProductOperations<T>;\n\treadonly root: UntypedSparseProduct<T>;\n}\n\ninterface Box<T> {\n\tbox: UntypedProduct<T>;\n\tprobabilities: Probabilities<T>;\n\tchildren?: Pair<Box<T>>;\n\tdepth: number;\n}\n\nconst tops: { [poKey in string]?: Box<unknown> } = {};\nconst top = <T>(productOperations: ProductOperations<T>): Box<T> => {\n\tconst dims: [keyof T, ProductOperations<T>[keyof T][\"id\"]][] = [];\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tdims.push([dim, productOperations[dim].id]);\n\t}\n\n\tconst poKey = JSON.stringify(dims.sort());\n\tlet currTop = tops[poKey];\n\tif (currTop === undefined) {\n\t\tcurrTop = { box: {}, probabilities: {}, depth: 1 };\n\t\ttops[poKey] = currTop;\n\t}\n\n\treturn currTop;\n};\n\nfunction subspace<T>(bounds: UntypedProduct<T>): Subspace<T> | Dense {\n\tlet isDense = true;\n\tfor (const dim of Object.keys(bounds)) {\n\t\tif (Object.prototype.hasOwnProperty.call(bounds, dim)) {\n\t\t\tisDense = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (isDense) {\n\t\treturn dense;\n\t}\n\treturn { isSubspace: true as const, bounds };\n}\n\nfunction getUntypedSubspaceCount<T>(set: UntypedSparseProduct<T>) {\n\tif (set.isSubspace) {\n\t\treturn 1;\n\t}\n\treturn set.subspaceCount;\n}\n\nconst union = <T>(\n\tleft: UntypedSparseProduct<T>,\n\tright: UntypedSparseProduct<T>,\n\tbounds: UntypedProduct<T>,\n): Union<T> => ({\n\tisSubspace: false as const,\n\tleft,\n\tright,\n\tbounds,\n\tsubspaceCount: getUntypedSubspaceCount(left) + getUntypedSubspaceCount(right),\n});\n\nfunction sparseProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\troot: UntypedSparseProduct<T> | Dense,\n): SparseProduct<T> | Dense {\n\tif (root === dense) {\n\t\treturn root;\n\t}\n\tif (root.isSubspace) {\n\t\tlet hasSparseDimensions = false;\n\t\tfor (const dim of Object.keys(root.bounds)) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\thasSparseDimensions = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasSparseDimensions) {\n\t\t\treturn dense;\n\t\t}\n\t}\n\treturn { productOperations, root };\n}\n\ntype UntypedProductSet<T> = Empty | Dense | UntypedSparseProduct<T>;\nexport type ProductSet<T> = Empty | Dense | SparseProduct<T>;\n\nfunction toBspSet<T>(set: UntypedBspSet<T> | undefined) {\n\tif (set === undefined) {\n\t\treturn dense;\n\t}\n\treturn set;\n}\n\n/** An object that contains all downcasts. The operations in here are generally of the kind that need dynamic\n * features, i.e. iterate over the object properties somehow. Their *usage* can be considered safe, but they warrant\n * more careful review whenever a change occurs, because we get less support from the type system and we are\n * downcasting. */\nconst unsafe = {\n\tunzip<T>(product: Product<T>): ProductSet<T> {\n\t\tconst productOperations: { [dim in keyof T]?: SetOperations<unknown, unknown> } = {};\n\t\tconst root: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n\t\tfor (const dimStr of Object.keys(product)) {\n\t\t\tconst dim = dimStr as keyof T;\n\t\t\tif (Object.prototype.hasOwnProperty.call(product, dim)) {\n\t\t\t\tconst set: BspSet<unknown, unknown> = product[dim];\n\t\t\t\tif (set === empty) {\n\t\t\t\t\treturn empty;\n\t\t\t\t}\n\t\t\t\tif (set === dense) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tproductOperations[dim] = set.setOperations;\n\t\t\t\troot[dim] = set.root;\n\t\t\t}\n\t\t}\n\n\t\treturn sparseProduct(\n\t\t\tproductOperations as ProductOperations<T>,\n\t\t\tsubspace(root as UntypedProduct<T>),\n\t\t);\n\t},\n\n\tcombineProduct<T>(\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: UntypedProduct<T>,\n\t\tright: UntypedProduct<T>,\n\t\tcombineFunc: <Key extends Cachable<Key>, Id>(\n\t\t\tsetOperations: SetOperations<Key, Id>,\n\t\t\tleft: UntypedBspSet<Key>,\n\t\t\tright: UntypedBspSet<Key>,\n\t\t) => UntypedBspSet<Key>,\n\t) {\n\t\tconst res: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n\t\tfor (const dimStr of Object.keys(productOperations)) {\n\t\t\tconst dim = dimStr as keyof T;\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\tconst combined = combineFunc<unknown, unknown>(\n\t\t\t\t\tproductOperations[dim],\n\t\t\t\t\ttoBspSet(left[dim]),\n\t\t\t\t\ttoBspSet(right[dim]),\n\t\t\t\t);\n\t\t\t\tif (combined === empty) {\n\t\t\t\t\treturn combined;\n\t\t\t\t}\n\t\t\t\tif (combined === dense) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres[dim] = combined;\n\t\t\t}\n\t\t}\n\n\t\treturn res as UntypedProduct<T>;\n\t},\n\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n\trestrict<T extends object, Props extends (keyof T)[]>(object: T, ...props: Props) {\n\t\tconst res: Partial<Restrict<T, Props>> = {};\n\t\tfor (const key of props) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(object, key)) {\n\t\t\t\tconst prop = object[key];\n\t\t\t\tres[key] = prop;\n\t\t\t}\n\t\t}\n\n\t\treturn res as Restrict<T, Props>;\n\t},\n\n\tfromUntypedProduct<T, Props extends (keyof T)[]>(\n\t\tproductOperations: ProductOperations<Restrict<T, Props>>,\n\t\tbounds: UntypedProduct<Restrict<T, Props>>,\n\t\tdims: Props,\n\t) {\n\t\tconst product: { [dim in Props[number]]?: BspSet<unknown, unknown> } = {};\n\t\tfor (const dim of dims) {\n\t\t\tconst bound: UntypedSparse<unknown> | undefined = bounds[dim];\n\t\t\tproduct[dim] = fromUntyped(productOperations[dim], bound !== undefined ? bound : dense);\n\t\t}\n\t\treturn product as Product<Restrict<T, Props>>;\n\t},\n\n\tdenseProduct<T, Props extends (keyof T)[]>(dims: Props): Product<Restrict<T, Props>> {\n\t\tconst top_inner: { [dim in Props[number]]?: Dense } = {};\n\t\tfor (const dim of dims) {\n\t\t\ttop_inner[dim] = dense;\n\t\t}\n\t\treturn top_inner as Product<Restrict<T, Props>>;\n\t},\n};\n\nexport const createFromProduct = unsafe.unzip.bind(unsafe);\n\ntype Compatible<T, U> = { [dim in keyof T & keyof U]: T[dim] };\n\nfunction joinBounds<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tconst join = unsafe.combineProduct(productOperations, left, right, unionUntyped);\n\tif (join === empty) {\n\t\tthrow new Error(\"broken invariant: the union of two non-empty products cannot be empty\");\n\t}\n\n\treturn join;\n}\n\nfunction compareSubspace<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tlet cmp: ReturnType<typeof combineCmp> = 0;\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst lProj = toBspSet(left[dim]);\n\t\t\tconst rProj = toBspSet(right[dim]);\n\t\t\tconst setOperations = productOperations[dim];\n\n\t\t\tcmp = combineCmp(cmp, compareUntyped<unknown, unknown>(setOperations, lProj, rProj));\n\n\t\t\tif (cmp === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn cmp;\n}\n\nconst tryUnionSubspaces = (() => {\n\tconst cache: { left?: unknown; right?: unknown; res?: unknown } = {};\n\treturn <T>(\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: Subspace<T>,\n\t\tright: Subspace<T>,\n\t): Subspace<T> | Dense | Empty | undefined => {\n\t\tif (left === cache.left && right === cache.right) {\n\t\t\treturn cache.res as ReturnType<typeof tryUnionSubspaces>;\n\t\t}\n\t\tcache.left = left;\n\t\tcache.right = right;\n\n\t\tconst cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n\t\tif (cmp !== undefined) {\n\t\t\treturn (cache.res = cmp <= 0 ? right : left);\n\t\t}\n\t\tlet differentDimension: keyof T | undefined;\n\n\t\t// because Object.keys only returns string[], we need to downcast\n\t\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\t\tfor (const dim of po_keys) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\tconst cmp_inner = compareUntyped<unknown, unknown>(\n\t\t\t\t\tproductOperations[dim],\n\t\t\t\t\ttoBspSet(left.bounds[dim]),\n\t\t\t\t\ttoBspSet(right.bounds[dim]),\n\t\t\t\t);\n\t\t\t\tif (cmp_inner !== 0) {\n\t\t\t\t\tif (differentDimension !== undefined) {\n\t\t\t\t\t\treturn (cache.res = undefined);\n\t\t\t\t\t}\n\n\t\t\t\t\tdifferentDimension = dim;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (differentDimension !== undefined) {\n\t\t\tconst newDim = unionUntyped<unknown, unknown>(\n\t\t\t\tproductOperations[differentDimension],\n\t\t\t\ttoBspSet(left.bounds[differentDimension]),\n\t\t\t\ttoBspSet(right.bounds[differentDimension]),\n\t\t\t);\n\t\t\tif (newDim === empty) {\n\t\t\t\treturn (cache.res = empty);\n\t\t\t}\n\t\t\tif (newDim === dense) {\n\t\t\t\t// we are actually deleting the `differentDimension`, so the variable\n\t\t\t\t// `deleted` must be there. Hence disabling the rule here.\n\t\t\t\tconst { [differentDimension]: deleted, ...leftBoundsWithoutDifferentDimension } =\n\t\t\t\t\tleft.bounds;\n\t\t\t\treturn (cache.res = subspace<unknown>(leftBoundsWithoutDifferentDimension));\n\t\t\t}\n\n\t\t\tconst newBounds: UntypedProduct<T> = {\n\t\t\t\t...left.bounds,\n\t\t\t\t[differentDimension]: newDim,\n\t\t\t};\n\t\t\treturn (cache.res = subspace(newBounds));\n\t\t}\n\n\t\treturn (cache.res = undefined);\n\t};\n})();\n\nfunction combineChildren<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n): UntypedProductSet<T> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\n\tif (!left.isSubspace || !right.isSubspace) {\n\t\treturn union<T>(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n\t}\n\n\tconst combinedSubspace = tryUnionSubspaces<T>(productOperations, left, right);\n\n\tif (combinedSubspace !== undefined) {\n\t\treturn combinedSubspace;\n\t}\n\treturn union(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n}\n\nfunction projectUntyped<T, Props extends (keyof T)[]>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedSparseProduct<T>,\n\t...dims: Props\n): UntypedProductSet<Restrict<T, Props>> {\n\tconst bounds = unsafe.restrict(set.bounds, ...dims);\n\tif (set.isSubspace) {\n\t\treturn subspace(bounds);\n\t}\n\n\tconst lChild = projectUntyped(productOperations, set.left, ...dims);\n\tif (lChild === dense) {\n\t\treturn dense;\n\t}\n\tconst rChild = projectUntyped(productOperations, set.right, ...dims);\n\treturn combineChildren(productOperations, lChild, rChild);\n}\n\nexport function project<T, Props extends (keyof T)[]>(\n\tset: ProductSet<T>,\n\t...dims: Props\n): ProductSet<Restrict<T, Props>> {\n\tif (set === dense || set === empty) {\n\t\treturn set;\n\t}\n\tconst productOperations = unsafe.restrict(set.productOperations, ...dims);\n\tconst root = projectUntyped(productOperations, set.root, ...dims);\n\tif (root === empty) {\n\t\treturn root;\n\t}\n\treturn sparseProduct(productOperations, root);\n}\n\nfunction splitBox<T>(productOperations: ProductOperations<T>, currentBox: Box<T>): Pair<Box<T>> {\n\tif (currentBox.children !== undefined) {\n\t\treturn currentBox.children;\n\t}\n\tconst { box, probabilities } = currentBox;\n\tlet biggestDim: keyof T | undefined;\n\tlet biggestDimKey;\n\tlet currentProb = 0;\n\t// because Object.keys only returns string[], we need to downcast\n\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\tfor (const dim of po_keys) {\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst prob: number | undefined = probabilities[dim];\n\t\t\tconst setOperations_inner = productOperations[dim];\n\t\t\tif (prob === undefined) {\n\t\t\t\tbiggestDim = dim;\n\t\t\t\tbiggestDimKey = setOperations_inner.top;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (prob > currentProb) {\n\t\t\t\tconst dimensionSet = toBspSet(box[dim]);\n\t\t\t\tif (dimensionSet === empty) {\n\t\t\t\t\tthrow new Error(\"the key split can never return empty\");\n\t\t\t\t}\n\t\t\t\tlet key = setOperations_inner.top;\n\t\t\t\tif (dimensionSet !== dense) {\n\t\t\t\t\tif (!dimensionSet.isExact) {\n\t\t\t\t\t\tthrow new Error(\"the key can always be represented exactly\");\n\t\t\t\t\t}\n\n\t\t\t\t\tkey = dimensionSet.key;\n\t\t\t\t}\n\t\t\t\tif (!setOperations_inner.canSplit(key)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbiggestDim = dim;\n\t\t\t\tcurrentProb = prob;\n\t\t\t\tbiggestDimKey = key;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (biggestDim === undefined || biggestDimKey === undefined) {\n\t\tthrow new Error(\"there has to be at least one dimension\");\n\t}\n\n\tconst setOperations = productOperations[biggestDim];\n\n\tconst [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);\n\tconst res: ReturnType<typeof splitBox> = [\n\t\t{\n\t\t\tbox: {\n\t\t\t\t...box,\n\t\t\t\t[biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, leftDim),\n\t\t\t},\n\t\t\tprobabilities: { ...probabilities, [biggestDim]: leftProb },\n\t\t\tdepth: currentBox.depth + 1,\n\t\t},\n\t\t{\n\t\t\tbox: {\n\t\t\t\t...box,\n\t\t\t\t[biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, rightDim),\n\t\t\t},\n\t\t\tprobabilities: { ...probabilities, [biggestDim]: rightProb },\n\t\t\tdepth: currentBox.depth + 1,\n\t\t},\n\t];\n\tif (currentBox.depth < 10) {\n\t\tcurrentBox.children = res;\n\t}\n\treturn res;\n}\n\nfunction restrictByBounds<T>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedProductSet<T>,\n\tleftBounds: UntypedProduct<T>,\n\trightBounds: UntypedProduct<T>,\n): Pair<UntypedProductSet<T>> {\n\tif (set === empty) {\n\t\treturn [empty, empty];\n\t}\n\tif (set === dense) {\n\t\treturn [subspace(leftBounds), subspace(rightBounds)];\n\t}\n\tconst cmp = compareSubspace(productOperations, set.bounds, leftBounds);\n\n\t// the set is fully contained in the left half, i.e. we know the pair.\n\tif (cmp !== undefined && cmp <= 0) {\n\t\treturn [set, empty];\n\t}\n\n\tconst newLeftBounds = unsafe.combineProduct(\n\t\tproductOperations,\n\t\tset.bounds,\n\t\tleftBounds,\n\t\tintersectUntyped,\n\t);\n\n\t// if we know, that the left set is completely empty, then the whole set is in the right bounds.\n\tif (newLeftBounds === empty) {\n\t\treturn [empty, set];\n\t}\n\n\tconst newRightBounds = unsafe.combineProduct(\n\t\tproductOperations,\n\t\tset.bounds,\n\t\trightBounds,\n\t\tintersectUntyped,\n\t);\n\tif (set.isSubspace) {\n\t\treturn [\n\t\t\tsubspace(newLeftBounds),\n\t\t\tnewRightBounds === empty ? empty : subspace(newRightBounds),\n\t\t];\n\t}\n\n\tconst [ll, lr] = restrictByBounds(productOperations, set.left, leftBounds, rightBounds);\n\tconst [rl, rr] = restrictByBounds(productOperations, set.right, leftBounds, rightBounds);\n\treturn [combineChildren(productOperations, ll, rl), combineChildren(productOperations, lr, rr)];\n}\n\nconst splitByBox = <T>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedProductSet<T>,\n\t{ box: leftBounds }: Box<T>,\n\t{ box: rightBounds }: Box<T>,\n): Pair<UntypedProductSet<T>, UntypedProductSet<T>> => {\n\treturn restrictByBounds(productOperations, set, leftBounds, rightBounds);\n};\n\nfunction recurse<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n\tvisitFunc: (\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: UntypedProductSet<T>,\n\t\tright: UntypedProductSet<T>,\n\t\tbox: Box<T>,\n\t) => UntypedProductSet<T>,\n) {\n\tconst [leftBox, rightBox] = splitBox(productOperations, currentBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\tconst lChild = visitFunc(productOperations, ll, rl, leftBox);\n\tif (lChild === dense) {\n\t\treturn dense;\n\t}\n\tconst rChild = visitFunc(productOperations, lr, rr, rightBox);\n\treturn combineChildren(productOperations, lChild, rChild);\n}\n\nfunction unionUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst combinedSubspace = tryUnionSubspaces(productOperations, left, right);\n\t\tif (combinedSubspace !== undefined) {\n\t\t\treturn combinedSubspace;\n\t\t}\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, unionUntypedProduct);\n}\n\nexport function unionProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = unionUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction intersectUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (left === empty || right === empty) {\n\t\treturn empty;\n\t}\n\tif (left === dense) {\n\t\treturn right;\n\t}\n\tif (right === dense) {\n\t\treturn left;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst res = unsafe.combineProduct(\n\t\t\tproductOperations,\n\t\t\tleft.bounds,\n\t\t\tright.bounds,\n\t\t\tintersectUntyped,\n\t\t);\n\t\tif (res === empty) {\n\t\t\treturn empty;\n\t\t}\n\t\treturn subspace(res);\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, intersectUntypedProduct);\n}\n\nexport function intersectProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn right;\n\t}\n\tif (right === dense) {\n\t\treturn left;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = intersectUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction tryExceptSubspaces<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: Subspace<T>,\n\tright: Subspace<T>,\n): Subspace<T> | Dense | Empty | undefined {\n\tconst cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n\tif (cmp === 0 || cmp === -1) {\n\t\treturn empty;\n\t}\n\tlet notContainedDimension: keyof T | undefined;\n\t// because Object.keys only returns string[], we need to downcast\n\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\tfor (const dim of po_keys) {\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst cmp_inner = compareUntyped<unknown, unknown>(\n\t\t\t\tproductOperations[dim],\n\t\t\t\ttoBspSet(left.bounds[dim]),\n\t\t\t\ttoBspSet(right.bounds[dim]),\n\t\t\t);\n\t\t\tif (cmp_inner === undefined || cmp_inner > 0) {\n\t\t\t\tif (notContainedDimension !== undefined) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tnotContainedDimension = dim;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (notContainedDimension !== undefined) {\n\t\tconst newDim = exceptUntyped<unknown, unknown>(\n\t\t\tproductOperations[notContainedDimension],\n\t\t\ttoBspSet(left.bounds[notContainedDimension]),\n\t\t\ttoBspSet(right.bounds[notContainedDimension]),\n\t\t);\n\n\t\tif (newDim === empty) {\n\t\t\treturn empty;\n\t\t}\n\t\tif (newDim === dense) {\n\t\t\t// we are actually deleting the `differentDimension`, so the variable\n\t\t\t// `deleted` must be there. Hence disabling the rule here.\n\t\t\tconst { [notContainedDimension]: deleted, ...leftBoundsWithoutDifferentDimension } =\n\t\t\t\tleft.bounds;\n\t\t\treturn subspace<unknown>(leftBoundsWithoutDifferentDimension);\n\t\t}\n\t\tconst newBounds: UntypedProduct<T> = {\n\t\t\t...left.bounds,\n\t\t\t[notContainedDimension]: newDim,\n\t\t};\n\t\treturn subspace(newBounds);\n\t}\n\n\treturn undefined;\n}\n\nfunction exceptUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn empty;\n\t}\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\n\tif (left === dense) {\n\t\treturn recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n\t}\n\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst combinedSubspace = tryExceptSubspaces(productOperations, left, right);\n\t\tif (combinedSubspace !== undefined) {\n\t\t\treturn combinedSubspace;\n\t\t}\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n}\n\nexport function exceptProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn empty;\n\t}\n\tif (left === dense) {\n\t\tconst res_inner = exceptUntypedProduct(\n\t\t\tright.productOperations,\n\t\t\tdense,\n\t\t\tright.root,\n\t\t\ttop(right.productOperations),\n\t\t);\n\t\tif (res_inner === empty) {\n\t\t\treturn res_inner;\n\t\t}\n\t\treturn sparseProduct(right.productOperations, res_inner);\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = exceptUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction compareUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tboundingBox: Box<T>,\n): -1 | 0 | 1 | undefined {\n\tif (left === right) {\n\t\treturn 0;\n\t}\n\n\tif (left === empty) {\n\t\treturn -1;\n\t}\n\n\tif (right === empty) {\n\t\treturn 1;\n\t}\n\n\tif (left === dense) {\n\t\tif (right === dense) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif (right === dense) {\n\t\treturn -1;\n\t}\n\n\tif (left.isSubspace) {\n\t\tif (right.isSubspace) {\n\t\t\treturn compareSubspace(productOperations, left.bounds, right.bounds);\n\t\t}\n\t}\n\n\tconst [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\tconst leftCmp = compareUntypedProduct(productOperations, ll, rl, leftBox);\n\tif (leftCmp === undefined) {\n\t\treturn undefined;\n\t}\n\treturn combineCmp(leftCmp, compareUntypedProduct(productOperations, lr, rr, rightBox));\n}\n\nexport function compareProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n) {\n\tif (left === right) {\n\t\treturn 0;\n\t}\n\n\tif (left === empty) {\n\t\treturn -1;\n\t}\n\n\tif (right === empty) {\n\t\treturn 1;\n\t}\n\n\tif (left === dense) {\n\t\tif (right === dense) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif (right === dense) {\n\t\treturn -1;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\treturn compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nfunction meetsSubspace<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst lProj = toBspSet(left[dim]);\n\t\t\tconst rProj = toBspSet(right[dim]);\n\t\t\tconst setOperations = productOperations[dim];\n\t\t\tif (!meetsUntyped<unknown, unknown>(setOperations, lProj, rProj)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n}\n\nfunction meetsUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tboundingBox: Box<T>,\n): boolean {\n\tif (left === empty || right === empty) {\n\t\treturn false;\n\t}\n\tif (left === dense || right === dense) {\n\t\treturn true;\n\t}\n\tif (!meetsSubspace(productOperations, left.bounds, right.bounds)) {\n\t\treturn false;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\treturn true;\n\t}\n\n\tconst [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\treturn (\n\t\tmeetsUntypedProduct(productOperations, ll, rl, leftBox) ||\n\t\tmeetsUntypedProduct(productOperations, lr, rr, rightBox)\n\t);\n}\n\nexport function meetsProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n) {\n\tif (left === empty || right === empty) {\n\t\treturn false;\n\t}\n\tif (left === dense || right === dense) {\n\t\treturn true;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\treturn meetsUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nexport const complementProduct = <T>(set: ProductSet<T>) => exceptProduct(dense, set);\n\nexport const symmetricDiffProduct = <T>(left: ProductSet<T>, right: ProductSet<T>) =>\n\tunionProduct(exceptProduct(left, right), exceptProduct(right, left));\n\nexport function getSubspaces<T>(set: ProductSet<T>) {\n\tif (set === empty || set === dense) {\n\t\treturn [];\n\t}\n\tconst res: UntypedProduct<T>[] = [];\n\tfunction loop(root: UntypedSparseProduct<T>) {\n\t\tif (root.isSubspace) {\n\t\t\tres.push(root.bounds);\n\t\t\treturn;\n\t\t}\n\n\t\tloop(root.left);\n\t\tloop(root.right);\n\t}\n\n\tloop(set.root);\n\treturn res;\n}\n\nexport function forEachProduct<T, Props extends (keyof T)[]>(\n\tset: ProductSet<T>,\n\tf: (product: Product<Restrict<T, Props>>) => boolean,\n\t...dims: Props\n): boolean {\n\tconst newSet = project(set, ...dims);\n\tif (newSet === empty) {\n\t\treturn true;\n\t}\n\tif (newSet === dense) {\n\t\treturn f(unsafe.denseProduct(dims));\n\t}\n\n\tconst { productOperations, root } = newSet;\n\n\tfunction loop(root_inner: UntypedSparseProduct<T>): boolean {\n\t\tif (root_inner.isSubspace) {\n\t\t\treturn f(unsafe.fromUntypedProduct(productOperations, root_inner.bounds, dims));\n\t\t}\n\t\treturn loop(root_inner.left) && loop(root_inner.right);\n\t}\n\n\treturn loop(root);\n}\n\nexport function getSubspaceCount<T>(set: ProductSet<T>) {\n\tif (set === empty || set === dense) {\n\t\treturn 0;\n\t}\n\treturn getUntypedSubspaceCount(set.root);\n}\n"]}
1
+ {"version":3,"file":"productSet.js","sourceRoot":"","sources":["../src/productSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,KAAK,EACL,KAAK,EAGL,UAAU,EAEV,gBAAgB,EAChB,cAAc,EAGd,YAAY,EACZ,aAAa,EACb,IAAI,EAEJ,WAAW,EACX,YAAY,GAEZ,MAAM,UAAU,CAAC;AAmElB,MAAM,IAAI,GAAyC,EAAE,CAAC;AACtD,MAAM,GAAG,GAAG,CAAI,iBAAuC,EAAU,EAAE;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;QAChD,IAAI,UAAU,CAAC,UAAU,EAAE;YAC1B,OAAO,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;SAChF;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,GAAkB;IACrD,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,EAAE;QACnC,OAAO,CAAC,CAAC;KACT;IACD,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tBspSet,\n\tempty,\n\tdense,\n\tEmpty,\n\tDense,\n\tcombineCmp,\n\tSetOperations,\n\tintersectUntyped,\n\tcompareUntyped,\n\tCachable,\n\tUntypedBspSet,\n\tunionUntyped,\n\texceptUntyped,\n\tlazy,\n\tUntypedSparse,\n\tfromUntyped,\n\tmeetsUntyped,\n\tPair,\n} from \"./bspSet\";\n\ntype Restrict<T, Props extends (keyof T)[]> = { [Prop in Props[number]]: T[Prop] };\n\nexport type Product<T> = {\n\treadonly [dim in keyof T]: T[dim] extends BspSet<infer _TKey, infer _TId> ? T[dim] : never;\n};\n\ntype UntypedProduct<T> = {\n\treadonly [dim in keyof T]?: T[dim] extends BspSet<infer TKey, infer _TId>\n\t\t? UntypedSparse<TKey>\n\t\t: never;\n};\n\ntype Probabilities<T> = { readonly [dim in keyof T]?: number };\n\ntype ProductOperations<T> = {\n\treadonly [dim in keyof T]: T[dim] extends BspSet<infer TKey, infer TId>\n\t\t? SetOperations<TKey, TId>\n\t\t: never;\n};\n\n/** Given a cartesian product, a subspace is a subset of said space, such that it is also a cartesian product\n * and all the dimensions form subsets of the original cartesian product.\n *\n * This is a generalized notion of something like hyper-rectangles. Examples include:\n * - Rectangles\n * - Individual cells in a grid\n * - Rectangular ranges with missing rows and/or columns\n *\n * For the actual definition and properties, please read the document about *Operations on Cartesian Products*.\n */\ninterface Subspace<T> {\n\treadonly isSubspace: true;\n\t// isCoSubspace: boolean;\n\treadonly bounds: UntypedProduct<T>;\n}\n\n// type CoSubspace<T> = {\n// isSubspace: boolean;\n// isCoSubspace: true;\n// subspace: Product<T>;\n// };\n\ninterface Union<T> {\n\treadonly isSubspace: false;\n\t// readonly isCoSubspace: false;\n\treadonly left: UntypedSparseProduct<T>;\n\treadonly right: UntypedSparseProduct<T>;\n\treadonly bounds: UntypedProduct<T>;\n\treadonly subspaceCount: number;\n}\n\ntype UntypedSparseProduct<T> = Subspace<T> | Union<T>; // | CoSubspace<T>;\n\ninterface SparseProduct<T> {\n\treadonly productOperations: ProductOperations<T>;\n\treadonly root: UntypedSparseProduct<T>;\n}\n\ninterface Box<T> {\n\tbox: UntypedProduct<T>;\n\tprobabilities: Probabilities<T>;\n\tchildren?: Pair<Box<T>>;\n\tdepth: number;\n}\n\nconst tops: { [poKey in string]?: Box<unknown> } = {};\nconst top = <T>(productOperations: ProductOperations<T>): Box<T> => {\n\tconst dims: [keyof T, ProductOperations<T>[keyof T][\"id\"]][] = [];\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tdims.push([dim, productOperations[dim].id]);\n\t}\n\n\tconst poKey = JSON.stringify(dims.sort());\n\tlet currTop = tops[poKey];\n\tif (currTop === undefined) {\n\t\tcurrTop = { box: {}, probabilities: {}, depth: 1 };\n\t\ttops[poKey] = currTop;\n\t}\n\n\treturn currTop;\n};\n\nfunction subspace<T>(bounds: UntypedProduct<T>): Subspace<T> | Dense {\n\tlet isDense = true;\n\tfor (const dim of Object.keys(bounds)) {\n\t\tif (Object.prototype.hasOwnProperty.call(bounds, dim)) {\n\t\t\tisDense = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (isDense) {\n\t\treturn dense;\n\t}\n\treturn { isSubspace: true as const, bounds };\n}\n\nfunction getUntypedSubspaceCount<T>(set: UntypedSparseProduct<T>) {\n\tif (set.isSubspace) {\n\t\treturn 1;\n\t}\n\treturn set.subspaceCount;\n}\n\nconst union = <T>(\n\tleft: UntypedSparseProduct<T>,\n\tright: UntypedSparseProduct<T>,\n\tbounds: UntypedProduct<T>,\n): Union<T> => ({\n\tisSubspace: false as const,\n\tleft,\n\tright,\n\tbounds,\n\tsubspaceCount: getUntypedSubspaceCount(left) + getUntypedSubspaceCount(right),\n});\n\nfunction sparseProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\troot: UntypedSparseProduct<T> | Dense,\n): SparseProduct<T> | Dense {\n\tif (root === dense) {\n\t\treturn root;\n\t}\n\tif (root.isSubspace) {\n\t\tlet hasSparseDimensions = false;\n\t\tfor (const dim of Object.keys(root.bounds)) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\thasSparseDimensions = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasSparseDimensions) {\n\t\t\treturn dense;\n\t\t}\n\t}\n\treturn { productOperations, root };\n}\n\ntype UntypedProductSet<T> = Empty | Dense | UntypedSparseProduct<T>;\nexport type ProductSet<T> = Empty | Dense | SparseProduct<T>;\n\nfunction toBspSet<T>(set: UntypedBspSet<T> | undefined) {\n\tif (set === undefined) {\n\t\treturn dense;\n\t}\n\treturn set;\n}\n\n/** An object that contains all downcasts. The operations in here are generally of the kind that need dynamic\n * features, i.e. iterate over the object properties somehow. Their *usage* can be considered safe, but they warrant\n * more careful review whenever a change occurs, because we get less support from the type system and we are\n * downcasting. */\nconst unsafe = {\n\tunzip<T>(product: Product<T>): ProductSet<T> {\n\t\tconst productOperations: { [dim in keyof T]?: SetOperations<unknown, unknown> } = {};\n\t\tconst root: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n\t\tfor (const dimStr of Object.keys(product)) {\n\t\t\tconst dim = dimStr as keyof T;\n\t\t\tif (Object.prototype.hasOwnProperty.call(product, dim)) {\n\t\t\t\tconst set: BspSet<unknown, unknown> = product[dim];\n\t\t\t\tif (set === empty) {\n\t\t\t\t\treturn empty;\n\t\t\t\t}\n\t\t\t\tif (set === dense) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tproductOperations[dim] = set.setOperations;\n\t\t\t\troot[dim] = set.root;\n\t\t\t}\n\t\t}\n\n\t\treturn sparseProduct(\n\t\t\tproductOperations as ProductOperations<T>,\n\t\t\tsubspace(root as UntypedProduct<T>),\n\t\t);\n\t},\n\n\tcombineProduct<T>(\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: UntypedProduct<T>,\n\t\tright: UntypedProduct<T>,\n\t\tcombineFunc: <Key extends Cachable<Key>, Id>(\n\t\t\tsetOperations: SetOperations<Key, Id>,\n\t\t\tleft: UntypedBspSet<Key>,\n\t\t\tright: UntypedBspSet<Key>,\n\t\t) => UntypedBspSet<Key>,\n\t) {\n\t\tconst res: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n\t\tfor (const dimStr of Object.keys(productOperations)) {\n\t\t\tconst dim = dimStr as keyof T;\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\tconst combined = combineFunc<unknown, unknown>(\n\t\t\t\t\tproductOperations[dim],\n\t\t\t\t\ttoBspSet(left[dim]),\n\t\t\t\t\ttoBspSet(right[dim]),\n\t\t\t\t);\n\t\t\t\tif (combined === empty) {\n\t\t\t\t\treturn combined;\n\t\t\t\t}\n\t\t\t\tif (combined === dense) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres[dim] = combined;\n\t\t\t}\n\t\t}\n\n\t\treturn res as UntypedProduct<T>;\n\t},\n\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n\trestrict<T extends object, Props extends (keyof T)[]>(object: T, ...props: Props) {\n\t\tconst res: Partial<Restrict<T, Props>> = {};\n\t\tfor (const key of props) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(object, key)) {\n\t\t\t\tconst prop = object[key];\n\t\t\t\tres[key] = prop;\n\t\t\t}\n\t\t}\n\n\t\treturn res as Restrict<T, Props>;\n\t},\n\n\tfromUntypedProduct<T, Props extends (keyof T)[]>(\n\t\tproductOperations: ProductOperations<Restrict<T, Props>>,\n\t\tbounds: UntypedProduct<Restrict<T, Props>>,\n\t\tdims: Props,\n\t) {\n\t\tconst product: { [dim in Props[number]]?: BspSet<unknown, unknown> } = {};\n\t\tfor (const dim of dims) {\n\t\t\tconst bound: UntypedSparse<unknown> | undefined = bounds[dim];\n\t\t\tproduct[dim] = fromUntyped(productOperations[dim], bound !== undefined ? bound : dense);\n\t\t}\n\t\treturn product as Product<Restrict<T, Props>>;\n\t},\n\n\tdenseProduct<T, Props extends (keyof T)[]>(dims: Props): Product<Restrict<T, Props>> {\n\t\tconst top_inner: { [dim in Props[number]]?: Dense } = {};\n\t\tfor (const dim of dims) {\n\t\t\ttop_inner[dim] = dense;\n\t\t}\n\t\treturn top_inner as Product<Restrict<T, Props>>;\n\t},\n};\n\nexport const createFromProduct = unsafe.unzip.bind(unsafe);\n\ntype Compatible<T, U> = { [dim in keyof T & keyof U]: T[dim] };\n\nfunction joinBounds<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tconst join = unsafe.combineProduct(productOperations, left, right, unionUntyped);\n\tif (join === empty) {\n\t\tthrow new Error(\"broken invariant: the union of two non-empty products cannot be empty\");\n\t}\n\n\treturn join;\n}\n\nfunction compareSubspace<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tlet cmp: ReturnType<typeof combineCmp> = 0;\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst lProj = toBspSet(left[dim]);\n\t\t\tconst rProj = toBspSet(right[dim]);\n\t\t\tconst setOperations = productOperations[dim];\n\n\t\t\tcmp = combineCmp(cmp, compareUntyped<unknown, unknown>(setOperations, lProj, rProj));\n\n\t\t\tif (cmp === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn cmp;\n}\n\nconst tryUnionSubspaces = (() => {\n\tconst cache: { left?: unknown; right?: unknown; res?: unknown } = {};\n\treturn <T>(\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: Subspace<T>,\n\t\tright: Subspace<T>,\n\t): Subspace<T> | Dense | Empty | undefined => {\n\t\tif (left === cache.left && right === cache.right) {\n\t\t\treturn cache.res as ReturnType<typeof tryUnionSubspaces>;\n\t\t}\n\t\tcache.left = left;\n\t\tcache.right = right;\n\n\t\tconst cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n\t\tif (cmp !== undefined) {\n\t\t\treturn (cache.res = cmp <= 0 ? right : left);\n\t\t}\n\t\tlet differentDimension: keyof T | undefined;\n\n\t\t// because Object.keys only returns string[], we need to downcast\n\t\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\t\tfor (const dim of po_keys) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\t\tconst cmp_inner = compareUntyped<unknown, unknown>(\n\t\t\t\t\tproductOperations[dim],\n\t\t\t\t\ttoBspSet(left.bounds[dim]),\n\t\t\t\t\ttoBspSet(right.bounds[dim]),\n\t\t\t\t);\n\t\t\t\tif (cmp_inner !== 0) {\n\t\t\t\t\tif (differentDimension !== undefined) {\n\t\t\t\t\t\treturn (cache.res = undefined);\n\t\t\t\t\t}\n\n\t\t\t\t\tdifferentDimension = dim;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (differentDimension !== undefined) {\n\t\t\tconst newDim = unionUntyped<unknown, unknown>(\n\t\t\t\tproductOperations[differentDimension],\n\t\t\t\ttoBspSet(left.bounds[differentDimension]),\n\t\t\t\ttoBspSet(right.bounds[differentDimension]),\n\t\t\t);\n\t\t\tif (newDim === empty) {\n\t\t\t\treturn (cache.res = empty);\n\t\t\t}\n\t\t\tif (newDim === dense) {\n\t\t\t\t// we are actually deleting the `differentDimension`, so the variable\n\t\t\t\t// `deleted` must be there. Hence disabling the rule here.\n\t\t\t\tconst { [differentDimension]: deleted, ...leftBoundsWithoutDifferentDimension } =\n\t\t\t\t\tleft.bounds;\n\t\t\t\treturn (cache.res = subspace<unknown>(leftBoundsWithoutDifferentDimension));\n\t\t\t}\n\n\t\t\tconst newBounds: UntypedProduct<T> = {\n\t\t\t\t...left.bounds,\n\t\t\t\t[differentDimension]: newDim,\n\t\t\t};\n\t\t\treturn (cache.res = subspace(newBounds));\n\t\t}\n\n\t\treturn (cache.res = undefined);\n\t};\n})();\n\nfunction combineChildren<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n): UntypedProductSet<T> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\n\tif (!left.isSubspace || !right.isSubspace) {\n\t\treturn union<T>(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n\t}\n\n\tconst combinedSubspace = tryUnionSubspaces<T>(productOperations, left, right);\n\n\tif (combinedSubspace !== undefined) {\n\t\treturn combinedSubspace;\n\t}\n\treturn union(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n}\n\nfunction projectUntyped<T, Props extends (keyof T)[]>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedSparseProduct<T>,\n\t...dims: Props\n): UntypedProductSet<Restrict<T, Props>> {\n\tconst bounds = unsafe.restrict(set.bounds, ...dims);\n\tif (set.isSubspace) {\n\t\treturn subspace(bounds);\n\t}\n\n\tconst lChild = projectUntyped(productOperations, set.left, ...dims);\n\tif (lChild === dense) {\n\t\treturn dense;\n\t}\n\tconst rChild = projectUntyped(productOperations, set.right, ...dims);\n\treturn combineChildren(productOperations, lChild, rChild);\n}\n\nexport function project<T, Props extends (keyof T)[]>(\n\tset: ProductSet<T>,\n\t...dims: Props\n): ProductSet<Restrict<T, Props>> {\n\tif (set === dense || set === empty) {\n\t\treturn set;\n\t}\n\tconst productOperations = unsafe.restrict(set.productOperations, ...dims);\n\tconst root = projectUntyped(productOperations, set.root, ...dims);\n\tif (root === empty) {\n\t\treturn root;\n\t}\n\treturn sparseProduct(productOperations, root);\n}\n\nfunction splitBox<T>(productOperations: ProductOperations<T>, currentBox: Box<T>): Pair<Box<T>> {\n\tif (currentBox.children !== undefined) {\n\t\treturn currentBox.children;\n\t}\n\tconst { box, probabilities } = currentBox;\n\tlet biggestDim: keyof T | undefined;\n\tlet biggestDimKey;\n\tlet currentProb = 0;\n\t// because Object.keys only returns string[], we need to downcast\n\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\tfor (const dim of po_keys) {\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst prob: number | undefined = probabilities[dim];\n\t\t\tconst setOperations_inner = productOperations[dim];\n\t\t\tif (prob === undefined) {\n\t\t\t\tbiggestDim = dim;\n\t\t\t\tbiggestDimKey = setOperations_inner.top;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (prob > currentProb) {\n\t\t\t\tconst dimensionSet = toBspSet(box[dim]);\n\t\t\t\tif (dimensionSet === empty) {\n\t\t\t\t\tthrow new Error(\"the key split can never return empty\");\n\t\t\t\t}\n\t\t\t\tlet key = setOperations_inner.top;\n\t\t\t\tif (dimensionSet !== dense) {\n\t\t\t\t\tif (!dimensionSet.isExact) {\n\t\t\t\t\t\tthrow new Error(\"the key can always be represented exactly\");\n\t\t\t\t\t}\n\n\t\t\t\t\tkey = dimensionSet.key;\n\t\t\t\t}\n\t\t\t\tif (!setOperations_inner.canSplit(key)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbiggestDim = dim;\n\t\t\t\tcurrentProb = prob;\n\t\t\t\tbiggestDimKey = key;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (biggestDim === undefined || biggestDimKey === undefined) {\n\t\tthrow new Error(\"there has to be at least one dimension\");\n\t}\n\n\tconst setOperations = productOperations[biggestDim];\n\n\tconst [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);\n\tconst res: ReturnType<typeof splitBox> = [\n\t\t{\n\t\t\tbox: {\n\t\t\t\t...box,\n\t\t\t\t[biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, leftDim),\n\t\t\t},\n\t\t\tprobabilities: { ...probabilities, [biggestDim]: leftProb },\n\t\t\tdepth: currentBox.depth + 1,\n\t\t},\n\t\t{\n\t\t\tbox: {\n\t\t\t\t...box,\n\t\t\t\t[biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, rightDim),\n\t\t\t},\n\t\t\tprobabilities: { ...probabilities, [biggestDim]: rightProb },\n\t\t\tdepth: currentBox.depth + 1,\n\t\t},\n\t];\n\tif (currentBox.depth < 10) {\n\t\tcurrentBox.children = res;\n\t}\n\treturn res;\n}\n\nfunction restrictByBounds<T>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedProductSet<T>,\n\tleftBounds: UntypedProduct<T>,\n\trightBounds: UntypedProduct<T>,\n): Pair<UntypedProductSet<T>> {\n\tif (set === empty) {\n\t\treturn [empty, empty];\n\t}\n\tif (set === dense) {\n\t\treturn [subspace(leftBounds), subspace(rightBounds)];\n\t}\n\tconst cmp = compareSubspace(productOperations, set.bounds, leftBounds);\n\n\t// the set is fully contained in the left half, i.e. we know the pair.\n\tif (cmp !== undefined && cmp <= 0) {\n\t\treturn [set, empty];\n\t}\n\n\tconst newLeftBounds = unsafe.combineProduct(\n\t\tproductOperations,\n\t\tset.bounds,\n\t\tleftBounds,\n\t\tintersectUntyped,\n\t);\n\n\t// if we know, that the left set is completely empty, then the whole set is in the right bounds.\n\tif (newLeftBounds === empty) {\n\t\treturn [empty, set];\n\t}\n\n\tconst newRightBounds = unsafe.combineProduct(\n\t\tproductOperations,\n\t\tset.bounds,\n\t\trightBounds,\n\t\tintersectUntyped,\n\t);\n\tif (set.isSubspace) {\n\t\treturn [\n\t\t\tsubspace(newLeftBounds),\n\t\t\tnewRightBounds === empty ? empty : subspace(newRightBounds),\n\t\t];\n\t}\n\n\tconst [ll, lr] = restrictByBounds(productOperations, set.left, leftBounds, rightBounds);\n\tconst [rl, rr] = restrictByBounds(productOperations, set.right, leftBounds, rightBounds);\n\treturn [combineChildren(productOperations, ll, rl), combineChildren(productOperations, lr, rr)];\n}\n\nconst splitByBox = <T>(\n\tproductOperations: ProductOperations<T>,\n\tset: UntypedProductSet<T>,\n\t{ box: leftBounds }: Box<T>,\n\t{ box: rightBounds }: Box<T>,\n): Pair<UntypedProductSet<T>, UntypedProductSet<T>> => {\n\treturn restrictByBounds(productOperations, set, leftBounds, rightBounds);\n};\n\nfunction recurse<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n\tvisitFunc: (\n\t\tproductOperations: ProductOperations<T>,\n\t\tleft: UntypedProductSet<T>,\n\t\tright: UntypedProductSet<T>,\n\t\tbox: Box<T>,\n\t) => UntypedProductSet<T>,\n) {\n\tconst [leftBox, rightBox] = splitBox(productOperations, currentBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\tconst lChild = visitFunc(productOperations, ll, rl, leftBox);\n\tif (lChild === dense) {\n\t\treturn dense;\n\t}\n\tconst rChild = visitFunc(productOperations, lr, rr, rightBox);\n\treturn combineChildren(productOperations, lChild, rChild);\n}\n\nfunction unionUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst combinedSubspace = tryUnionSubspaces(productOperations, left, right);\n\t\tif (combinedSubspace !== undefined) {\n\t\t\treturn combinedSubspace;\n\t\t}\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, unionUntypedProduct);\n}\n\nexport function unionProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn right;\n\t}\n\tif (left === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn left;\n\t}\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = unionUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction intersectUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (left === empty || right === empty) {\n\t\treturn empty;\n\t}\n\tif (left === dense) {\n\t\treturn right;\n\t}\n\tif (right === dense) {\n\t\treturn left;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst res = unsafe.combineProduct(\n\t\t\tproductOperations,\n\t\t\tleft.bounds,\n\t\t\tright.bounds,\n\t\t\tintersectUntyped,\n\t\t);\n\t\tif (res === empty) {\n\t\t\treturn empty;\n\t\t}\n\t\treturn subspace(res);\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, intersectUntypedProduct);\n}\n\nexport function intersectProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === empty) {\n\t\treturn right;\n\t}\n\tif (left === dense) {\n\t\treturn right;\n\t}\n\tif (right === dense) {\n\t\treturn left;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = intersectUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction tryExceptSubspaces<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: Subspace<T>,\n\tright: Subspace<T>,\n): Subspace<T> | Dense | Empty | undefined {\n\tconst cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n\tif (cmp === 0 || cmp === -1) {\n\t\treturn empty;\n\t}\n\tlet notContainedDimension: keyof T | undefined;\n\t// because Object.keys only returns string[], we need to downcast\n\tconst po_keys = Object.keys(productOperations) as (keyof T)[];\n\tfor (const dim of po_keys) {\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst cmp_inner = compareUntyped<unknown, unknown>(\n\t\t\t\tproductOperations[dim],\n\t\t\t\ttoBspSet(left.bounds[dim]),\n\t\t\t\ttoBspSet(right.bounds[dim]),\n\t\t\t);\n\t\t\tif (cmp_inner === undefined || cmp_inner > 0) {\n\t\t\t\tif (notContainedDimension !== undefined) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tnotContainedDimension = dim;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (notContainedDimension !== undefined) {\n\t\tconst newDim = exceptUntyped<unknown, unknown>(\n\t\t\tproductOperations[notContainedDimension],\n\t\t\ttoBspSet(left.bounds[notContainedDimension]),\n\t\t\ttoBspSet(right.bounds[notContainedDimension]),\n\t\t);\n\n\t\tif (newDim === empty) {\n\t\t\treturn empty;\n\t\t}\n\t\tif (newDim === dense) {\n\t\t\t// we are actually deleting the `differentDimension`, so the variable\n\t\t\t// `deleted` must be there. Hence disabling the rule here.\n\t\t\tconst { [notContainedDimension]: deleted, ...leftBoundsWithoutDifferentDimension } =\n\t\t\t\tleft.bounds;\n\t\t\treturn subspace<unknown>(leftBoundsWithoutDifferentDimension);\n\t\t}\n\t\tconst newBounds: UntypedProduct<T> = {\n\t\t\t...left.bounds,\n\t\t\t[notContainedDimension]: newDim,\n\t\t};\n\t\treturn subspace(newBounds);\n\t}\n\n\treturn undefined;\n}\n\nfunction exceptUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tcurrentBox: Box<T>,\n): UntypedProductSet<T> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn empty;\n\t}\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\n\tif (left === dense) {\n\t\treturn recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n\t}\n\n\tif (left.isSubspace && right.isSubspace) {\n\t\tconst combinedSubspace = tryExceptSubspaces(productOperations, left, right);\n\t\tif (combinedSubspace !== undefined) {\n\t\t\treturn combinedSubspace;\n\t\t}\n\t}\n\n\treturn recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n}\n\nexport function exceptProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n): ProductSet<T & U> {\n\tif (left === empty) {\n\t\treturn left;\n\t}\n\tif (right === empty) {\n\t\treturn left;\n\t}\n\tif (right === dense) {\n\t\treturn empty;\n\t}\n\tif (left === dense) {\n\t\tconst res_inner = exceptUntypedProduct(\n\t\t\tright.productOperations,\n\t\t\tdense,\n\t\t\tright.root,\n\t\t\ttop(right.productOperations),\n\t\t);\n\t\tif (res_inner === empty) {\n\t\t\treturn res_inner;\n\t\t}\n\t\treturn sparseProduct(right.productOperations, res_inner);\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\tconst res = exceptUntypedProduct(\n\t\tproductOperations,\n\t\tleft.root,\n\t\tright.root,\n\t\ttop(productOperations),\n\t);\n\tif (res === empty) {\n\t\treturn res;\n\t}\n\treturn sparseProduct(productOperations, res);\n}\n\nfunction compareUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tboundingBox: Box<T>,\n): -1 | 0 | 1 | undefined {\n\tif (left === right) {\n\t\treturn 0;\n\t}\n\n\tif (left === empty) {\n\t\treturn -1;\n\t}\n\n\tif (right === empty) {\n\t\treturn 1;\n\t}\n\n\tif (left === dense) {\n\t\tif (right === dense) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif (right === dense) {\n\t\treturn -1;\n\t}\n\n\tif (left.isSubspace) {\n\t\tif (right.isSubspace) {\n\t\t\treturn compareSubspace(productOperations, left.bounds, right.bounds);\n\t\t}\n\t}\n\n\tconst [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\tconst leftCmp = compareUntypedProduct(productOperations, ll, rl, leftBox);\n\tif (leftCmp === undefined) {\n\t\treturn undefined;\n\t}\n\treturn combineCmp(leftCmp, compareUntypedProduct(productOperations, lr, rr, rightBox));\n}\n\nexport function compareProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n) {\n\tif (left === right) {\n\t\treturn 0;\n\t}\n\n\tif (left === empty) {\n\t\treturn -1;\n\t}\n\n\tif (right === empty) {\n\t\treturn 1;\n\t}\n\n\tif (left === dense) {\n\t\tif (right === dense) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif (right === dense) {\n\t\treturn -1;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\treturn compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nfunction meetsSubspace<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProduct<T>,\n\tright: UntypedProduct<T>,\n) {\n\tfor (const dimStr of Object.keys(productOperations)) {\n\t\tconst dim = dimStr as keyof T;\n\t\tif (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n\t\t\tconst lProj = toBspSet(left[dim]);\n\t\t\tconst rProj = toBspSet(right[dim]);\n\t\t\tconst setOperations = productOperations[dim];\n\t\t\tif (!meetsUntyped<unknown, unknown>(setOperations, lProj, rProj)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n}\n\nfunction meetsUntypedProduct<T>(\n\tproductOperations: ProductOperations<T>,\n\tleft: UntypedProductSet<T>,\n\tright: UntypedProductSet<T>,\n\tboundingBox: Box<T>,\n): boolean {\n\tif (left === empty || right === empty) {\n\t\treturn false;\n\t}\n\tif (left === dense || right === dense) {\n\t\treturn true;\n\t}\n\tif (!meetsSubspace(productOperations, left.bounds, right.bounds)) {\n\t\treturn false;\n\t}\n\tif (left.isSubspace && right.isSubspace) {\n\t\treturn true;\n\t}\n\n\tconst [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n\tconst [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n\tconst [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n\treturn (\n\t\tmeetsUntypedProduct(productOperations, ll, rl, leftBox) ||\n\t\tmeetsUntypedProduct(productOperations, lr, rr, rightBox)\n\t);\n}\n\nexport function meetsProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n\tleft: ProductSet<T>,\n\tright: ProductSet<U>,\n) {\n\tif (left === empty || right === empty) {\n\t\treturn false;\n\t}\n\tif (left === dense || right === dense) {\n\t\treturn true;\n\t}\n\n\tconst productOperations = { ...left.productOperations, ...right.productOperations };\n\treturn meetsUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nexport const complementProduct = <T>(set: ProductSet<T>) => exceptProduct(dense, set);\n\nexport const symmetricDiffProduct = <T>(left: ProductSet<T>, right: ProductSet<T>) =>\n\tunionProduct(exceptProduct(left, right), exceptProduct(right, left));\n\nexport function getSubspaces<T>(set: ProductSet<T>) {\n\tif (set === empty || set === dense) {\n\t\treturn [];\n\t}\n\tconst res: UntypedProduct<T>[] = [];\n\tfunction loop(root: UntypedSparseProduct<T>) {\n\t\tif (root.isSubspace) {\n\t\t\tres.push(root.bounds);\n\t\t\treturn;\n\t\t}\n\n\t\tloop(root.left);\n\t\tloop(root.right);\n\t}\n\n\tloop(set.root);\n\treturn res;\n}\n\nexport function forEachProduct<T, Props extends (keyof T)[]>(\n\tset: ProductSet<T>,\n\tf: (product: Product<Restrict<T, Props>>) => boolean,\n\t...dims: Props\n): boolean {\n\tconst newSet = project(set, ...dims);\n\tif (newSet === empty) {\n\t\treturn true;\n\t}\n\tif (newSet === dense) {\n\t\treturn f(unsafe.denseProduct(dims));\n\t}\n\n\tconst { productOperations, root } = newSet;\n\n\tfunction loop(root_inner: UntypedSparseProduct<T>): boolean {\n\t\tif (root_inner.isSubspace) {\n\t\t\treturn f(unsafe.fromUntypedProduct(productOperations, root_inner.bounds, dims));\n\t\t}\n\t\treturn loop(root_inner.left) && loop(root_inner.right);\n\t}\n\n\treturn loop(root);\n}\n\nexport function getSubspaceCount<T>(set: ProductSet<T>) {\n\tif (set === empty || set === dense) {\n\t\treturn 0;\n\t}\n\treturn getUntypedSubspaceCount(set.root);\n}\n"]}
@@ -11,12 +11,11 @@ export class VectorUndoProvider {
11
11
  this.driver = driver;
12
12
  }
13
13
  record(deltaArgs) {
14
- var _a, _b, _c, _d;
15
14
  if (deltaArgs.deltaSegments.length > 0) {
16
15
  // If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking
17
16
  // group so that we can preserve the original segment ranges as a single op/group as we move
18
17
  // ops between the undo <-> redo stacks.
19
- const revertibles = (_a = this.currentGroup) !== null && _a !== void 0 ? _a : [];
18
+ const revertibles = this.currentGroup ?? [];
20
19
  appendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);
21
20
  // For SharedMatrix, each IRevertibles always holds a single row/col operation.
22
21
  // Therefore, 'currentOp' must either be undefined or equal to the current op.
@@ -34,7 +33,7 @@ export class VectorUndoProvider {
34
33
  // so the new segment takes them over. there is no efficient look-up for this.
35
34
  // the tracking group provides one.
36
35
  const trackingGroup = (removeTrackingGroup =
37
- (_b = this.currentRemoveTrackingGroup) !== null && _b !== void 0 ? _b : new TrackingGroup());
36
+ this.currentRemoveTrackingGroup ?? new TrackingGroup());
38
37
  deltaArgs.deltaSegments.forEach((d) => d.segment.trackingCollection.link(trackingGroup));
39
38
  }
40
39
  switch (deltaArgs.operation) {
@@ -51,8 +50,8 @@ export class VectorUndoProvider {
51
50
  // another revertible until `IRevertable.revert()` finishes the current op and clears this
52
51
  // field.
53
52
  if (this.currentGroup !== undefined) {
54
- (_c = this.currentOp) !== null && _c !== void 0 ? _c : (this.currentOp = deltaArgs.operation);
55
- (_d = this.currentRemoveTrackingGroup) !== null && _d !== void 0 ? _d : (this.currentRemoveTrackingGroup = removeTrackingGroup);
53
+ this.currentOp ?? (this.currentOp = deltaArgs.operation);
54
+ this.currentRemoveTrackingGroup ?? (this.currentRemoveTrackingGroup = removeTrackingGroup);
56
55
  }
57
56
  }
58
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EACN,kBAAkB,EAGlB,iCAAiC,EAC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,EAAE;YAC5C,aAAa;gBACZ,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACpC,CAAC;YACD,cAAc,CAAC,GAAG,EAAE,IAAI;gBACvB,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,WAAW,CAAC,KAAK,EAAE,GAAG;gBACrB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;YACvC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,SAAiB,EAAE,QAAuB;QACpE,MAAM,CACL,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,EACpD,KAAK,CAAC,wDAAwD,CAC9D,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpC,MAAM,EAAE,GAAG,EAAE;oBACZ,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,6DAA6D;oBAC7D,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;wBAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tMergeTreeDeltaType,\n\tMergeTreeDeltaRevertible,\n\tIMergeTreeDeltaCallbackArgs,\n\tappendToMergeTreeDeltaRevertibles,\n\trevertMergeTreeDeltaRevertibles,\n\tMergeTreeRevertibleDriver,\n\tdiscardMergeTreeDeltaRevertible,\n\tTrackingGroup,\n\tITrackingGroup,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: MergeTreeDeltaRevertible[];\n\tprivate currentOp?: MergeTreeDeltaType;\n\tprivate currentRemoveTrackingGroup?: TrackingGroup;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly driver: MergeTreeRevertibleDriver,\n\t) {}\n\n\tpublic record(deltaArgs: IMergeTreeDeltaCallbackArgs) {\n\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst revertibles: MergeTreeDeltaRevertible[] = this.currentGroup ?? [];\n\t\t\tappendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === deltaArgs.operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\t\t\tlet removeTrackingGroup: TrackingGroup | undefined;\n\t\t\tif (deltaArgs.operation === MergeTreeDeltaType.REMOVE) {\n\t\t\t\t// for removed segment we need a tracking group.\n\t\t\t\t// this is for a few reason:\n\t\t\t\t// 1. the handle for the row/column on the removed segment is still allocated,\n\t\t\t\t//\t\tand needs to be in order to process unacked ops sent before the remove.\n\t\t\t\t// 2. handles are freed on unlink(zamboni), but that also clears the row/column data.\n\t\t\t\t//\t\twhich we don't want to happen, so we can re-insert the cells when the row/col comes back.\n\t\t\t\t//\t\tthe tracking group prevents unlink.\n\t\t\t\t// 3. when we re-insert we need to find the old segment and clear their handles\n\t\t\t\t//\t\tso the new segment takes them over. there is no efficient look-up for this.\n\t\t\t\t//\t\tthe tracking group provides one.\n\t\t\t\tconst trackingGroup = (removeTrackingGroup =\n\t\t\t\t\tthis.currentRemoveTrackingGroup ?? new TrackingGroup());\n\t\t\t\tdeltaArgs.deltaSegments.forEach((d) =>\n\t\t\t\t\td.segment.trackingCollection.link(trackingGroup),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tswitch (deltaArgs.operation) {\n\t\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== deltaArgs.operation) {\n\t\t\t\t\t\tthis.pushRevertible(revertibles, removeTrackingGroup);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp ??= deltaArgs.operation;\n\t\t\t\tthis.currentRemoveTrackingGroup ??= removeTrackingGroup;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\trevertibles: MergeTreeDeltaRevertible[],\n\t\tremovedTrackingGroup: ITrackingGroup | undefined,\n\t) {\n\t\tconst reverter = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = [];\n\n\t\t\t\ttry {\n\t\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\t\tconst tracked = removedTrackingGroup.tracked[0];\n\t\t\t\t\t\t\tremovedTrackingGroup.unlink(tracked);\n\t\t\t\t\t\t\t// if there are groups tracked, this in a revert of a remove.\n\t\t\t\t\t\t\t// this means we are about to re-insert the row/column\n\t\t\t\t\t\t\t// with the same handle. We reuse the handle so the row/columns cells\n\t\t\t\t\t\t\t// get re-inserted too.\n\t\t\t\t\t\t\t// since a new segment will have the handle, we need to\n\t\t\t\t\t\t\t// remove it from the removed segment which was tracked\n\t\t\t\t\t\t\t(tracked as PermutationSegment).reset();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trevertMergeTreeDeltaRevertibles(this.driver, revertibles);\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t\tthis.currentRemoveTrackingGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\tremovedTrackingGroup.unlink(removedTrackingGroup.tracked[0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdiscardMergeTreeDeltaRevertible(revertibles);\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(reverter);\n\n\t\treturn reverter;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveRows(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeRows(start, end - start);\n\t\t\t},\n\t\t});\n\t\tcols.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveCols(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeCols(start, end - start);\n\t\t\t},\n\t\t});\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EACN,kBAA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YAC5C,aAAa;gBACZ,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACpC,CAAC;YACD,cAAc,CAAC,GAAG,EAAE,IAAI;gBACvB,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,WAAW,CAAC,KAAK,EAAE,GAAG;gBACrB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;YACvC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,SAAiB,EAAE,QAAuB;QACpE,MAAM,CACL,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,EACpD,KAAK,CAAC,wDAAwD,CAC9D,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpC,MAAM,EAAE,GAAG,EAAE;oBACZ,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,6DAA6D;oBAC7D,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;wBAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tMergeTreeDeltaType,\n\tMergeTreeDeltaRevertible,\n\tIMergeTreeDeltaCallbackArgs,\n\tappendToMergeTreeDeltaRevertibles,\n\trevertMergeTreeDeltaRevertibles,\n\tMergeTreeRevertibleDriver,\n\tdiscardMergeTreeDeltaRevertible,\n\tTrackingGroup,\n\tITrackingGroup,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: MergeTreeDeltaRevertible[];\n\tprivate currentOp?: MergeTreeDeltaType;\n\tprivate currentRemoveTrackingGroup?: TrackingGroup;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly driver: MergeTreeRevertibleDriver,\n\t) {}\n\n\tpublic record(deltaArgs: IMergeTreeDeltaCallbackArgs) {\n\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst revertibles: MergeTreeDeltaRevertible[] = this.currentGroup ?? [];\n\t\t\tappendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === deltaArgs.operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\t\t\tlet removeTrackingGroup: TrackingGroup | undefined;\n\t\t\tif (deltaArgs.operation === MergeTreeDeltaType.REMOVE) {\n\t\t\t\t// for removed segment we need a tracking group.\n\t\t\t\t// this is for a few reason:\n\t\t\t\t// 1. the handle for the row/column on the removed segment is still allocated,\n\t\t\t\t//\t\tand needs to be in order to process unacked ops sent before the remove.\n\t\t\t\t// 2. handles are freed on unlink(zamboni), but that also clears the row/column data.\n\t\t\t\t//\t\twhich we don't want to happen, so we can re-insert the cells when the row/col comes back.\n\t\t\t\t//\t\tthe tracking group prevents unlink.\n\t\t\t\t// 3. when we re-insert we need to find the old segment and clear their handles\n\t\t\t\t//\t\tso the new segment takes them over. there is no efficient look-up for this.\n\t\t\t\t//\t\tthe tracking group provides one.\n\t\t\t\tconst trackingGroup = (removeTrackingGroup =\n\t\t\t\t\tthis.currentRemoveTrackingGroup ?? new TrackingGroup());\n\t\t\t\tdeltaArgs.deltaSegments.forEach((d) =>\n\t\t\t\t\td.segment.trackingCollection.link(trackingGroup),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tswitch (deltaArgs.operation) {\n\t\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== deltaArgs.operation) {\n\t\t\t\t\t\tthis.pushRevertible(revertibles, removeTrackingGroup);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp ??= deltaArgs.operation;\n\t\t\t\tthis.currentRemoveTrackingGroup ??= removeTrackingGroup;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\trevertibles: MergeTreeDeltaRevertible[],\n\t\tremovedTrackingGroup: ITrackingGroup | undefined,\n\t) {\n\t\tconst reverter = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = [];\n\n\t\t\t\ttry {\n\t\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\t\tconst tracked = removedTrackingGroup.tracked[0];\n\t\t\t\t\t\t\tremovedTrackingGroup.unlink(tracked);\n\t\t\t\t\t\t\t// if there are groups tracked, this in a revert of a remove.\n\t\t\t\t\t\t\t// this means we are about to re-insert the row/column\n\t\t\t\t\t\t\t// with the same handle. We reuse the handle so the row/columns cells\n\t\t\t\t\t\t\t// get re-inserted too.\n\t\t\t\t\t\t\t// since a new segment will have the handle, we need to\n\t\t\t\t\t\t\t// remove it from the removed segment which was tracked\n\t\t\t\t\t\t\t(tracked as PermutationSegment).reset();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trevertMergeTreeDeltaRevertibles(this.driver, revertibles);\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t\tthis.currentRemoveTrackingGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\tremovedTrackingGroup.unlink(removedTrackingGroup.tracked[0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdiscardMergeTreeDeltaRevertible(revertibles);\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(reverter);\n\n\t\treturn reverter;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveRows(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeRows(start, end - start);\n\t\t\t},\n\t\t});\n\t\tcols.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveCols(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeCols(start, end - start);\n\t\t\t},\n\t\t});\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}