@fluidframework/matrix 0.59.2001 → 0.59.3000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bspSet.d.ts +2 -2
- package/dist/bspSet.js +1 -1
- package/dist/bspSet.js.map +1 -1
- package/dist/handlecache.d.ts +1 -1
- package/dist/handlecache.js +4 -4
- package/dist/handlecache.js.map +1 -1
- package/dist/handletable.js.map +1 -1
- package/dist/matrix.d.ts +4 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +57 -22
- package/dist/matrix.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/permutationvector.js +10 -10
- package/dist/permutationvector.js.map +1 -1
- package/dist/productSet.js +10 -10
- package/dist/productSet.js.map +1 -1
- package/dist/range.d.ts +1 -1
- package/dist/range.js +1 -1
- package/dist/range.js.map +1 -1
- package/dist/serialization.js +1 -1
- package/dist/serialization.js.map +1 -1
- package/dist/undoprovider.d.ts.map +1 -1
- package/dist/undoprovider.js +3 -3
- package/dist/undoprovider.js.map +1 -1
- package/lib/bspSet.d.ts +2 -2
- package/lib/handlecache.d.ts +1 -1
- package/lib/handlecache.js +1 -1
- package/lib/handlecache.js.map +1 -1
- package/lib/handletable.js.map +1 -1
- package/lib/matrix.d.ts +4 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +39 -4
- package/lib/matrix.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/productSet.js.map +1 -1
- package/lib/range.d.ts +1 -1
- package/lib/range.js +1 -1
- package/lib/range.js.map +1 -1
- package/lib/undoprovider.d.ts.map +1 -1
- package/lib/undoprovider.js.map +1 -1
- package/package.json +16 -15
- package/src/handlecache.ts +1 -1
- package/src/matrix.ts +60 -13
- package/src/packageVersion.ts +1 -1
- package/src/productSet.ts +1 -1
- package/src/range.ts +1 -1
- package/src/undoprovider.ts +1 -1
package/lib/matrix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAQtD,OAAO,EAEH,uBAAuB,EACvB,YAAY,EACZ,YAAY,GAEf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAQ3F,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA2BpD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,YACT,SAAQ,YAAY;IAepB,YAAY,OAA+B,EAAS,EAAU,EAAE,UAA8B;QAC1F,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QADiB,OAAE,GAAF,EAAE,CAAQ;QAV7C,cAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;QAO/D,UAAK,GAAG,IAAI,aAAa,EAAiB,CAAC,CAAK,sBAAsB;QACtE,YAAO,GAAG,IAAI,aAAa,EAAU,CAAC,CAAU,yBAAyB;QAihBjF,sFAAsF;QACrE,eAAU,GAAG,CAAC,QAAgB,EAAE,YAAoB,EAAE,aAAqB,EAAE,EA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.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set,\n row: number,\n col: number,\n value: MatrixItem<T>,\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle,\n colHandle: Handle,\n localSeq: number,\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>>\n{\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<T>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAQtD,OAAO,EAEH,uBAAuB,EACvB,YAAY,EACZ,YAAY,GAEf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAQ3F,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA2BpD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,YACT,SAAQ,YAAY;IAcpB,YAAY,OAA+B,EAAS,EAAU,EAAE,UAA8B;QAC1F,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QADiB,OAAE,GAAF,EAAE,CAAQ;QAV7C,cAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;QAO/D,UAAK,GAAG,IAAI,aAAa,EAAiB,CAAC,CAAK,sBAAsB;QACtE,YAAO,GAAG,IAAI,aAAa,EAAU,CAAC,CAAU,yBAAyB;QAihBjF,sFAAsF;QACrE,eAAU,GAAG,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BACxB;gBAED,IAAI,CAAC,IAAI,CAAC,OAAO,CACb,SAAS,EACT,SAAS,EACT,QAAQ,CAAC,CAAC;aACjB;YAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAmB;gBAC7B,SAAS;gBACT,SAAS;gBACT,QAAQ;aACX,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC;CACJ","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 { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set;\n row: number;\n col: number;\n value: MatrixItem<T>;\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle;\n colHandle: Handle;\n localSeq: number;\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>> {\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<T>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg, local);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg, local);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n */\n protected applyStashedOp(content: any): unknown {\n if (content.target === SnapshotPath.cols || content.target === SnapshotPath.rows) {\n const op = content as IMergeTreeOp;\n const currentVector = content.target === SnapshotPath.cols ? this.cols : this.rows;\n const oppositeVector = content.target === SnapshotPath.cols ? this.rows : this.cols;\n const metadata = currentVector.applyStashedOp(op);\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n assert(\n localSeq > oppositeWindow.localSeq,\n 0x2d9,\n /* \"The 'localSeq' of the vector applying stashed op must > the 'localSeq' of the other vector.\" */\n );\n\n oppositeWindow.localSeq = localSeq;\n\n return metadata;\n } else {\n assert(content.type === MatrixOp.set, 0x2da /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<T>;\n const rowHandle = this.rows.getAllocatedHandle(setOp.row);\n const colHandle = this.cols.getAllocatedHandle(setOp.col);\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, setOp.value);\n const localSeq = this.nextLocalSeq();\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.pending.setCell(rowHandle, colHandle, localSeq);\n return metadata;\n }\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/matrix";
|
|
8
|
-
export declare const pkgVersion = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.3000";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.59.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.59.3000\";\n"]}
|
package/lib/productSet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"productSet.js","sourceRoot":"","sources":["../src/productSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;AAEH,OAAO,EAEH,KAAK,EACL,KAAK,EAGL,UAAU,EAEV,gBAAgB,EAChB,cAAc,EAGd,YAAY,EACZ,aAAa,EACb,IAAI,EAEJ,WAAW,EACX,YAAY,GAEf,MAAM,UAAU,CAAC;AA6DlB,MAAM,IAAI,GAAyC,EAAE,CAAC;AACtD,MAAM,GAAG,GAAG,CAAI,iBAAuC,EAAU,EAAE;IAC/D,MAAM,IAAI,GAAqD,EAAE,CAAC;IAClE,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;QACjD,MAAM,GAAG,GAAG,MAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC/C;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,OAAO,KAAK,SAAS,EAAE;QACvB,OAAO,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;KACzB;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,SAAS,QAAQ,CAAI,MAAyB;IAC1C,IAAI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C,IAAI,CAAC,CAAC;IACf,OAAO,GAAG,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAC1B,GAAkB,EAClB,CAAoD,EACpD,GAAG,IAAW;IAEd,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,IAAI,MAAM,KAAK,KAAK,EAAE;QAClB,OAAO,IAAI,CAAC;KACf;IACD,IAAI,MAAM,KAAK,KAAK,EAAE;QAClB,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;KACvC;IAED,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAE3C,SAAS,IAAI,CAAC,UAAmC;QAC7C,IAAI,UAAU,CAAC,UAAU,EAAE;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;SACnF;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,GAAkB;IAClD,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,CAAC;KACZ;IACD,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n BspSet,\n empty,\n dense,\n Empty,\n Dense,\n combineCmp,\n SetOperations,\n intersectUntyped,\n compareUntyped,\n Cachable,\n UntypedBspSet,\n unionUntyped,\n exceptUntyped,\n lazy,\n UntypedSparse,\n fromUntyped,\n meetsUntyped,\n Pair,\n} from \"./bspSet\";\n\ntype Restrict<T, Props extends (keyof T)[]> = { [Prop in Props[number]]: T[Prop] };\n\nexport type Product<T> = { readonly [dim in keyof T]: T[dim] extends BspSet<infer _TKey, infer _TId> ? T[dim] : never };\n\ntype UntypedProduct<T> = {\n readonly [dim in keyof T]?: T[dim] extends BspSet<infer TKey, infer _TId> ? UntypedSparse<TKey> : never;\n};\n\ntype Probabilities<T> = { readonly [dim in keyof T]?: number };\n\ntype ProductOperations<T> = {\n readonly [dim in keyof T]: T[dim] extends BspSet<infer TKey, infer TId> ? SetOperations<TKey, TId> : 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 readonly isSubspace: true;\n // isCoSubspace: boolean;\n readonly 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 readonly isSubspace: false;\n // readonly isCoSubspace: false;\n readonly left: UntypedSparseProduct<T>;\n readonly right: UntypedSparseProduct<T>;\n readonly bounds: UntypedProduct<T>;\n readonly subspaceCount: number;\n}\n\ntype UntypedSparseProduct<T> = Subspace<T> | Union<T>; // | CoSubspace<T>;\n\ninterface SparseProduct<T> {\n readonly productOperations: ProductOperations<T>;\n readonly root: UntypedSparseProduct<T>;\n}\n\ninterface Box<T> {\n box: UntypedProduct<T>;\n probabilities: Probabilities<T>;\n children?: Pair<Box<T>>;\n depth: number;\n}\n\nconst tops: { [poKey in string]?: Box<unknown> } = {};\nconst top = <T>(productOperations: ProductOperations<T>): Box<T> => {\n const dims: [keyof T, ProductOperations<T>[keyof T][\"id\"]][] = [];\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n dims.push([dim, productOperations[dim].id]);\n }\n\n const poKey = JSON.stringify(dims.sort());\n let currTop = tops[poKey];\n if (currTop === undefined) {\n currTop = { box: {}, probabilities: {}, depth: 1 };\n tops[poKey] = currTop;\n }\n\n return currTop;\n};\n\nfunction subspace<T>(bounds: UntypedProduct<T>): Subspace<T> | Dense {\n let isDense = true;\n for (const dim of Object.keys(bounds)) {\n if (Object.prototype.hasOwnProperty.call(bounds, dim)) {\n isDense = false;\n break;\n }\n }\n if (isDense) {\n return dense;\n }\n return { isSubspace: true as const, bounds };\n}\n\nfunction getUntypedSubspaceCount<T>(set: UntypedSparseProduct<T>) {\n if (set.isSubspace) {\n return 1;\n }\n return set.subspaceCount;\n}\n\nconst union = <T>(\n left: UntypedSparseProduct<T>,\n right: UntypedSparseProduct<T>,\n bounds: UntypedProduct<T>,\n): Union<T> => ({\n isSubspace: false as const,\n left,\n right,\n bounds,\n subspaceCount: getUntypedSubspaceCount(left) + getUntypedSubspaceCount(right),\n});\n\nfunction sparseProduct<T>(\n productOperations: ProductOperations<T>,\n root: UntypedSparseProduct<T> | Dense,\n): SparseProduct<T> | Dense {\n if (root === dense) {\n return root;\n }\n if (root.isSubspace) {\n let hasSparseDimensions = false;\n for (const dim of Object.keys(root.bounds)) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n hasSparseDimensions = true;\n break;\n }\n }\n if (!hasSparseDimensions) {\n return dense;\n }\n }\n return { 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 if (set === undefined) {\n return dense;\n }\n return 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 unzip<T>(product: Product<T>): ProductSet<T> {\n const productOperations: { [dim in keyof T]?: SetOperations<unknown, unknown> } = {};\n const root: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n for (const dimStr of Object.keys(product)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(product, dim)) {\n const set: BspSet<unknown, unknown> = product[dim];\n if (set === empty) {\n return empty;\n }\n if (set === dense) {\n continue;\n }\n\n productOperations[dim] = set.setOperations;\n root[dim] = set.root;\n }\n }\n\n return sparseProduct(productOperations as ProductOperations<T>, subspace(root as UntypedProduct<T>));\n },\n\n combineProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProduct<T>,\n right: UntypedProduct<T>,\n combineFunc: <Key extends Cachable<Key>, Id>(\n setOperations: SetOperations<Key, Id>,\n left: UntypedBspSet<Key>,\n right: UntypedBspSet<Key>\n ) => UntypedBspSet<Key>,\n ) {\n const res: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const combined = combineFunc<unknown, unknown>(\n productOperations[dim],\n toBspSet(left[dim]),\n toBspSet(right[dim]),\n );\n if (combined === empty) {\n return combined;\n }\n if (combined === dense) {\n continue;\n }\n res[dim] = combined;\n }\n }\n\n return res as UntypedProduct<T>;\n },\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n restrict<T extends object, Props extends (keyof T)[]>(object: T, ...props: Props) {\n const res: Partial<Restrict<T, Props>> = {};\n for (const key of props) {\n if (Object.prototype.hasOwnProperty.call(object, key)) {\n const prop = object[key];\n res[key] = prop;\n }\n }\n\n return res as Restrict<T, Props>;\n },\n\n fromUntypedProduct<T, Props extends (keyof T)[]>(\n productOperations: ProductOperations<Restrict<T, Props>>,\n bounds: UntypedProduct<Restrict<T, Props>>,\n dims: Props,\n ) {\n const product: { [dim in Props[number]]?: BspSet<unknown, unknown> } = {};\n for (const dim of dims) {\n const bound: UntypedSparse<unknown> | undefined = bounds[dim];\n product[dim] = fromUntyped(productOperations[dim], bound !== undefined ? bound : dense);\n }\n return product as Product<Restrict<T, Props>>;\n },\n\n denseProduct<T, Props extends (keyof T)[]>(dims: Props): Product<Restrict<T, Props>> {\n const top_inner: { [dim in Props[number]]?: Dense } = {};\n for (const dim of dims) {\n top_inner[dim] = dense;\n }\n return top_inner as Product<Restrict<T, Props>>;\n },\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>(productOperations: ProductOperations<T>, left: UntypedProduct<T>, right: UntypedProduct<T>) {\n const join = unsafe.combineProduct(productOperations, left, right, unionUntyped);\n if (join === empty) {\n throw new Error(\"broken invariant: the union of two non-empty products cannot be empty\");\n }\n\n return join;\n}\n\nfunction compareSubspace<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProduct<T>,\n right: UntypedProduct<T>,\n) {\n let cmp: ReturnType<typeof combineCmp> = 0;\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const lProj = toBspSet(left[dim]);\n const rProj = toBspSet(right[dim]);\n const setOperations = productOperations[dim];\n\n cmp = combineCmp(cmp, compareUntyped<unknown, unknown>(setOperations, lProj, rProj));\n\n if (cmp === undefined) {\n return undefined;\n }\n }\n }\n\n return cmp;\n}\n\nconst tryUnionSubspaces = (() => {\n const cache: { left?: unknown; right?: unknown; res?: unknown } = {};\n return <T>(\n productOperations: ProductOperations<T>,\n left: Subspace<T>,\n right: Subspace<T>,\n ): Subspace<T> | Dense | Empty | undefined => {\n if (left === cache.left && right === cache.right) {\n return cache.res as ReturnType<typeof tryUnionSubspaces>;\n }\n cache.left = left;\n cache.right = right;\n\n const cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n if (cmp !== undefined) {\n return (cache.res = cmp <= 0 ? right : left);\n }\n let differentDimension: keyof T | undefined;\n\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const cmp_inner = compareUntyped<unknown, unknown>(\n productOperations[dim],\n toBspSet(left.bounds[dim]),\n toBspSet(right.bounds[dim]),\n );\n if (cmp_inner !== 0) {\n if (differentDimension !== undefined) {\n return (cache.res = undefined);\n }\n\n differentDimension = dim;\n }\n }\n }\n\n if (differentDimension !== undefined) {\n const newDim = unionUntyped<unknown, unknown>(\n productOperations[differentDimension],\n toBspSet(left.bounds[differentDimension]),\n toBspSet(right.bounds[differentDimension]),\n );\n if (newDim === empty) {\n return (cache.res = empty);\n }\n if (newDim === dense) {\n // we are actually deleting the `differentDimension`, so the variable\n // `deleted` must be there. Hence disabling the rule here.\n const { [differentDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;\n return (cache.res = subspace<unknown>(leftBoundsWithoutDifferentDimension));\n }\n\n const newBounds: UntypedProduct<T> = {\n ...left.bounds,\n [differentDimension]: newDim,\n };\n return (cache.res = subspace(newBounds));\n }\n\n return (cache.res = undefined);\n };\n})();\n\nfunction combineChildren<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n): UntypedProductSet<T> {\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n\n if (!left.isSubspace || !right.isSubspace) {\n return union<T>(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n }\n\n const combinedSubspace = tryUnionSubspaces<T>(productOperations, left, right);\n\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n return union(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n}\n\nfunction projectUntyped<T, Props extends (keyof T)[]>(\n productOperations: ProductOperations<T>,\n set: UntypedSparseProduct<T>,\n ...dims: Props\n): UntypedProductSet<Restrict<T, Props>> {\n const bounds = unsafe.restrict(set.bounds, ...dims);\n if (set.isSubspace) {\n return subspace(bounds);\n }\n\n const lChild = projectUntyped(productOperations, set.left, ...dims);\n if (lChild === dense) {\n return dense;\n }\n const rChild = projectUntyped(productOperations, set.right, ...dims);\n return combineChildren(productOperations, lChild, rChild);\n}\n\nexport function project<T, Props extends (keyof T)[]>(\n set: ProductSet<T>,\n ...dims: Props\n): ProductSet<Restrict<T, Props>> {\n if (set === dense || set === empty) {\n return set;\n }\n const productOperations = unsafe.restrict(set.productOperations, ...dims);\n const root = projectUntyped(productOperations, set.root, ...dims);\n if (root === empty) {\n return root;\n }\n return sparseProduct(productOperations, root);\n}\n\nfunction splitBox<T>(productOperations: ProductOperations<T>, currentBox: Box<T>): Pair<Box<T>> {\n if (currentBox.children !== undefined) { return currentBox.children; }\n const { box, probabilities } = currentBox;\n let biggestDim: keyof T | undefined;\n let biggestDimKey;\n let currentProb = 0;\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const prob: number | undefined = probabilities[dim];\n const setOperations_inner = productOperations[dim];\n if (prob === undefined) {\n biggestDim = dim;\n biggestDimKey = setOperations_inner.top;\n break;\n }\n\n if (prob > currentProb) {\n const dimensionSet = toBspSet(box[dim]);\n if (dimensionSet === empty) {\n throw new Error(\"the key split can never return empty\");\n }\n let key = setOperations_inner.top;\n if (dimensionSet !== dense) {\n if (!dimensionSet.isExact) {\n throw new Error(\"the key can always be represented exactly\");\n }\n\n key = dimensionSet.key;\n }\n if (!setOperations_inner.canSplit(key)) {\n continue;\n }\n biggestDim = dim;\n currentProb = prob;\n biggestDimKey = key;\n }\n }\n }\n\n if (biggestDim === undefined || biggestDimKey === undefined) {\n throw new Error(\"there has to be at least one dimension\");\n }\n\n const setOperations = productOperations[biggestDim];\n\n const [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);\n const res: ReturnType<typeof splitBox> = [\n {\n box: { ...box, [biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, leftDim) },\n probabilities: { ...probabilities, [biggestDim]: leftProb },\n depth: currentBox.depth + 1,\n },\n {\n box: { ...box, [biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, rightDim) },\n probabilities: { ...probabilities, [biggestDim]: rightProb },\n depth: currentBox.depth + 1,\n },\n ];\n if (currentBox.depth < 10) {\n currentBox.children = res;\n }\n return res;\n}\n\nfunction restrictByBounds<T>(\n productOperations: ProductOperations<T>,\n set: UntypedProductSet<T>,\n leftBounds: UntypedProduct<T>,\n rightBounds: UntypedProduct<T>,\n): Pair<UntypedProductSet<T>> {\n if (set === empty) {\n return [empty, empty];\n }\n if (set === dense) {\n return [subspace(leftBounds), subspace(rightBounds)];\n }\n const cmp = compareSubspace(productOperations, set.bounds, leftBounds);\n\n // the set is fully contained in the left half, i.e. we know the pair.\n if (cmp !== undefined && cmp <= 0) {\n return [set, empty];\n }\n\n const newLeftBounds = unsafe.combineProduct(productOperations, set.bounds, leftBounds, intersectUntyped);\n\n // if we know, that the left set is completely empty, then the whole set is in the right bounds.\n if (newLeftBounds === empty) {\n return [empty, set];\n }\n\n const newRightBounds = unsafe.combineProduct(productOperations, set.bounds, rightBounds, intersectUntyped);\n if (set.isSubspace) {\n return [subspace(newLeftBounds), newRightBounds === empty ? empty : subspace(newRightBounds)];\n }\n\n const [ll, lr] = restrictByBounds(productOperations, set.left, leftBounds, rightBounds);\n const [rl, rr] = restrictByBounds(productOperations, set.right, leftBounds, rightBounds);\n return [combineChildren(productOperations, ll, rl), combineChildren(productOperations, lr, rr)];\n}\n\nconst splitByBox = <T>(\n productOperations: ProductOperations<T>,\n set: UntypedProductSet<T>,\n { box: leftBounds }: Box<T>,\n { box: rightBounds }: Box<T>,\n): Pair<UntypedProductSet<T>, UntypedProductSet<T>> => {\n return restrictByBounds(productOperations, set, leftBounds, rightBounds);\n};\n\nfunction recurse<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n visitFunc: (\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n box: Box<T>\n ) => UntypedProductSet<T>,\n) {\n const [leftBox, rightBox] = splitBox(productOperations, currentBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n const lChild = visitFunc(productOperations, ll, rl, leftBox);\n if (lChild === dense) {\n return dense;\n }\n const rChild = visitFunc(productOperations, lr, rr, rightBox);\n return combineChildren(productOperations, lChild, rChild);\n}\n\nfunction unionUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (right === empty) {\n return left;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left.isSubspace && right.isSubspace) {\n const combinedSubspace = tryUnionSubspaces(productOperations, left, right);\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n }\n\n return recurse(productOperations, left, right, currentBox, unionUntypedProduct);\n}\n\nexport function unionProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = unionUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction intersectUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (left === empty || right === empty) {\n return empty;\n }\n if (left === dense) {\n return right;\n }\n if (right === dense) {\n return left;\n }\n if (left.isSubspace && right.isSubspace) {\n const res = unsafe.combineProduct(productOperations, left.bounds, right.bounds, intersectUntyped);\n if (res === empty) {\n return empty;\n }\n return subspace(res);\n }\n\n return recurse(productOperations, left, right, currentBox, intersectUntypedProduct);\n}\n\nexport function intersectProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (left === empty) {\n return left;\n }\n if (right === empty) {\n return right;\n }\n if (left === dense) {\n return right;\n }\n if (right === dense) {\n return left;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = intersectUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction tryExceptSubspaces<T>(\n productOperations: ProductOperations<T>,\n left: Subspace<T>,\n right: Subspace<T>,\n): Subspace<T> | Dense | Empty | undefined {\n const cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n if (cmp === 0 || cmp === -1) {\n return empty;\n }\n let notContainedDimension: keyof T | undefined;\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const cmp_inner = compareUntyped<unknown, unknown>(\n productOperations[dim],\n toBspSet(left.bounds[dim]),\n toBspSet(right.bounds[dim]),\n );\n if (cmp_inner === undefined || cmp_inner > 0) {\n if (notContainedDimension !== undefined) {\n return undefined;\n }\n\n notContainedDimension = dim;\n }\n }\n }\n\n if (notContainedDimension !== undefined) {\n const newDim = exceptUntyped<unknown, unknown>(\n productOperations[notContainedDimension],\n toBspSet(left.bounds[notContainedDimension]),\n toBspSet(right.bounds[notContainedDimension]),\n );\n\n if (newDim === empty) {\n return empty;\n }\n if (newDim === dense) {\n // we are actually deleting the `differentDimension`, so the variable\n // `deleted` must be there. Hence disabling the rule here.\n const { [notContainedDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;\n return subspace<unknown>(leftBoundsWithoutDifferentDimension);\n }\n const newBounds: UntypedProduct<T> = {\n ...left.bounds,\n [notContainedDimension]: newDim,\n };\n return subspace(newBounds);\n }\n\n return undefined;\n}\n\nfunction exceptUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (left === empty) {\n return left;\n }\n if (right === dense) {\n return empty;\n }\n if (right === empty) {\n return left;\n }\n\n if (left === dense) {\n return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n }\n\n if (left.isSubspace && right.isSubspace) {\n const combinedSubspace = tryExceptSubspaces(productOperations, left, right);\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n }\n\n return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n}\n\nexport function exceptProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (left === empty) {\n return left;\n }\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return empty;\n }\n if (left === dense) {\n const res_inner =\n exceptUntypedProduct(right.productOperations, dense, right.root, top(right.productOperations));\n if (res_inner === empty) {\n return res_inner;\n }\n return sparseProduct(right.productOperations, res_inner);\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = exceptUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction compareUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n boundingBox: Box<T>,\n): -1 | 0 | 1 | undefined {\n if (left === right) {\n return 0;\n }\n\n if (left === empty) {\n return -1;\n }\n\n if (right === empty) {\n return 1;\n }\n\n if (left === dense) {\n if (right === dense) {\n return 0;\n }\n\n return 1;\n }\n\n if (right === dense) {\n return -1;\n }\n\n if (left.isSubspace) {\n if (right.isSubspace) {\n return compareSubspace(productOperations, left.bounds, right.bounds);\n }\n }\n\n const [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n const leftCmp = compareUntypedProduct(productOperations, ll, rl, leftBox);\n if (leftCmp === undefined) {\n return undefined;\n }\n return combineCmp(leftCmp, compareUntypedProduct(productOperations, lr, rr, rightBox));\n}\n\nexport function compareProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n) {\n if (left === right) {\n return 0;\n }\n\n if (left === empty) {\n return -1;\n }\n\n if (right === empty) {\n return 1;\n }\n\n if (left === dense) {\n if (right === dense) {\n return 0;\n }\n\n return 1;\n }\n\n if (right === dense) {\n return -1;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n return compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nfunction meetsSubspace<T>(productOperations: ProductOperations<T>, left: UntypedProduct<T>, right: UntypedProduct<T>) {\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const lProj = toBspSet(left[dim]);\n const rProj = toBspSet(right[dim]);\n const setOperations = productOperations[dim];\n if (!meetsUntyped<unknown, unknown>(setOperations, lProj, rProj)) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction meetsUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n boundingBox: Box<T>,\n): boolean {\n if (left === empty || right === empty) {\n return false;\n }\n if (left === dense || right === dense) {\n return true;\n }\n if (!meetsSubspace(productOperations, left.bounds, right.bounds)) {\n return false;\n }\n if (left.isSubspace && right.isSubspace) {\n return true;\n }\n\n const [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n return (\n meetsUntypedProduct(productOperations, ll, rl, leftBox)\n || meetsUntypedProduct(productOperations, lr, rr, rightBox)\n );\n}\n\nexport function meetsProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n) {\n if (left === empty || right === empty) {\n return false;\n }\n if (left === dense || right === dense) {\n return true;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n return 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 unionProduct(exceptProduct(left, right), exceptProduct(right, left));\n\nexport function getSubspaces<T>(set: ProductSet<T>) {\n if (set === empty || set === dense) {\n return [];\n }\n const res: UntypedProduct<T>[] = [];\n function loop(root: UntypedSparseProduct<T>) {\n if (root.isSubspace) {\n res.push(root.bounds);\n return;\n }\n\n loop(root.left);\n loop(root.right);\n }\n\n loop(set.root);\n return res;\n}\n\nexport function forEachProduct<T, Props extends (keyof T)[]>(\n set: ProductSet<T>,\n f: (product: Product<Restrict<T, Props>>) => boolean,\n ...dims: Props\n): boolean {\n const newSet = project(set, ...dims);\n if (newSet === empty) {\n return true;\n }\n if (newSet === dense) {\n return f(unsafe.denseProduct(dims));\n }\n\n const { productOperations, root } = newSet;\n\n function loop(root_inner: UntypedSparseProduct<T>): boolean {\n if (root_inner.isSubspace) {\n return f(unsafe.fromUntypedProduct(productOperations, root_inner.bounds, dims));\n }\n return loop(root_inner.left) && loop(root_inner.right);\n }\n\n return loop(root);\n}\n\nexport function getSubspaceCount<T>(set: ProductSet<T>) {\n if (set === empty || set === dense) {\n return 0;\n }\n return getUntypedSubspaceCount(set.root);\n}\n"]}
|
|
1
|
+
{"version":3,"file":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AAE;QAClB,OAAO,IAAI,CAAC;KACf;IACD,IAAI,MAAM,KAAK,KAAK,EAAE;QAClB,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;KACvC;IAED,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAE3C,SAAS,IAAI,CAAC,UAAmC;QAC7C,IAAI,UAAU,CAAC,UAAU,EAAE;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;SACnF;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,GAAkB;IAClD,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,CAAC;KACZ;IACD,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n BspSet,\n empty,\n dense,\n Empty,\n Dense,\n combineCmp,\n SetOperations,\n intersectUntyped,\n compareUntyped,\n Cachable,\n UntypedBspSet,\n unionUntyped,\n exceptUntyped,\n lazy,\n UntypedSparse,\n fromUntyped,\n meetsUntyped,\n Pair,\n} from \"./bspSet\";\n\ntype Restrict<T, Props extends (keyof T)[]> = { [Prop in Props[number]]: T[Prop] };\n\nexport type Product<T> = { readonly [dim in keyof T]: T[dim] extends BspSet<infer _TKey, infer _TId> ? T[dim] : never };\n\ntype UntypedProduct<T> = {\n readonly [dim in keyof T]?: T[dim] extends BspSet<infer TKey, infer _TId> ? UntypedSparse<TKey> : never;\n};\n\ntype Probabilities<T> = { readonly [dim in keyof T]?: number };\n\ntype ProductOperations<T> = {\n readonly [dim in keyof T]: T[dim] extends BspSet<infer TKey, infer TId> ? SetOperations<TKey, TId> : 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 readonly isSubspace: true;\n // isCoSubspace: boolean;\n readonly 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 readonly isSubspace: false;\n // readonly isCoSubspace: false;\n readonly left: UntypedSparseProduct<T>;\n readonly right: UntypedSparseProduct<T>;\n readonly bounds: UntypedProduct<T>;\n readonly subspaceCount: number;\n}\n\ntype UntypedSparseProduct<T> = Subspace<T> | Union<T>; // | CoSubspace<T>;\n\ninterface SparseProduct<T> {\n readonly productOperations: ProductOperations<T>;\n readonly root: UntypedSparseProduct<T>;\n}\n\ninterface Box<T> {\n box: UntypedProduct<T>;\n probabilities: Probabilities<T>;\n children?: Pair<Box<T>>;\n depth: number;\n}\n\nconst tops: { [poKey in string]?: Box<unknown> } = {};\nconst top = <T>(productOperations: ProductOperations<T>): Box<T> => {\n const dims: [keyof T, ProductOperations<T>[keyof T][\"id\"]][] = [];\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n dims.push([dim, productOperations[dim].id]);\n }\n\n const poKey = JSON.stringify(dims.sort());\n let currTop = tops[poKey];\n if (currTop === undefined) {\n currTop = { box: {}, probabilities: {}, depth: 1 };\n tops[poKey] = currTop;\n }\n\n return currTop;\n};\n\nfunction subspace<T>(bounds: UntypedProduct<T>): Subspace<T> | Dense {\n let isDense = true;\n for (const dim of Object.keys(bounds)) {\n if (Object.prototype.hasOwnProperty.call(bounds, dim)) {\n isDense = false;\n break;\n }\n }\n if (isDense) {\n return dense;\n }\n return { isSubspace: true as const, bounds };\n}\n\nfunction getUntypedSubspaceCount<T>(set: UntypedSparseProduct<T>) {\n if (set.isSubspace) {\n return 1;\n }\n return set.subspaceCount;\n}\n\nconst union = <T>(\n left: UntypedSparseProduct<T>,\n right: UntypedSparseProduct<T>,\n bounds: UntypedProduct<T>,\n): Union<T> => ({\n isSubspace: false as const,\n left,\n right,\n bounds,\n subspaceCount: getUntypedSubspaceCount(left) + getUntypedSubspaceCount(right),\n});\n\nfunction sparseProduct<T>(\n productOperations: ProductOperations<T>,\n root: UntypedSparseProduct<T> | Dense,\n): SparseProduct<T> | Dense {\n if (root === dense) {\n return root;\n }\n if (root.isSubspace) {\n let hasSparseDimensions = false;\n for (const dim of Object.keys(root.bounds)) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n hasSparseDimensions = true;\n break;\n }\n }\n if (!hasSparseDimensions) {\n return dense;\n }\n }\n return { 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 if (set === undefined) {\n return dense;\n }\n return 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 unzip<T>(product: Product<T>): ProductSet<T> {\n const productOperations: { [dim in keyof T]?: SetOperations<unknown, unknown> } = {};\n const root: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n for (const dimStr of Object.keys(product)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(product, dim)) {\n const set: BspSet<unknown, unknown> = product[dim];\n if (set === empty) {\n return empty;\n }\n if (set === dense) {\n continue;\n }\n\n productOperations[dim] = set.setOperations;\n root[dim] = set.root;\n }\n }\n\n return sparseProduct(productOperations as ProductOperations<T>, subspace(root as UntypedProduct<T>));\n },\n\n combineProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProduct<T>,\n right: UntypedProduct<T>,\n combineFunc: <Key extends Cachable<Key>, Id>(\n setOperations: SetOperations<Key, Id>,\n left: UntypedBspSet<Key>,\n right: UntypedBspSet<Key>\n ) => UntypedBspSet<Key>,\n ) {\n const res: { [dim in keyof T]?: UntypedSparse<unknown> } = {};\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const combined = combineFunc<unknown, unknown>(\n productOperations[dim],\n toBspSet(left[dim]),\n toBspSet(right[dim]),\n );\n if (combined === empty) {\n return combined;\n }\n if (combined === dense) {\n continue;\n }\n res[dim] = combined;\n }\n }\n\n return res as UntypedProduct<T>;\n },\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n restrict<T extends object, Props extends (keyof T)[]>(object: T, ...props: Props) {\n const res: Partial<Restrict<T, Props>> = {};\n for (const key of props) {\n if (Object.prototype.hasOwnProperty.call(object, key)) {\n const prop = object[key];\n res[key] = prop;\n }\n }\n\n return res as Restrict<T, Props>;\n },\n\n fromUntypedProduct<T, Props extends (keyof T)[]>(\n productOperations: ProductOperations<Restrict<T, Props>>,\n bounds: UntypedProduct<Restrict<T, Props>>,\n dims: Props,\n ) {\n const product: { [dim in Props[number]]?: BspSet<unknown, unknown> } = {};\n for (const dim of dims) {\n const bound: UntypedSparse<unknown> | undefined = bounds[dim];\n product[dim] = fromUntyped(productOperations[dim], bound !== undefined ? bound : dense);\n }\n return product as Product<Restrict<T, Props>>;\n },\n\n denseProduct<T, Props extends (keyof T)[]>(dims: Props): Product<Restrict<T, Props>> {\n const top_inner: { [dim in Props[number]]?: Dense } = {};\n for (const dim of dims) {\n top_inner[dim] = dense;\n }\n return top_inner as Product<Restrict<T, Props>>;\n },\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>(productOperations: ProductOperations<T>, left: UntypedProduct<T>, right: UntypedProduct<T>) {\n const join = unsafe.combineProduct(productOperations, left, right, unionUntyped);\n if (join === empty) {\n throw new Error(\"broken invariant: the union of two non-empty products cannot be empty\");\n }\n\n return join;\n}\n\nfunction compareSubspace<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProduct<T>,\n right: UntypedProduct<T>,\n) {\n let cmp: ReturnType<typeof combineCmp> = 0;\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const lProj = toBspSet(left[dim]);\n const rProj = toBspSet(right[dim]);\n const setOperations = productOperations[dim];\n\n cmp = combineCmp(cmp, compareUntyped<unknown, unknown>(setOperations, lProj, rProj));\n\n if (cmp === undefined) {\n return undefined;\n }\n }\n }\n\n return cmp;\n}\n\nconst tryUnionSubspaces = (() => {\n const cache: { left?: unknown; right?: unknown; res?: unknown; } = {};\n return <T>(\n productOperations: ProductOperations<T>,\n left: Subspace<T>,\n right: Subspace<T>,\n ): Subspace<T> | Dense | Empty | undefined => {\n if (left === cache.left && right === cache.right) {\n return cache.res as ReturnType<typeof tryUnionSubspaces>;\n }\n cache.left = left;\n cache.right = right;\n\n const cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n if (cmp !== undefined) {\n return (cache.res = cmp <= 0 ? right : left);\n }\n let differentDimension: keyof T | undefined;\n\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const cmp_inner = compareUntyped<unknown, unknown>(\n productOperations[dim],\n toBspSet(left.bounds[dim]),\n toBspSet(right.bounds[dim]),\n );\n if (cmp_inner !== 0) {\n if (differentDimension !== undefined) {\n return (cache.res = undefined);\n }\n\n differentDimension = dim;\n }\n }\n }\n\n if (differentDimension !== undefined) {\n const newDim = unionUntyped<unknown, unknown>(\n productOperations[differentDimension],\n toBspSet(left.bounds[differentDimension]),\n toBspSet(right.bounds[differentDimension]),\n );\n if (newDim === empty) {\n return (cache.res = empty);\n }\n if (newDim === dense) {\n // we are actually deleting the `differentDimension`, so the variable\n // `deleted` must be there. Hence disabling the rule here.\n const { [differentDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;\n return (cache.res = subspace<unknown>(leftBoundsWithoutDifferentDimension));\n }\n\n const newBounds: UntypedProduct<T> = {\n ...left.bounds,\n [differentDimension]: newDim,\n };\n return (cache.res = subspace(newBounds));\n }\n\n return (cache.res = undefined);\n };\n})();\n\nfunction combineChildren<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n): UntypedProductSet<T> {\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n\n if (!left.isSubspace || !right.isSubspace) {\n return union<T>(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n }\n\n const combinedSubspace = tryUnionSubspaces<T>(productOperations, left, right);\n\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n return union(left, right, joinBounds(productOperations, left.bounds, right.bounds));\n}\n\nfunction projectUntyped<T, Props extends (keyof T)[]>(\n productOperations: ProductOperations<T>,\n set: UntypedSparseProduct<T>,\n ...dims: Props\n): UntypedProductSet<Restrict<T, Props>> {\n const bounds = unsafe.restrict(set.bounds, ...dims);\n if (set.isSubspace) {\n return subspace(bounds);\n }\n\n const lChild = projectUntyped(productOperations, set.left, ...dims);\n if (lChild === dense) {\n return dense;\n }\n const rChild = projectUntyped(productOperations, set.right, ...dims);\n return combineChildren(productOperations, lChild, rChild);\n}\n\nexport function project<T, Props extends (keyof T)[]>(\n set: ProductSet<T>,\n ...dims: Props\n): ProductSet<Restrict<T, Props>> {\n if (set === dense || set === empty) {\n return set;\n }\n const productOperations = unsafe.restrict(set.productOperations, ...dims);\n const root = projectUntyped(productOperations, set.root, ...dims);\n if (root === empty) {\n return root;\n }\n return sparseProduct(productOperations, root);\n}\n\nfunction splitBox<T>(productOperations: ProductOperations<T>, currentBox: Box<T>): Pair<Box<T>> {\n if (currentBox.children !== undefined) { return currentBox.children; }\n const { box, probabilities } = currentBox;\n let biggestDim: keyof T | undefined;\n let biggestDimKey;\n let currentProb = 0;\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const prob: number | undefined = probabilities[dim];\n const setOperations_inner = productOperations[dim];\n if (prob === undefined) {\n biggestDim = dim;\n biggestDimKey = setOperations_inner.top;\n break;\n }\n\n if (prob > currentProb) {\n const dimensionSet = toBspSet(box[dim]);\n if (dimensionSet === empty) {\n throw new Error(\"the key split can never return empty\");\n }\n let key = setOperations_inner.top;\n if (dimensionSet !== dense) {\n if (!dimensionSet.isExact) {\n throw new Error(\"the key can always be represented exactly\");\n }\n\n key = dimensionSet.key;\n }\n if (!setOperations_inner.canSplit(key)) {\n continue;\n }\n biggestDim = dim;\n currentProb = prob;\n biggestDimKey = key;\n }\n }\n }\n\n if (biggestDim === undefined || biggestDimKey === undefined) {\n throw new Error(\"there has to be at least one dimension\");\n }\n\n const setOperations = productOperations[biggestDim];\n\n const [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);\n const res: ReturnType<typeof splitBox> = [\n {\n box: { ...box, [biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, leftDim) },\n probabilities: { ...probabilities, [biggestDim]: leftProb },\n depth: currentBox.depth + 1,\n },\n {\n box: { ...box, [biggestDim]: lazy<unknown, unknown>(setOperations, setOperations.top, rightDim) },\n probabilities: { ...probabilities, [biggestDim]: rightProb },\n depth: currentBox.depth + 1,\n },\n ];\n if (currentBox.depth < 10) {\n currentBox.children = res;\n }\n return res;\n}\n\nfunction restrictByBounds<T>(\n productOperations: ProductOperations<T>,\n set: UntypedProductSet<T>,\n leftBounds: UntypedProduct<T>,\n rightBounds: UntypedProduct<T>,\n): Pair<UntypedProductSet<T>> {\n if (set === empty) {\n return [empty, empty];\n }\n if (set === dense) {\n return [subspace(leftBounds), subspace(rightBounds)];\n }\n const cmp = compareSubspace(productOperations, set.bounds, leftBounds);\n\n // the set is fully contained in the left half, i.e. we know the pair.\n if (cmp !== undefined && cmp <= 0) {\n return [set, empty];\n }\n\n const newLeftBounds = unsafe.combineProduct(productOperations, set.bounds, leftBounds, intersectUntyped);\n\n // if we know, that the left set is completely empty, then the whole set is in the right bounds.\n if (newLeftBounds === empty) {\n return [empty, set];\n }\n\n const newRightBounds = unsafe.combineProduct(productOperations, set.bounds, rightBounds, intersectUntyped);\n if (set.isSubspace) {\n return [subspace(newLeftBounds), newRightBounds === empty ? empty : subspace(newRightBounds)];\n }\n\n const [ll, lr] = restrictByBounds(productOperations, set.left, leftBounds, rightBounds);\n const [rl, rr] = restrictByBounds(productOperations, set.right, leftBounds, rightBounds);\n return [combineChildren(productOperations, ll, rl), combineChildren(productOperations, lr, rr)];\n}\n\nconst splitByBox = <T>(\n productOperations: ProductOperations<T>,\n set: UntypedProductSet<T>,\n { box: leftBounds }: Box<T>,\n { box: rightBounds }: Box<T>,\n): Pair<UntypedProductSet<T>, UntypedProductSet<T>> => {\n return restrictByBounds(productOperations, set, leftBounds, rightBounds);\n};\n\nfunction recurse<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n visitFunc: (\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n box: Box<T>\n ) => UntypedProductSet<T>,\n) {\n const [leftBox, rightBox] = splitBox(productOperations, currentBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n const lChild = visitFunc(productOperations, ll, rl, leftBox);\n if (lChild === dense) {\n return dense;\n }\n const rChild = visitFunc(productOperations, lr, rr, rightBox);\n return combineChildren(productOperations, lChild, rChild);\n}\n\nfunction unionUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (right === empty) {\n return left;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left.isSubspace && right.isSubspace) {\n const combinedSubspace = tryUnionSubspaces(productOperations, left, right);\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n }\n\n return recurse(productOperations, left, right, currentBox, unionUntypedProduct);\n}\n\nexport function unionProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return right;\n }\n if (left === empty) {\n return right;\n }\n if (left === dense) {\n return left;\n }\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = unionUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction intersectUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (left === empty || right === empty) {\n return empty;\n }\n if (left === dense) {\n return right;\n }\n if (right === dense) {\n return left;\n }\n if (left.isSubspace && right.isSubspace) {\n const res = unsafe.combineProduct(productOperations, left.bounds, right.bounds, intersectUntyped);\n if (res === empty) {\n return empty;\n }\n return subspace(res);\n }\n\n return recurse(productOperations, left, right, currentBox, intersectUntypedProduct);\n}\n\nexport function intersectProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (left === empty) {\n return left;\n }\n if (right === empty) {\n return right;\n }\n if (left === dense) {\n return right;\n }\n if (right === dense) {\n return left;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = intersectUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction tryExceptSubspaces<T>(\n productOperations: ProductOperations<T>,\n left: Subspace<T>,\n right: Subspace<T>,\n): Subspace<T> | Dense | Empty | undefined {\n const cmp = compareSubspace(productOperations, left.bounds, right.bounds);\n if (cmp === 0 || cmp === -1) {\n return empty;\n }\n let notContainedDimension: keyof T | undefined;\n // because Object.keys only returns string[], we need to downcast\n const po_keys = Object.keys(productOperations) as (keyof T)[];\n for (const dim of po_keys) {\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const cmp_inner = compareUntyped<unknown, unknown>(\n productOperations[dim],\n toBspSet(left.bounds[dim]),\n toBspSet(right.bounds[dim]),\n );\n if (cmp_inner === undefined || cmp_inner > 0) {\n if (notContainedDimension !== undefined) {\n return undefined;\n }\n\n notContainedDimension = dim;\n }\n }\n }\n\n if (notContainedDimension !== undefined) {\n const newDim = exceptUntyped<unknown, unknown>(\n productOperations[notContainedDimension],\n toBspSet(left.bounds[notContainedDimension]),\n toBspSet(right.bounds[notContainedDimension]),\n );\n\n if (newDim === empty) {\n return empty;\n }\n if (newDim === dense) {\n // we are actually deleting the `differentDimension`, so the variable\n // `deleted` must be there. Hence disabling the rule here.\n const { [notContainedDimension]: deleted, ...leftBoundsWithoutDifferentDimension } = left.bounds;\n return subspace<unknown>(leftBoundsWithoutDifferentDimension);\n }\n const newBounds: UntypedProduct<T> = {\n ...left.bounds,\n [notContainedDimension]: newDim,\n };\n return subspace(newBounds);\n }\n\n return undefined;\n}\n\nfunction exceptUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n currentBox: Box<T>,\n): UntypedProductSet<T> {\n if (left === empty) {\n return left;\n }\n if (right === dense) {\n return empty;\n }\n if (right === empty) {\n return left;\n }\n\n if (left === dense) {\n return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n }\n\n if (left.isSubspace && right.isSubspace) {\n const combinedSubspace = tryExceptSubspaces(productOperations, left, right);\n if (combinedSubspace !== undefined) {\n return combinedSubspace;\n }\n }\n\n return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);\n}\n\nexport function exceptProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n): ProductSet<T & U> {\n if (left === empty) {\n return left;\n }\n if (right === empty) {\n return left;\n }\n if (right === dense) {\n return empty;\n }\n if (left === dense) {\n const res_inner =\n exceptUntypedProduct(right.productOperations, dense, right.root, top(right.productOperations));\n if (res_inner === empty) {\n return res_inner;\n }\n return sparseProduct(right.productOperations, res_inner);\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n const res = exceptUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n if (res === empty) {\n return res;\n }\n return sparseProduct(productOperations, res);\n}\n\nfunction compareUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n boundingBox: Box<T>,\n): -1 | 0 | 1 | undefined {\n if (left === right) {\n return 0;\n }\n\n if (left === empty) {\n return -1;\n }\n\n if (right === empty) {\n return 1;\n }\n\n if (left === dense) {\n if (right === dense) {\n return 0;\n }\n\n return 1;\n }\n\n if (right === dense) {\n return -1;\n }\n\n if (left.isSubspace) {\n if (right.isSubspace) {\n return compareSubspace(productOperations, left.bounds, right.bounds);\n }\n }\n\n const [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n const leftCmp = compareUntypedProduct(productOperations, ll, rl, leftBox);\n if (leftCmp === undefined) {\n return undefined;\n }\n return combineCmp(leftCmp, compareUntypedProduct(productOperations, lr, rr, rightBox));\n}\n\nexport function compareProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n) {\n if (left === right) {\n return 0;\n }\n\n if (left === empty) {\n return -1;\n }\n\n if (right === empty) {\n return 1;\n }\n\n if (left === dense) {\n if (right === dense) {\n return 0;\n }\n\n return 1;\n }\n\n if (right === dense) {\n return -1;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n return compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));\n}\n\nfunction meetsSubspace<T>(productOperations: ProductOperations<T>, left: UntypedProduct<T>, right: UntypedProduct<T>) {\n for (const dimStr of Object.keys(productOperations)) {\n const dim = dimStr as keyof T;\n if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {\n const lProj = toBspSet(left[dim]);\n const rProj = toBspSet(right[dim]);\n const setOperations = productOperations[dim];\n if (!meetsUntyped<unknown, unknown>(setOperations, lProj, rProj)) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction meetsUntypedProduct<T>(\n productOperations: ProductOperations<T>,\n left: UntypedProductSet<T>,\n right: UntypedProductSet<T>,\n boundingBox: Box<T>,\n): boolean {\n if (left === empty || right === empty) {\n return false;\n }\n if (left === dense || right === dense) {\n return true;\n }\n if (!meetsSubspace(productOperations, left.bounds, right.bounds)) {\n return false;\n }\n if (left.isSubspace && right.isSubspace) {\n return true;\n }\n\n const [leftBox, rightBox] = splitBox(productOperations, boundingBox);\n const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);\n const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);\n\n return (\n meetsUntypedProduct(productOperations, ll, rl, leftBox)\n || meetsUntypedProduct(productOperations, lr, rr, rightBox)\n );\n}\n\nexport function meetsProduct<T extends Compatible<U, T>, U extends Compatible<T, U>>(\n left: ProductSet<T>,\n right: ProductSet<U>,\n) {\n if (left === empty || right === empty) {\n return false;\n }\n if (left === dense || right === dense) {\n return true;\n }\n\n const productOperations = { ...left.productOperations, ...right.productOperations };\n return 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 unionProduct(exceptProduct(left, right), exceptProduct(right, left));\n\nexport function getSubspaces<T>(set: ProductSet<T>) {\n if (set === empty || set === dense) {\n return [];\n }\n const res: UntypedProduct<T>[] = [];\n function loop(root: UntypedSparseProduct<T>) {\n if (root.isSubspace) {\n res.push(root.bounds);\n return;\n }\n\n loop(root.left);\n loop(root.right);\n }\n\n loop(set.root);\n return res;\n}\n\nexport function forEachProduct<T, Props extends (keyof T)[]>(\n set: ProductSet<T>,\n f: (product: Product<Restrict<T, Props>>) => boolean,\n ...dims: Props\n): boolean {\n const newSet = project(set, ...dims);\n if (newSet === empty) {\n return true;\n }\n if (newSet === dense) {\n return f(unsafe.denseProduct(dims));\n }\n\n const { productOperations, root } = newSet;\n\n function loop(root_inner: UntypedSparseProduct<T>): boolean {\n if (root_inner.isSubspace) {\n return f(unsafe.fromUntypedProduct(productOperations, root_inner.bounds, dims));\n }\n return loop(root_inner.left) && loop(root_inner.right);\n }\n\n return loop(root);\n}\n\nexport function getSubspaceCount<T>(set: ProductSet<T>) {\n if (set === empty || set === dense) {\n return 0;\n }\n return getUntypedSubspaceCount(set.root);\n}\n"]}
|
package/lib/range.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Ensures that 0
|
|
6
|
+
* Ensures that 0 \<= 'value' \< 'limit'. Throws a RangeError otherwise.
|
|
7
7
|
*/
|
|
8
8
|
export declare function ensureRange(value: number, limit: number): void;
|
|
9
9
|
//# sourceMappingURL=range.d.ts.map
|
package/lib/range.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Ensures that 0
|
|
6
|
+
* Ensures that 0 \<= 'value' \< 'limit'. Throws a RangeError otherwise.
|
|
7
7
|
*/
|
|
8
8
|
export function ensureRange(value, limit) {
|
|
9
9
|
// Coerce 'value' to Uint32 so that we can range check with a single branch.
|
package/lib/range.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEF;;GAEG;AACJ,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAa;IACpD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAG,iCAAiC;IAE/D,IAAI,MAAM,IAAI,KAAK,EAAE;QACjB,MAAM,IAAI,UAAU,CAAC,gCAAgC,CAAC,CAAC;KAC1D;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n /**\n * Ensures that 0
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEF;;GAEG;AACJ,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAa;IACpD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAG,iCAAiC;IAE/D,IAAI,MAAM,IAAI,KAAK,EAAE;QACjB,MAAM,IAAI,UAAU,CAAC,gCAAgC,CAAC,CAAC;KAC1D;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n /**\n * Ensures that 0 \\<= 'value' \\< 'limit'. Throws a RangeError otherwise.\n */\nexport function ensureRange(value: number, limit: number) {\n // Coerce 'value' to Uint32 so that we can range check with a single branch.\n const _value = value >>> 0; // eslint-disable-line no-bitwise\n\n if (_value >= limit) {\n throw new RangeError(\"Invalid (row, col) coordinate.\");\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undoprovider.d.ts","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAiB,2BAA2B,EAAsB,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,kBAAkB;IAQvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN/B,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAC,CAAqB;gBAGlB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,EACjD,UAAU,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI;IAG/D,MAAM,CAAC,SAAS,EAAE,2BAA2B,EAAE,MAAM,EAAE;QAAE,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"undoprovider.d.ts","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAiB,2BAA2B,EAAsB,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,MAAM,EAA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