@fluidframework/matrix 2.0.0-internal.6.3.2 → 2.0.0-internal.6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +8 -6
- 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.d.ts.map +1 -1
- package/dist/permutationvector.js +1 -0
- package/dist/permutationvector.js.map +1 -1
- package/dist/sparsearray2d.d.ts +2 -2
- package/dist/sparsearray2d.d.ts.map +1 -1
- package/dist/sparsearray2d.js +3 -7
- package/dist/sparsearray2d.js.map +1 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +8 -6
- 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/permutationvector.d.ts.map +1 -1
- package/lib/permutationvector.js +1 -0
- package/lib/permutationvector.js.map +1 -1
- package/lib/sparsearray2d.d.ts +2 -2
- package/lib/sparsearray2d.d.ts.map +1 -1
- package/lib/sparsearray2d.js +3 -7
- package/lib/sparsearray2d.js.map +1 -1
- package/package.json +15 -16
- package/src/matrix.ts +15 -6
- package/src/packageVersion.ts +1 -1
- package/src/permutationvector.ts +1 -0
- package/src/sparsearray2d.ts +3 -7
package/CHANGELOG.md
CHANGED
package/dist/matrix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,MAAM,uCAAuC,CA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YAAY;IAuB5E,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAiB5E;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,iBAAiB;IAQzD;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAUpB,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,CAAC,EAAE,GAAG;IAoBhE,SAAS,CAAC,SAAS;IASnB,SAAS,CAAC,SAAS;IAWnB,OAAO,CAAC,cAAc;IAmBtB,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO;IAqD7D,SAAS,CAAC,YAAY;IAEtB;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAyBxD,SAAS,CAAC,WAAW,CACpB,UAAU,EAAE,yBAAyB,EACrC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO;IA+DzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAGF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAiBrB,QAAQ;IAoBf;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;CA0D/C"}
|
package/dist/matrix.js
CHANGED
|
@@ -450,10 +450,12 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
|
|
|
450
450
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
451
451
|
*/
|
|
452
452
|
applyStashedOp(content) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const
|
|
453
|
+
const parsedContent = (0, shared_object_base_1.parseHandles)(content, this.serializer);
|
|
454
|
+
if (parsedContent.target === "cols" /* cols */ ||
|
|
455
|
+
parsedContent.target === "rows" /* rows */) {
|
|
456
|
+
const op = parsedContent;
|
|
457
|
+
const currentVector = parsedContent.target === "cols" /* cols */ ? this.cols : this.rows;
|
|
458
|
+
const oppositeVector = parsedContent.target === "cols" /* cols */ ? this.rows : this.cols;
|
|
457
459
|
const metadata = currentVector.applyStashedOp(op);
|
|
458
460
|
const localSeq = currentVector.getCollabWindow().localSeq;
|
|
459
461
|
const oppositeWindow = oppositeVector.getCollabWindow();
|
|
@@ -462,8 +464,8 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
|
|
|
462
464
|
return metadata;
|
|
463
465
|
}
|
|
464
466
|
else {
|
|
465
|
-
(0, core_utils_1.assert)(
|
|
466
|
-
const setOp =
|
|
467
|
+
(0, core_utils_1.assert)(parsedContent.type === ops_1.MatrixOp.set, 0x2da /* "Unknown SharedMatrix 'op' type." */);
|
|
468
|
+
const setOp = parsedContent;
|
|
467
469
|
const rowHandle = this.rows.getAllocatedHandle(setOp.row);
|
|
468
470
|
const colHandle = this.cols.getAllocatedHandle(setOp.col);
|
|
469
471
|
const rowsRefSeq = this.rows.getCollabWindow().currentSeq;
|
package/dist/matrix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAQpD,2EAM4C;AAE5C,iEAA2F;AAE3F,2DAMoC;AACpC,+BAAiC;AACjC,2DAAmF;AACnF,mDAAgD;AAChD,uCAAgD;AAChD,+CAAsD;AACtD,mDAAkD;AAClD,mCAAsC;AAEtC,iDAAoD;AA8BpD;;;;;;;;;;;GAWG;AACH,MAAa,YACZ,SAAQ,iCAAY;IAkBpB,YACC,OAA+B,EACxB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;QAHzC,OAAE,G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;gBAC5B,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACxD,IAAI,QAAQ,KAAK,IAAI,EAAE;oBACtB,QAAQ,GAAG,SAAS,CAAC;iBACrB;gBAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;aAClD;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;gBAChC,SAAS;gBACT,SAAS;gBACT,QAAQ;gBACR,UAAU;gBACV,UAAU;aACV,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;SAChB;IACF,CAAC;CACD;AAltBD,oCAktBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tSerializable,\n\tIChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidSerializer,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tSharedObject,\n\tSummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IMatrixProducer, IMatrixConsumer, IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\nimport {\n\tMergeTreeDeltaType,\n\tIMergeTreeOp,\n\tSegmentGroup,\n\tClient,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, reinsertSegmentIntoVector } 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\trows = \"rows\",\n\tcols = \"cols\",\n\tcells = \"cells\",\n}\n\ninterface ISetOp<T> {\n\ttype: MatrixOp.set;\n\trow: number;\n\tcol: number;\n\tvalue: MatrixItem<T>;\n}\n\ninterface ISetOpMetadata {\n\trowHandle: Handle;\n\tcolHandle: Handle;\n\tlocalSeq: number;\n\trowsRefSeq: number;\n\tcolsRefSeq: 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 */\n// eslint-disable-next-line @rushstack/no-new-null -- Using 'null' to disallow 'null'.\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\textends SharedObject\n\timplements\n\t\tIMatrixProducer<MatrixItem<T>>,\n\t\tIMatrixReader<MatrixItem<T>>,\n\t\tIMatrixWriter<MatrixItem<T>>\n{\n\tprivate readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n\tpublic static getFactory() {\n\t\treturn new SharedMatrixFactory();\n\t}\n\n\tprivate readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n\tprivate readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n\tprivate cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n\tprivate pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n\tconstructor(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_matrix_\");\n\n\t\tthis.rows = new PermutationVector(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onRowDelta,\n\t\t\tthis.onRowHandlesRecycled,\n\t\t);\n\n\t\tthis.cols = new PermutationVector(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onColDelta,\n\t\t\tthis.onColHandlesRecycled,\n\t\t);\n\t}\n\n\tprivate undo?: MatrixUndoProvider<T>;\n\n\t/**\n\t * Subscribes the given IUndoConsumer to the matrix.\n\t */\n\tpublic openUndo(consumer: IUndoConsumer) {\n\t\tassert(\n\t\t\tthis.undo === undefined,\n\t\t\t0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */,\n\t\t);\n\n\t\tthis.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n\t}\n\n\t// TODO: closeUndo()?\n\n\tprivate get rowHandles() {\n\t\treturn this.rows.handleCache;\n\t}\n\tprivate get colHandles() {\n\t\treturn this.cols.handleCache;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n\t}\n\n\t// #region IMatrixProducer\n\n\topenMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>> {\n\t\tthis.consumers.add(consumer);\n\t\treturn this;\n\t}\n\n\tcloseMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n\t\tthis.consumers.delete(consumer);\n\t}\n\n\t// #endregion IMatrixProducer\n\n\t// #region IMatrixReader\n\n\tpublic get rowCount() {\n\t\treturn this.rows.getLength();\n\t}\n\tpublic get colCount() {\n\t\treturn this.cols.getLength();\n\t}\n\n\tpublic getCell(row: number, col: number): MatrixItem<T> {\n\t\t// Perf: When possible, bounds checking is performed inside the implementation for\n\t\t// 'getHandle()' so that it can be elided in the case of a cache hit. This\n\t\t// yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n\t\t// Map the logical (row, col) to associated storage handles.\n\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\tif (isHandleValid(rowHandle)) {\n\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\tif (isHandleValid(colHandle)) {\n\t\t\t\treturn this.cells.getCell(rowHandle, colHandle);\n\t\t\t}\n\t\t} else {\n\t\t\t// If we early exit because the given rowHandle is unallocated, we still need to\n\t\t\t// bounds-check the 'col' parameter.\n\t\t\tensureRange(col, this.cols.getLength());\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer(): IMatrixProducer<MatrixItem<T>> {\n\t\treturn this;\n\t}\n\n\t// #endregion IMatrixReader\n\n\tpublic setCell(row: number, col: number, value: MatrixItem<T>) {\n\t\tassert(\n\t\t\t0 <= row && row < this.rowCount && 0 <= col && col < this.colCount,\n\t\t\t0x01a /* \"Trying to set out-of-bounds cell!\" */,\n\t\t);\n\n\t\tthis.setCellCore(row, col, value);\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(row, col, 1, 1, this);\n\t\t}\n\t}\n\n\tpublic setCells(\n\t\trowStart: number,\n\t\tcolStart: number,\n\t\tcolCount: number,\n\t\tvalues: readonly MatrixItem<T>[],\n\t) {\n\t\tconst rowCount = Math.ceil(values.length / colCount);\n\n\t\tassert(\n\t\t\t0 <= rowStart &&\n\t\t\t\trowStart < this.rowCount &&\n\t\t\t\t0 <= colStart &&\n\t\t\t\tcolStart < this.colCount &&\n\t\t\t\t1 <= colCount &&\n\t\t\t\tcolCount <= this.colCount - colStart &&\n\t\t\t\trowCount <= this.rowCount - rowStart,\n\t\t\t0x01b /* \"Trying to set multiple out-of-bounds cells!\" */,\n\t\t);\n\n\t\tconst endCol = colStart + colCount;\n\t\tlet r = rowStart;\n\t\tlet c = colStart;\n\n\t\tfor (const value of values) {\n\t\t\tthis.setCellCore(r, c, value);\n\n\t\t\tif (++c === endCol) {\n\t\t\t\tc = colStart;\n\t\t\t\tr++;\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprivate setCellCore(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle = this.rows.getAllocatedHandle(row),\n\t\tcolHandle = this.cols.getAllocatedHandle(col),\n\t) {\n\t\tif (this.undo !== undefined) {\n\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\tif (oldValue === null) {\n\t\t\t\toldValue = undefined;\n\t\t\t}\n\n\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t}\n\n\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\tif (this.isAttached()) {\n\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t}\n\t}\n\n\tprivate sendSetCellOp(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle: Handle,\n\t\tcolHandle: Handle,\n\t\tlocalSeq = this.nextLocalSeq(),\n\t\trowsRefSeq = this.rows.getCollabWindow().currentSeq,\n\t\tcolsRefSeq = this.cols.getCollabWindow().currentSeq,\n\t) {\n\t\tassert(\n\t\t\tthis.isAttached(),\n\t\t\t0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */,\n\t\t);\n\n\t\tconst op: ISetOp<T> = {\n\t\t\ttype: MatrixOp.set,\n\t\t\trow,\n\t\t\tcol,\n\t\t\tvalue,\n\t\t};\n\n\t\tconst metadata: ISetOpMetadata = {\n\t\t\trowHandle,\n\t\t\tcolHandle,\n\t\t\tlocalSeq,\n\t\t\trowsRefSeq,\n\t\t\tcolsRefSeq,\n\t\t};\n\n\t\tthis.submitLocalMessage(op, metadata);\n\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t}\n\n\tprivate submitVectorMessage(\n\t\tcurrentVector: PermutationVector,\n\t\toppositeVector: PermutationVector,\n\t\tdimension: SnapshotPath.rows | SnapshotPath.cols,\n\t\tmessage: any,\n\t) {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n\t\t// for each submitted op it not aware of to keep them synchronized.\n\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t// Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n\t\t// the MergeTree submits the op with the original 'localSeq'.\n\t\tassert(\n\t\t\tlocalSeq >= oppositeWindow.localSeq,\n\t\t\t0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */,\n\t\t);\n\n\t\toppositeWindow.localSeq = localSeq;\n\n\t\t// If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n\t\t// Do not queue a message or track the pending op, as there will never be an ACK, etc.\n\t\tif (this.isAttached()) {\n\t\t\t// Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n\t\t\tmessage.target = dimension;\n\n\t\t\tthis.submitLocalMessage(\n\t\t\t\tmessage,\n\t\t\t\tcurrentVector.peekPendingSegmentGroups(\n\t\t\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate submitColMessage(message: any) {\n\t\tthis.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n\t}\n\n\tpublic insertCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.insert(colStart, count));\n\t}\n\n\tpublic removeCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.remove(colStart, count));\n\t}\n\n\tprivate submitRowMessage(message: any) {\n\t\tthis.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n\t}\n\n\tpublic insertRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.insert(rowStart, count));\n\t}\n\n\tpublic removeRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.remove(rowStart, count));\n\t}\n\n\t/** @internal */ public _undoRemoveRows(rowStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.rows, rowStart, spec);\n\t\tthis.submitRowMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted rows.\n\t\tlet rowHandle = inserted.start;\n\t\tconst rowCount = inserted.cachedLength;\n\t\tfor (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n\t\t}\n\t}\n\n\t/** @internal */ public _undoRemoveCols(colStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.cols, colStart, spec);\n\t\tthis.submitColMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted cols.\n\t\tlet colHandle = inserted.start;\n\t\tconst colCount = inserted.cachedLength;\n\t\tfor (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n\t\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.rows.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.cols.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.cells,\n\t\t\tserializer.stringify([this.cells.snapshot(), this.pending.snapshot()], this.handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer on the GC data for this SharedMatrix.\n\t * All the IFluidHandle's stored in the cells represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tserializer.stringify(this.getCell(row, col), this.handle);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advances the 'localSeq' counter for the cell data operation currently being queued.\n\t *\n\t * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n\t * automatically advance 'localSeq'.\n\t */\n\tprivate nextLocalSeq() {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n\t\t// for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n\t\t// need to bump both counters.)\n\n\t\tthis.cols.getCollabWindow().localSeq++;\n\t\treturn ++this.rows.getCollabWindow().localSeq;\n\t}\n\n\tprotected submitLocalMessage(message: any, localOpMetadata?: any) {\n\t\t// TODO: Recommend moving this assertion into SharedObject\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/2559)\n\t\tassert(\n\t\t\tthis.isAttached() === true,\n\t\t\t0x01d /* \"Trying to submit message to runtime while detached!\" */,\n\t\t);\n\n\t\tsuper.submitLocalMessage(\n\t\t\tmakeHandlesSerializable(message, this.serializer, this.handle),\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\t// Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n\t\t\t0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n\t\t);\n\t}\n\n\tprotected didAttach() {\n\t\t// We've attached we need to start generating and sending ops.\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\tprotected onConnect() {\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n\t\t\t0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */,\n\t\t);\n\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t}\n\n\tprivate rebasePosition(\n\t\tclient: Client,\n\t\tpos: number,\n\t\treferenceSequenceNumber: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tconst { clientId } = client.getCollabWindow();\n\t\tconst { segment, offset } = client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{ referenceSequenceNumber, clientId: client.getLongClientId(clientId) },\n\t\t\tlocalSeq,\n\t\t);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn client.findReconnectionPosition(segment, localSeq) + offset;\n\t}\n\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tswitch (content.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.submitColMessage(\n\t\t\t\t\tthis.cols.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.submitRowMessage(\n\t\t\t\t\tthis.rows.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontent.type === MatrixOp.set,\n\t\t\t\t\t0x020 /* \"Unknown SharedMatrix 'op' type.\" */,\n\t\t\t\t);\n\n\t\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\t\tconst { rowHandle, colHandle, localSeq, rowsRefSeq, colsRefSeq } =\n\t\t\t\t\tlocalOpMetadata as ISetOpMetadata;\n\n\t\t\t\t// If there are more pending local writes to the same row/col handle, it is important\n\t\t\t\t// to skip resubmitting this op since it is possible the row/col handle has been recycled\n\t\t\t\t// and now refers to a different position than when this op was originally submitted.\n\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\tconst row = this.rebasePosition(this.rows, setOp.row, rowsRefSeq, localSeq);\n\t\t\t\t\tconst col = this.rebasePosition(this.cols, setOp.col, colsRefSeq, localSeq);\n\n\t\t\t\t\tif (row !== undefined && col !== undefined && row >= 0 && col >= 0) {\n\t\t\t\t\t\tthis.sendSetCellOp(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tcol,\n\t\t\t\t\t\t\tsetOp.value,\n\t\t\t\t\t\t\trowHandle,\n\t\t\t\t\t\t\tcolHandle,\n\t\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\t\trowsRefSeq,\n\t\t\t\t\t\t\tcolsRefSeq,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\ttry {\n\t\t\tawait this.rows.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.rows),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tawait this.cols.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.cols),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tconst [cellData, pendingCliSeqData] = await deserializeBlob(\n\t\t\t\tstorage,\n\t\t\t\tSnapshotPath.cells,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\tthis.cells = SparseArray2D.load(cellData);\n\t\t\tthis.pending = SparseArray2D.load(pendingCliSeqData);\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\trawMessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tconst msg = parseHandles(rawMessage, this.serializer);\n\n\t\tconst contents = msg.contents;\n\n\t\tswitch (contents.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.cols.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.rows.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontents.type === MatrixOp.set,\n\t\t\t\t\t0x021 /* \"SharedMatrix message contents have unexpected type!\" */,\n\t\t\t\t);\n\n\t\t\t\tconst { row, col } = contents;\n\n\t\t\t\tif (local) {\n\t\t\t\t\t// We are receiving the ACK for a local pending set operation.\n\t\t\t\t\tconst { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n\t\t\t\t\t// If this is the most recent write to the cell by the local client, remove our\n\t\t\t\t\t// entry from 'pendingCliSeqs' to resume allowing remote writes.\n\t\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\t\tthis.pending.setCell(rowHandle, colHandle, undefined);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst adjustedRow = this.rows.adjustPosition(row, rawMessage);\n\n\t\t\t\t\tif (adjustedRow !== undefined) {\n\t\t\t\t\t\tconst adjustedCol = this.cols.adjustPosition(col, rawMessage);\n\n\t\t\t\t\t\tif (adjustedCol !== undefined) {\n\t\t\t\t\t\t\tconst rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n\t\t\t\t\t\t\tconst colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t\t\t\t\t\t0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If there is a pending (unACKed) local write to the same cell, skip the current op\n\t\t\t\t\t\t\t// since it \"happened before\" the pending write.\n\t\t\t\t\t\t\tif (this.pending.getCell(rowHandle, colHandle) === undefined) {\n\t\t\t\t\t\t\t\tconst { value } = contents;\n\t\t\t\t\t\t\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\t\t\t\t\t\t\tfor (const consumer of this.consumers.values()) {\n\t\t\t\t\t\t\t\t\tconsumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n\tprivate readonly onRowDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.rowsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n\tprivate readonly onColDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.colsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\tprivate readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n\t\tfor (const rowHandle of rowHandles) {\n\t\t\tthis.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t\tthis.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t}\n\t};\n\n\tprivate readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n\t\tfor (const colHandle of colHandles) {\n\t\t\tthis.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t\tthis.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t}\n\t};\n\n\t/**\n\t * Returns true if the latest pending write to the cell indicated by the given row/col handles\n\t * matches the given 'localSeq'.\n\t *\n\t * A return value of `true` indicates that there are no later local operations queued that will\n\t * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n\t * with a different value as well as row/col removals that might recycled the given row/col handles.\n\t */\n\tprivate isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n\t\t// Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n\t\t// locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n\t\t// be 'undefined' or > 'localSeq'.\n\t\tassert(\n\t\t\t!(pendingLocalSeq < localSeq),\n\t\t\t0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */,\n\t\t);\n\n\t\t// If this is the most recent write to the cell by the local client, the stored localSeq\n\t\t// will be an exact match for the given 'localSeq'.\n\t\treturn pendingLocalSeq === localSeq;\n\t}\n\n\tpublic toString() {\n\t\tlet s = `client:${\n\t\t\tthis.runtime.clientId\n\t\t}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n\t\tfor (let r = 0; r < this.rowCount; r++) {\n\t\t\ts += ` [`;\n\t\t\tfor (let c = 0; c < this.colCount; c++) {\n\t\t\t\tif (c > 0) {\n\t\t\t\t\ts += \", \";\n\t\t\t\t}\n\n\t\t\t\ts += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n\t\t\t}\n\t\t\ts += \"]\\n\";\n\t\t}\n\n\t\treturn `${s}\\n`;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): unknown {\n\t\tif (content.target === SnapshotPath.cols || content.target === SnapshotPath.rows) {\n\t\t\tconst op = content as IMergeTreeOp;\n\t\t\tconst currentVector = content.target === SnapshotPath.cols ? this.cols : this.rows;\n\t\t\tconst oppositeVector = content.target === SnapshotPath.cols ? this.rows : this.cols;\n\t\t\tconst metadata = currentVector.applyStashedOp(op);\n\t\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t\tassert(\n\t\t\t\tlocalSeq > oppositeWindow.localSeq,\n\t\t\t\t0x2d9,\n\t\t\t\t/* \"The 'localSeq' of the vector applying stashed op must > the 'localSeq' of the other vector.\" */\n\t\t\t);\n\n\t\t\toppositeWindow.localSeq = localSeq;\n\n\t\t\treturn metadata;\n\t\t} else {\n\t\t\tassert(content.type === MatrixOp.set, 0x2da /* \"Unknown SharedMatrix 'op' type.\" */);\n\n\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\tconst rowHandle = this.rows.getAllocatedHandle(setOp.row);\n\t\t\tconst colHandle = this.cols.getAllocatedHandle(setOp.col);\n\t\t\tconst rowsRefSeq = this.rows.getCollabWindow().currentSeq;\n\t\t\tconst colsRefSeq = this.cols.getCollabWindow().currentSeq;\n\t\t\tif (this.undo !== undefined) {\n\t\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (oldValue === null) {\n\t\t\t\t\toldValue = undefined;\n\t\t\t\t}\n\n\t\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t\t}\n\n\t\t\tthis.cells.setCell(rowHandle, colHandle, setOp.value);\n\t\t\tconst localSeq = this.nextLocalSeq();\n\t\t\tconst metadata: ISetOpMetadata = {\n\t\t\t\trowHandle,\n\t\t\t\tcolHandle,\n\t\t\t\tlocalSeq,\n\t\t\t\trowsRefSeq,\n\t\t\t\tcolsRefSeq,\n\t\t\t};\n\n\t\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t\t\treturn metadata;\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAQpD,2EAM4C;AAE5C,iEAA2F;AAE3F,2DAMoC;AACpC,+BAAiC;AACjC,2DAAmF;AACnF,mDAAgD;AAChD,uCAAgD;AAChD,+CAAsD;AACtD,mDAAkD;AAClD,mCAAsC;AAEtC,iDAAoD;AA8BpD;;;;;;;;;;;GAWG;AACH,MAAa,YACZ,SAAQ,iCAAY;IAkBpB,YACC,OAA+B,EACxB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;QAHzC,OAAE,GAAF,EAAE,CAAQ;QAdD,cAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;QAS/D,UAAK,GAAG,IAAI,6BAAa,EAAiB,CAAC,CAAC,sBAAsB;QAClE,YAAO,GAAG,IAAI,6BAAa,EAAU,CAAC,CAAC,yBAAyB;QA4jBxE,sFAAsF;QACrE,eAAU,GAAG,CAC7B,QAAgB,EAChB,YAAoB,EACpB,aAAqB,EACpB,EAAE;YACH,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;gBACtC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;aAClE;QACF,CAAC,CAAC;QAEF,sFAAsF;QACrE,eAAU,GAAG,CAC7B,QAAgB,EAChB,YAAoB,EACpB,aAAqB,EACpB,EAAE;YACH,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;gBACtC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;aAClE;QACF,CAAC,CAAC;QAEe,yBAAoB,G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AAQ,CAAC;SAChB;IACF,CAAC;CACD;AA3tBD,oCA2tBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tSerializable,\n\tIChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidSerializer,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tSharedObject,\n\tSummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IMatrixProducer, IMatrixConsumer, IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\nimport {\n\tMergeTreeDeltaType,\n\tIMergeTreeOp,\n\tSegmentGroup,\n\tClient,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, reinsertSegmentIntoVector } 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\trows = \"rows\",\n\tcols = \"cols\",\n\tcells = \"cells\",\n}\n\ninterface ISetOp<T> {\n\ttype: MatrixOp.set;\n\trow: number;\n\tcol: number;\n\tvalue: MatrixItem<T>;\n}\n\ninterface ISetOpMetadata {\n\trowHandle: Handle;\n\tcolHandle: Handle;\n\tlocalSeq: number;\n\trowsRefSeq: number;\n\tcolsRefSeq: 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 */\n// eslint-disable-next-line @rushstack/no-new-null -- Using 'null' to disallow 'null'.\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\textends SharedObject\n\timplements\n\t\tIMatrixProducer<MatrixItem<T>>,\n\t\tIMatrixReader<MatrixItem<T>>,\n\t\tIMatrixWriter<MatrixItem<T>>\n{\n\tprivate readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n\tpublic static getFactory() {\n\t\treturn new SharedMatrixFactory();\n\t}\n\n\tprivate readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n\tprivate readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n\tprivate cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n\tprivate pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n\tconstructor(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_matrix_\");\n\n\t\tthis.rows = new PermutationVector(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onRowDelta,\n\t\t\tthis.onRowHandlesRecycled,\n\t\t);\n\n\t\tthis.cols = new PermutationVector(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onColDelta,\n\t\t\tthis.onColHandlesRecycled,\n\t\t);\n\t}\n\n\tprivate undo?: MatrixUndoProvider<T>;\n\n\t/**\n\t * Subscribes the given IUndoConsumer to the matrix.\n\t */\n\tpublic openUndo(consumer: IUndoConsumer) {\n\t\tassert(\n\t\t\tthis.undo === undefined,\n\t\t\t0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */,\n\t\t);\n\n\t\tthis.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n\t}\n\n\t// TODO: closeUndo()?\n\n\tprivate get rowHandles() {\n\t\treturn this.rows.handleCache;\n\t}\n\tprivate get colHandles() {\n\t\treturn this.cols.handleCache;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n\t}\n\n\t// #region IMatrixProducer\n\n\topenMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>> {\n\t\tthis.consumers.add(consumer);\n\t\treturn this;\n\t}\n\n\tcloseMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n\t\tthis.consumers.delete(consumer);\n\t}\n\n\t// #endregion IMatrixProducer\n\n\t// #region IMatrixReader\n\n\tpublic get rowCount() {\n\t\treturn this.rows.getLength();\n\t}\n\tpublic get colCount() {\n\t\treturn this.cols.getLength();\n\t}\n\n\tpublic getCell(row: number, col: number): MatrixItem<T> {\n\t\t// Perf: When possible, bounds checking is performed inside the implementation for\n\t\t// 'getHandle()' so that it can be elided in the case of a cache hit. This\n\t\t// yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n\t\t// Map the logical (row, col) to associated storage handles.\n\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\tif (isHandleValid(rowHandle)) {\n\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\tif (isHandleValid(colHandle)) {\n\t\t\t\treturn this.cells.getCell(rowHandle, colHandle);\n\t\t\t}\n\t\t} else {\n\t\t\t// If we early exit because the given rowHandle is unallocated, we still need to\n\t\t\t// bounds-check the 'col' parameter.\n\t\t\tensureRange(col, this.cols.getLength());\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer(): IMatrixProducer<MatrixItem<T>> {\n\t\treturn this;\n\t}\n\n\t// #endregion IMatrixReader\n\n\tpublic setCell(row: number, col: number, value: MatrixItem<T>) {\n\t\tassert(\n\t\t\t0 <= row && row < this.rowCount && 0 <= col && col < this.colCount,\n\t\t\t0x01a /* \"Trying to set out-of-bounds cell!\" */,\n\t\t);\n\n\t\tthis.setCellCore(row, col, value);\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(row, col, 1, 1, this);\n\t\t}\n\t}\n\n\tpublic setCells(\n\t\trowStart: number,\n\t\tcolStart: number,\n\t\tcolCount: number,\n\t\tvalues: readonly MatrixItem<T>[],\n\t) {\n\t\tconst rowCount = Math.ceil(values.length / colCount);\n\n\t\tassert(\n\t\t\t0 <= rowStart &&\n\t\t\t\trowStart < this.rowCount &&\n\t\t\t\t0 <= colStart &&\n\t\t\t\tcolStart < this.colCount &&\n\t\t\t\t1 <= colCount &&\n\t\t\t\tcolCount <= this.colCount - colStart &&\n\t\t\t\trowCount <= this.rowCount - rowStart,\n\t\t\t0x01b /* \"Trying to set multiple out-of-bounds cells!\" */,\n\t\t);\n\n\t\tconst endCol = colStart + colCount;\n\t\tlet r = rowStart;\n\t\tlet c = colStart;\n\n\t\tfor (const value of values) {\n\t\t\tthis.setCellCore(r, c, value);\n\n\t\t\tif (++c === endCol) {\n\t\t\t\tc = colStart;\n\t\t\t\tr++;\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprivate setCellCore(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle = this.rows.getAllocatedHandle(row),\n\t\tcolHandle = this.cols.getAllocatedHandle(col),\n\t) {\n\t\tif (this.undo !== undefined) {\n\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\tif (oldValue === null) {\n\t\t\t\toldValue = undefined;\n\t\t\t}\n\n\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t}\n\n\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\tif (this.isAttached()) {\n\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t}\n\t}\n\n\tprivate sendSetCellOp(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle: Handle,\n\t\tcolHandle: Handle,\n\t\tlocalSeq = this.nextLocalSeq(),\n\t\trowsRefSeq = this.rows.getCollabWindow().currentSeq,\n\t\tcolsRefSeq = this.cols.getCollabWindow().currentSeq,\n\t) {\n\t\tassert(\n\t\t\tthis.isAttached(),\n\t\t\t0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */,\n\t\t);\n\n\t\tconst op: ISetOp<T> = {\n\t\t\ttype: MatrixOp.set,\n\t\t\trow,\n\t\t\tcol,\n\t\t\tvalue,\n\t\t};\n\n\t\tconst metadata: ISetOpMetadata = {\n\t\t\trowHandle,\n\t\t\tcolHandle,\n\t\t\tlocalSeq,\n\t\t\trowsRefSeq,\n\t\t\tcolsRefSeq,\n\t\t};\n\n\t\tthis.submitLocalMessage(op, metadata);\n\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t}\n\n\tprivate submitVectorMessage(\n\t\tcurrentVector: PermutationVector,\n\t\toppositeVector: PermutationVector,\n\t\tdimension: SnapshotPath.rows | SnapshotPath.cols,\n\t\tmessage: any,\n\t) {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n\t\t// for each submitted op it not aware of to keep them synchronized.\n\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t// Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n\t\t// the MergeTree submits the op with the original 'localSeq'.\n\t\tassert(\n\t\t\tlocalSeq >= oppositeWindow.localSeq,\n\t\t\t0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */,\n\t\t);\n\n\t\toppositeWindow.localSeq = localSeq;\n\n\t\t// If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n\t\t// Do not queue a message or track the pending op, as there will never be an ACK, etc.\n\t\tif (this.isAttached()) {\n\t\t\t// Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n\t\t\tmessage.target = dimension;\n\n\t\t\tthis.submitLocalMessage(\n\t\t\t\tmessage,\n\t\t\t\tcurrentVector.peekPendingSegmentGroups(\n\t\t\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate submitColMessage(message: any) {\n\t\tthis.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n\t}\n\n\tpublic insertCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.insert(colStart, count));\n\t}\n\n\tpublic removeCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.remove(colStart, count));\n\t}\n\n\tprivate submitRowMessage(message: any) {\n\t\tthis.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n\t}\n\n\tpublic insertRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.insert(rowStart, count));\n\t}\n\n\tpublic removeRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.remove(rowStart, count));\n\t}\n\n\t/** @internal */ public _undoRemoveRows(rowStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.rows, rowStart, spec);\n\t\tthis.submitRowMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted rows.\n\t\tlet rowHandle = inserted.start;\n\t\tconst rowCount = inserted.cachedLength;\n\t\tfor (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n\t\t}\n\t}\n\n\t/** @internal */ public _undoRemoveCols(colStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.cols, colStart, spec);\n\t\tthis.submitColMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted cols.\n\t\tlet colHandle = inserted.start;\n\t\tconst colCount = inserted.cachedLength;\n\t\tfor (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n\t\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.rows.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.cols.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.cells,\n\t\t\tserializer.stringify([this.cells.snapshot(), this.pending.snapshot()], this.handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer on the GC data for this SharedMatrix.\n\t * All the IFluidHandle's stored in the cells represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tserializer.stringify(this.getCell(row, col), this.handle);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advances the 'localSeq' counter for the cell data operation currently being queued.\n\t *\n\t * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n\t * automatically advance 'localSeq'.\n\t */\n\tprivate nextLocalSeq() {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n\t\t// for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n\t\t// need to bump both counters.)\n\n\t\tthis.cols.getCollabWindow().localSeq++;\n\t\treturn ++this.rows.getCollabWindow().localSeq;\n\t}\n\n\tprotected submitLocalMessage(message: any, localOpMetadata?: any) {\n\t\t// TODO: Recommend moving this assertion into SharedObject\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/2559)\n\t\tassert(\n\t\t\tthis.isAttached() === true,\n\t\t\t0x01d /* \"Trying to submit message to runtime while detached!\" */,\n\t\t);\n\n\t\tsuper.submitLocalMessage(\n\t\t\tmakeHandlesSerializable(message, this.serializer, this.handle),\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\t// Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n\t\t\t0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n\t\t);\n\t}\n\n\tprotected didAttach() {\n\t\t// We've attached we need to start generating and sending ops.\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\tprotected onConnect() {\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n\t\t\t0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */,\n\t\t);\n\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t}\n\n\tprivate rebasePosition(\n\t\tclient: Client,\n\t\tpos: number,\n\t\treferenceSequenceNumber: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tconst { clientId } = client.getCollabWindow();\n\t\tconst { segment, offset } = client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{ referenceSequenceNumber, clientId: client.getLongClientId(clientId) },\n\t\t\tlocalSeq,\n\t\t);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn client.findReconnectionPosition(segment, localSeq) + offset;\n\t}\n\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tswitch (content.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.submitColMessage(\n\t\t\t\t\tthis.cols.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.submitRowMessage(\n\t\t\t\t\tthis.rows.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontent.type === MatrixOp.set,\n\t\t\t\t\t0x020 /* \"Unknown SharedMatrix 'op' type.\" */,\n\t\t\t\t);\n\n\t\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\t\tconst { rowHandle, colHandle, localSeq, rowsRefSeq, colsRefSeq } =\n\t\t\t\t\tlocalOpMetadata as ISetOpMetadata;\n\n\t\t\t\t// If there are more pending local writes to the same row/col handle, it is important\n\t\t\t\t// to skip resubmitting this op since it is possible the row/col handle has been recycled\n\t\t\t\t// and now refers to a different position than when this op was originally submitted.\n\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\tconst row = this.rebasePosition(this.rows, setOp.row, rowsRefSeq, localSeq);\n\t\t\t\t\tconst col = this.rebasePosition(this.cols, setOp.col, colsRefSeq, localSeq);\n\n\t\t\t\t\tif (row !== undefined && col !== undefined && row >= 0 && col >= 0) {\n\t\t\t\t\t\tthis.sendSetCellOp(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tcol,\n\t\t\t\t\t\t\tsetOp.value,\n\t\t\t\t\t\t\trowHandle,\n\t\t\t\t\t\t\tcolHandle,\n\t\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\t\trowsRefSeq,\n\t\t\t\t\t\t\tcolsRefSeq,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\ttry {\n\t\t\tawait this.rows.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.rows),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tawait this.cols.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.cols),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tconst [cellData, pendingCliSeqData] = await deserializeBlob(\n\t\t\t\tstorage,\n\t\t\t\tSnapshotPath.cells,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\tthis.cells = SparseArray2D.load(cellData);\n\t\t\tthis.pending = SparseArray2D.load(pendingCliSeqData);\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\trawMessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tconst msg = parseHandles(rawMessage, this.serializer);\n\n\t\tconst contents = msg.contents;\n\n\t\tswitch (contents.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.cols.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.rows.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontents.type === MatrixOp.set,\n\t\t\t\t\t0x021 /* \"SharedMatrix message contents have unexpected type!\" */,\n\t\t\t\t);\n\n\t\t\t\tconst { row, col } = contents;\n\n\t\t\t\tif (local) {\n\t\t\t\t\t// We are receiving the ACK for a local pending set operation.\n\t\t\t\t\tconst { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n\t\t\t\t\t// If this is the most recent write to the cell by the local client, remove our\n\t\t\t\t\t// entry from 'pendingCliSeqs' to resume allowing remote writes.\n\t\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\t\tthis.pending.setCell(rowHandle, colHandle, undefined);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst adjustedRow = this.rows.adjustPosition(row, rawMessage);\n\n\t\t\t\t\tif (adjustedRow !== undefined) {\n\t\t\t\t\t\tconst adjustedCol = this.cols.adjustPosition(col, rawMessage);\n\n\t\t\t\t\t\tif (adjustedCol !== undefined) {\n\t\t\t\t\t\t\tconst rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n\t\t\t\t\t\t\tconst colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t\t\t\t\t\t0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If there is a pending (unACKed) local write to the same cell, skip the current op\n\t\t\t\t\t\t\t// since it \"happened before\" the pending write.\n\t\t\t\t\t\t\tif (this.pending.getCell(rowHandle, colHandle) === undefined) {\n\t\t\t\t\t\t\t\tconst { value } = contents;\n\t\t\t\t\t\t\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\t\t\t\t\t\t\tfor (const consumer of this.consumers.values()) {\n\t\t\t\t\t\t\t\t\tconsumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n\tprivate readonly onRowDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.rowsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n\tprivate readonly onColDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.colsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\tprivate readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n\t\tfor (const rowHandle of rowHandles) {\n\t\t\tthis.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t\tthis.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t}\n\t};\n\n\tprivate readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n\t\tfor (const colHandle of colHandles) {\n\t\t\tthis.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t\tthis.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t}\n\t};\n\n\t/**\n\t * Returns true if the latest pending write to the cell indicated by the given row/col handles\n\t * matches the given 'localSeq'.\n\t *\n\t * A return value of `true` indicates that there are no later local operations queued that will\n\t * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n\t * with a different value as well as row/col removals that might recycled the given row/col handles.\n\t */\n\tprivate isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n\t\t// Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n\t\t// locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n\t\t// be 'undefined' or > 'localSeq'.\n\t\tassert(\n\t\t\t!(pendingLocalSeq < localSeq),\n\t\t\t0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */,\n\t\t);\n\n\t\t// If this is the most recent write to the cell by the local client, the stored localSeq\n\t\t// will be an exact match for the given 'localSeq'.\n\t\treturn pendingLocalSeq === localSeq;\n\t}\n\n\tpublic toString() {\n\t\tlet s = `client:${\n\t\t\tthis.runtime.clientId\n\t\t}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n\t\tfor (let r = 0; r < this.rowCount; r++) {\n\t\t\ts += ` [`;\n\t\t\tfor (let c = 0; c < this.colCount; c++) {\n\t\t\t\tif (c > 0) {\n\t\t\t\t\ts += \", \";\n\t\t\t\t}\n\n\t\t\t\ts += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n\t\t\t}\n\t\t\ts += \"]\\n\";\n\t\t}\n\n\t\treturn `${s}\\n`;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): unknown {\n\t\tconst parsedContent = parseHandles(content, this.serializer);\n\t\tif (\n\t\t\tparsedContent.target === SnapshotPath.cols ||\n\t\t\tparsedContent.target === SnapshotPath.rows\n\t\t) {\n\t\t\tconst op = parsedContent as IMergeTreeOp;\n\t\t\tconst currentVector =\n\t\t\t\tparsedContent.target === SnapshotPath.cols ? this.cols : this.rows;\n\t\t\tconst oppositeVector =\n\t\t\t\tparsedContent.target === SnapshotPath.cols ? this.rows : this.cols;\n\t\t\tconst metadata = currentVector.applyStashedOp(op);\n\t\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t\tassert(\n\t\t\t\tlocalSeq > oppositeWindow.localSeq,\n\t\t\t\t0x2d9,\n\t\t\t\t/* \"The 'localSeq' of the vector applying stashed op must > the 'localSeq' of the other vector.\" */\n\t\t\t);\n\n\t\t\toppositeWindow.localSeq = localSeq;\n\n\t\t\treturn metadata;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tparsedContent.type === MatrixOp.set,\n\t\t\t\t0x2da /* \"Unknown SharedMatrix 'op' type.\" */,\n\t\t\t);\n\n\t\t\tconst setOp = parsedContent as ISetOp<T>;\n\t\t\tconst rowHandle = this.rows.getAllocatedHandle(setOp.row);\n\t\t\tconst colHandle = this.cols.getAllocatedHandle(setOp.col);\n\t\t\tconst rowsRefSeq = this.rows.getCollabWindow().currentSeq;\n\t\t\tconst colsRefSeq = this.cols.getCollabWindow().currentSeq;\n\t\t\tif (this.undo !== undefined) {\n\t\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (oldValue === null) {\n\t\t\t\t\toldValue = undefined;\n\t\t\t\t}\n\n\t\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t\t}\n\n\t\t\tthis.cells.setCell(rowHandle, colHandle, setOp.value);\n\t\t\tconst localSeq = this.nextLocalSeq();\n\t\t\tconst metadata: ISetOpMetadata = {\n\t\t\t\trowHandle,\n\t\t\t\tcolHandle,\n\t\t\t\tlocalSeq,\n\t\t\t\trowsRefSeq,\n\t\t\t\tcolsRefSeq,\n\t\t\t};\n\n\t\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t\t\treturn metadata;\n\t\t}\n\t}\n}\n"]}
|
package/dist/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 = "2.0.0-internal.6.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.6.4.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/matrix";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.6.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.6.4.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,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 = \"2.0.0-internal.6.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,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 = \"2.0.0-internal.6.4.0\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permutationvector.d.ts","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,WAAW,EACX,QAAQ,EACR,MAAM,EAMN,YAAY,EACZ,MAAM,4BAA4B,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AChB,OAAO,EACP,IAAI,sCAAsB,CAAC,OAAO,4BAAwB,EAC1D,UAAU,CACV,CAAC;IACH,CAAC;IAoGM,QAAQ;QACd,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;CACD;AApSD,8CAoSC;AAED,SAAgB,yBAAyB,CACxC,MAAyB,EACzB,GAAW,EACX,IAAkB;IAElB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,OAA6B,CAAC;IAEhF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,IAAA,2BAAa,EAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAClC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;KAChC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAzBD,8DAyBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tBaseSegment,\n\tISegment,\n\tClient,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tMergeTreeDeltaType,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tMergeTreeMaintenanceType,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { ITelemetryBaseLogger, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: any) {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start() {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset() {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject() {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength) {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment) {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString() {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n\t\t\t},\n\t\t); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number) {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number) {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(pos: number, op: ISequencedDocumentMessage) {\n\t\tconst { segment, offset } = this.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\t// Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n\t\t// a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n\t\t// by checking for the presence of 'removedSeq'.\n\t\tif (segment === undefined || segment.removedSeq !== undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.getPosition(segment) + offset!;\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq) {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t) {\n\t\tconst handleTableData = await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t);\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t) => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t// processing remote ops.\n\t\t\t\t\tsegment.reset();\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tnew Array(asPerm.cachedLength)\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString() {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n) {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos).segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\n\t);\n\treturn { op, inserted };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AACpD,qEAAoE;AAKpE,2DAUoC;AAIpC,iEAA2F;AAE3F,+CAAmE;AACnE,mDAAkD;AAClD,+CAA4C;AAU5C,MAAa,kBAAmB,SAAQ,wBAAW;IAWlD,YAAY,MAAc,EAAE,KAAK,gCAAqB;QACrD,KAAK,EAAE,CAAC;QAVD,WAAM,iCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC5B,CAAC;IAXM,MAAM,CAAC,cAAc,CAAC,IAAS;QACrC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAUD,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,IAAW,KAAK,CAAC,KAAa;QAC7B,IAAA,mBAAM,EACL,IAAI,CAAC,MAAM,kCAAuB,EAClC,KAAK,CAAC,sDAAsD,CAC5D,CAAC;QACF,IAAA,mBAAM,EACL,IAAA,2BAAa,EAAC,KAAK,CAAC,EAC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CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;CACD;AArSD,8CAqSC;AAED,SAAgB,yBAAyB,CACxC,MAAyB,EACzB,GAAW,EACX,IAAkB;IAElB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,OAA6B,CAAC;IAEhF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,IAAA,2BAAa,EAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAClC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;KAChC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC;AAzBD,8DAyBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tBaseSegment,\n\tISegment,\n\tClient,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tMergeTreeDeltaType,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tMergeTreeMaintenanceType,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { ITelemetryBaseLogger, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: any) {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start() {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset() {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject() {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength) {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment) {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString() {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n\t\t\t},\n\t\t); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number) {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number) {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(pos: number, op: ISequencedDocumentMessage) {\n\t\tconst { segment, offset } = this.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\t// Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n\t\t// a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n\t\t// by checking for the presence of 'removedSeq'.\n\t\tif (segment === undefined || segment.removedSeq !== undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.getPosition(segment) + offset!;\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq) {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t) {\n\t\tconst handleTableData = await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t);\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t) => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t// processing remote ops.\n\t\t\t\t\tsegment.reset();\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tnew Array(asPerm.cachedLength)\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString() {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n) {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos).segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\n\t);\n\treturn { op, inserted };\n}\n"]}
|
package/dist/sparsearray2d.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ declare type UA<T> = (T | undefined)[];
|
|
|
12
12
|
export declare class SparseArray2D<T> implements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined> {
|
|
13
13
|
private readonly root;
|
|
14
14
|
constructor(root?: UA<UA<UA<UA<UA<T>>>>>);
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
readonly rowCount = 4294967295;
|
|
16
|
+
readonly colCount = 4294967295;
|
|
17
17
|
getCell(row: number, col: number): T | undefined;
|
|
18
18
|
get matrixProducer(): any;
|
|
19
19
|
setCell(row: number, col: number, value: T | undefined): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparsearray2d.d.ts","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAmC/D,aAAK,gBAAgB,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7C,aAAK,UAAU,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;AAS3C,aAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;AAE/B;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC,CAC3B,YAAW,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC;IAEzD,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,GAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAe;IAEtE,
|
|
1
|
+
{"version":3,"file":"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E,QAAQ,EAAE,MAAM;IA0BnD,OAAO,CAAC,QAAQ;IAMT,QAAQ;WAID,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;CAGzC"}
|
package/dist/sparsearray2d.js
CHANGED
|
@@ -42,12 +42,8 @@ const nullToUndefined = (array) => array.map((value) => {
|
|
|
42
42
|
class SparseArray2D {
|
|
43
43
|
constructor(root = [undefined]) {
|
|
44
44
|
this.root = root;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return 0xffffffff;
|
|
48
|
-
}
|
|
49
|
-
get colCount() {
|
|
50
|
-
return 0xffffffff;
|
|
45
|
+
this.rowCount = 0xffffffff;
|
|
46
|
+
this.colCount = 0xffffffff;
|
|
51
47
|
}
|
|
52
48
|
getCell(row, col) {
|
|
53
49
|
const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);
|
|
@@ -187,7 +183,7 @@ class SparseArray2D {
|
|
|
187
183
|
getLevel(parent, subKey) {
|
|
188
184
|
const level = parent[subKey];
|
|
189
185
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
190
|
-
return level
|
|
186
|
+
return level ?? (parent[subKey] = new Array(256).fill(undefined));
|
|
191
187
|
}
|
|
192
188
|
snapshot() {
|
|
193
189
|
return this.root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparsearray2d.js","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,yDAAyD;AACzD,MAAM,iBAAiB,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;IACjE,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC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\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\n\n// Build a lookup table that maps a uint8 to the corresponding uint16 where 0s\n// are interleaved between the original bits. (e.g., 1111... -> 01010101...).\n//\n// (Lookup table ~17% faster than inlining the bit-twiddling on Node v12 x64)\n// (Array<T> ~2% faster than typed array on Node v12 x64)\nconst x8ToInterlacedX16 = new Array(256).fill(0).map((value, i) => {\n\tlet j = i;\n\tj = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n\tj = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n\tj = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n\treturn j;\n});\n\n// Selects individual bytes from a given 32b integer. The left shift are used to\n// clear upper bits (faster than using masks on Node 10 x64).\nconst byte0 = (x32: number) => x32 >>> 24;\nconst byte1 = (x32: number) => (x32 << 8) >>> 24;\nconst byte2 = (x32: number) => (x32 << 16) >>> 24;\nconst byte3 = (x32: number) => (x32 << 24) >>> 24;\n\n// Given a uint16 returns the corresponding uint32 integer where 0s are\n// interleaved between the original bits. (e.g., 1111... -> 01010101...).\nconst interlaceBitsX16 = (x16: number) =>\n\t(x8ToInterlacedX16[byte2(x16)] << 16) | x8ToInterlacedX16[byte3(x16)];\n\nconst r0ToMorton16 = (row: number) => (interlaceBitsX16(row) << 1) >>> 0;\nconst c0ToMorton16 = (col: number) => interlaceBitsX16(col) >>> 0;\n\n// Given a 2D uint16 coordinate returns the corresponding unt32 Morton coded\n// coordinate. (See https://en.wikipedia.org/wiki/Z-order_curve)\nconst r0c0ToMorton2x16 = (row: number, col: number) =>\n\t(r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;\n\ntype RecurArrayHelper<T> = RecurArray<T> | T;\ntype RecurArray<T> = RecurArrayHelper<T>[];\n\n/** Undo JSON serialization's coercion of 'undefined' to null. */\n// eslint-disable-next-line @rushstack/no-new-null -- Private use of 'null' to preserve 'undefined'\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> =>\n\tarray.map((value) => {\n\t\treturn value === null ? undefined : Array.isArray(value) ? nullToUndefined(value) : value;\n\t});\n\ntype UA<T> = (T | undefined)[];\n\n/**\n * A sparse 4 billion x 4 billion array stored as 16x16 tiles.\n */\nexport class SparseArray2D<T>\n\timplements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined>\n{\n\tconstructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) {}\n\n\tpublic get rowCount() {\n\t\treturn 0xffffffff;\n\t}\n\tpublic get colCount() {\n\t\treturn 0xffffffff;\n\t}\n\n\tpublic getCell(row: number, col: number): T | undefined {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst level0 = this.root[keyHi];\n\t\tif (level0 !== undefined) {\n\t\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\t\t\tconst level1 = level0[byte0(keyLo)];\n\t\t\tif (level1 !== undefined) {\n\t\t\t\tconst level2 = level1[byte1(keyLo)];\n\t\t\t\tif (level2 !== undefined) {\n\t\t\t\t\tconst level3 = level2[byte2(keyLo)];\n\t\t\t\t\tif (level3 !== undefined) {\n\t\t\t\t\t\treturn level3[byte3(keyLo)];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn undefined as any;\n\t}\n\n\tpublic setCell(row: number, col: number, value: T | undefined) {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\n\t\tconst level0 = this.getLevel(this.root, keyHi);\n\t\tconst level1 = this.getLevel(level0, byte0(keyLo));\n\t\tconst level2 = this.getLevel(level1, byte1(keyLo));\n\t\tconst level3 = this.getLevel(level2, byte2(keyLo));\n\t\tlevel3[byte3(keyLo)] = value;\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n\t\tfor (let col = 0; col < 16; col++) {\n\t\t\t// Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n\t\t\tcallback((rowBits | c0ToMorton16(col)) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInCol(col: number, callback: (key: number) => void) {\n\t\tfor (let row = 0; row < 16; row++) {\n\t\t\t// Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n\t\t\tcallback((r0ToMorton16(row) | col) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given row in the 'currentLevel'.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInRow<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\trowBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInRow(rowBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given col in the 'currentLevel'.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInCol<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\tcolBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInCol(colBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Clears the all cells contained within the specified span of rows. */\n\tpublic clearRows(rowStart: number, rowCount: number) {\n\t\tconst rowEnd = rowStart + rowCount;\n\t\tfor (let row = rowStart; row < rowEnd; row++) {\n\t\t\tconst rowHi = r0ToMorton16(row >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let colHi = 0; colHi < 0x10000; colHi++) {\n\t\t\t\tconst keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst rowLo = r0ToMorton16(row);\n\t\t\t\t\tthis.forEachInRow(level0, byte0(rowLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInRow(level1, byte1(rowLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInRow(level2, byte2(rowLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInRow(byte3(rowLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Clears the all cells contained within the specifed span of cols. */\n\tpublic clearCols(colStart: number, colCount: number) {\n\t\tconst colEnd = colStart + colCount;\n\t\tfor (let col = colStart; col < colEnd; col++) {\n\t\t\tconst colHi = c0ToMorton16(col >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n\t\t\t\tconst keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst colLo = c0ToMorton16(col);\n\t\t\t\t\tthis.forEachInCol(level0, byte0(colLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInCol(level1, byte1(colLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInCol(level2, byte2(colLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInCol(byte3(colLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n\t\tconst level = parent[subKey];\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn level === undefined ? (parent[subKey] = new Array(256).fill(undefined)) : level;\n\t}\n\n\tpublic snapshot() {\n\t\treturn this.root;\n\t}\n\n\tpublic static load<T>(data: RecurArray<T>) {\n\t\treturn new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sparsearray2d.js","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,yDAAyD;AACzD,MAAM,iBAAiB,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;IACjE,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,CA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Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\n\n// Build a lookup table that maps a uint8 to the corresponding uint16 where 0s\n// are interleaved between the original bits. (e.g., 1111... -> 01010101...).\n//\n// (Lookup table ~17% faster than inlining the bit-twiddling on Node v12 x64)\n// (Array<T> ~2% faster than typed array on Node v12 x64)\nconst x8ToInterlacedX16 = new Array(256).fill(0).map((value, i) => {\n\tlet j = i;\n\tj = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n\tj = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n\tj = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n\treturn j;\n});\n\n// Selects individual bytes from a given 32b integer. The left shift are used to\n// clear upper bits (faster than using masks on Node 10 x64).\nconst byte0 = (x32: number) => x32 >>> 24;\nconst byte1 = (x32: number) => (x32 << 8) >>> 24;\nconst byte2 = (x32: number) => (x32 << 16) >>> 24;\nconst byte3 = (x32: number) => (x32 << 24) >>> 24;\n\n// Given a uint16 returns the corresponding uint32 integer where 0s are\n// interleaved between the original bits. (e.g., 1111... -> 01010101...).\nconst interlaceBitsX16 = (x16: number) =>\n\t(x8ToInterlacedX16[byte2(x16)] << 16) | x8ToInterlacedX16[byte3(x16)];\n\nconst r0ToMorton16 = (row: number) => (interlaceBitsX16(row) << 1) >>> 0;\nconst c0ToMorton16 = (col: number) => interlaceBitsX16(col) >>> 0;\n\n// Given a 2D uint16 coordinate returns the corresponding unt32 Morton coded\n// coordinate. (See https://en.wikipedia.org/wiki/Z-order_curve)\nconst r0c0ToMorton2x16 = (row: number, col: number) =>\n\t(r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;\n\ntype RecurArrayHelper<T> = RecurArray<T> | T;\ntype RecurArray<T> = RecurArrayHelper<T>[];\n\n/** Undo JSON serialization's coercion of 'undefined' to null. */\n// eslint-disable-next-line @rushstack/no-new-null -- Private use of 'null' to preserve 'undefined'\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> =>\n\tarray.map((value) => {\n\t\treturn value === null ? undefined : Array.isArray(value) ? nullToUndefined(value) : value;\n\t});\n\ntype UA<T> = (T | undefined)[];\n\n/**\n * A sparse 4 billion x 4 billion array stored as 16x16 tiles.\n */\nexport class SparseArray2D<T>\n\timplements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined>\n{\n\tconstructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) {}\n\n\tpublic readonly rowCount = 0xffffffff;\n\tpublic readonly colCount = 0xffffffff;\n\n\tpublic getCell(row: number, col: number): T | undefined {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst level0 = this.root[keyHi];\n\t\tif (level0 !== undefined) {\n\t\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\t\t\tconst level1 = level0[byte0(keyLo)];\n\t\t\tif (level1 !== undefined) {\n\t\t\t\tconst level2 = level1[byte1(keyLo)];\n\t\t\t\tif (level2 !== undefined) {\n\t\t\t\t\tconst level3 = level2[byte2(keyLo)];\n\t\t\t\t\tif (level3 !== undefined) {\n\t\t\t\t\t\treturn level3[byte3(keyLo)];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn undefined as any;\n\t}\n\n\tpublic setCell(row: number, col: number, value: T | undefined) {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\n\t\tconst level0 = this.getLevel(this.root, keyHi);\n\t\tconst level1 = this.getLevel(level0, byte0(keyLo));\n\t\tconst level2 = this.getLevel(level1, byte1(keyLo));\n\t\tconst level3 = this.getLevel(level2, byte2(keyLo));\n\t\tlevel3[byte3(keyLo)] = value;\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n\t\tfor (let col = 0; col < 16; col++) {\n\t\t\t// Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n\t\t\tcallback((rowBits | c0ToMorton16(col)) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInCol(col: number, callback: (key: number) => void) {\n\t\tfor (let row = 0; row < 16; row++) {\n\t\t\t// Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n\t\t\tcallback((r0ToMorton16(row) | col) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given row in the 'currentLevel'.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInRow<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\trowBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInRow(rowBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given col in the 'currentLevel'.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInCol<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\tcolBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInCol(colBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Clears the all cells contained within the specified span of rows. */\n\tpublic clearRows(rowStart: number, rowCount: number) {\n\t\tconst rowEnd = rowStart + rowCount;\n\t\tfor (let row = rowStart; row < rowEnd; row++) {\n\t\t\tconst rowHi = r0ToMorton16(row >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let colHi = 0; colHi < 0x10000; colHi++) {\n\t\t\t\tconst keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst rowLo = r0ToMorton16(row);\n\t\t\t\t\tthis.forEachInRow(level0, byte0(rowLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInRow(level1, byte1(rowLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInRow(level2, byte2(rowLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInRow(byte3(rowLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Clears the all cells contained within the specifed span of cols. */\n\tpublic clearCols(colStart: number, colCount: number) {\n\t\tconst colEnd = colStart + colCount;\n\t\tfor (let col = colStart; col < colEnd; col++) {\n\t\t\tconst colHi = c0ToMorton16(col >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n\t\t\t\tconst keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst colLo = c0ToMorton16(col);\n\t\t\t\t\tthis.forEachInCol(level0, byte0(colLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInCol(level1, byte1(colLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInCol(level2, byte2(colLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInCol(byte3(colLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n\t\tconst level = parent[subKey];\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn level ?? (parent[subKey] = new Array(256).fill(undefined));\n\t}\n\n\tpublic snapshot() {\n\t\treturn this.root;\n\t}\n\n\tpublic static load<T>(data: RecurArray<T>) {\n\t\treturn new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n\t}\n}\n"]}
|
package/lib/matrix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,gBAAgB,EAGhB,YAAY,EACZ,iBAAiB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,E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