@fluidframework/matrix 0.56.7 → 0.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,+DAAsD;AAEtD,+CAAsD;AAEtD,mCAAsC;AAEtC;;;;;GAKG;AACH,MAAa,WAAW;IAIpB,YAA4B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAH7C,YAAO,GAAa,EAAE,CAAC;QACvB,UAAK,GAAG,CAAC,CAAC;IAEuC,CAAC;IAE1D;;;OAGG;IACK,QAAQ,CAAC,QAAgB;QAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,SAAS,CAAC,QAAgB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEtC,uFAAuF;QACvF,8BAA8B;QAE9B,oFAAoF;QACpF,qFAAqF;QACrF,uEAAuE;QAEvE,OAAO,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;YAC9B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACrB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,8EAA8E;IACvE,SAAS,CAAC,QAAgB,EAAE,MAAc;QAC7C,qBAAM,CAAC,2BAAa,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAE3E,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC7B,qBAAM,CAAC,CAAC,2BAAa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YAEhD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;YACrG,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAChD;IACL,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACnE,8EAA8E;QAC9E,6EAA6E;QAC7E,aAAa;QACb,EAAE;QACF,4EAA4E;QAC5E,wBAAwB;QACxB,EAAE;QACF,6FAA6F;QAC7F,2EAA2E;QAC3E,EAAE;QACF,gFAAgF;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAI,KAAK,CAAC;SAChC;IACL,CAAC;CAGJ;AAjHD,kCAiHC","sourcesContent":["/*!\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 { assert } from \"@fluidframework/common-utils\";\nimport { IVectorConsumer } from \"@tiny-calc/nano\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { ensureRange } from \"./range\";\n\n/**\n * Used by PermutationVector to cache position -> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n private handles: Handle[] = [];\n private start = 0;\n\n constructor(public readonly vector: PermutationVector) { }\n\n /**\n * Returns the index of the given position in the 'handles' array as a Uint32.\n * (If the position is not in the array, returns an integer greater than 'handles.length').\n */\n private getIndex(position: number) {\n return (position - this.start) >>> 0;\n }\n\n /**\n * Returns the handle currently assigned to the given 'position' (if any). Check\n * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n * the given position.\n *\n * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n * PermutationVector's length.\n */\n public getHandle(position: number) {\n const index = this.getIndex(position);\n\n // Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n // to a separate method.\n\n // Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n // checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n // ~40% speedup when the position is in the cache (node v12 x64).\n\n return index < this.handles.length\n ? this.handles[index]\n : this.cacheMiss(position);\n }\n\n /** Update the cache when a handle has been allocated for a given position. */\n public addHandle(position: number, handle: Handle) {\n assert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n const index = this.getIndex(position);\n if (index < this.handles.length) {\n assert(!isHandleValid(this.handles[index]),\n 0x018 /* \"Trying to insert handle into position with already valid handle!\" */);\n this.handles[index] = handle;\n }\n }\n\n /** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n private getHandles(start: number, end: number) {\n // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n // is that\n\n const handles: Handle[] = [];\n const { vector } = this;\n\n for (let pos = start; pos < end; pos++) {\n const { segment, offset } = vector.getContainingSegment(pos);\n const asPerm = segment as PermutationSegment;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n handles.push(asPerm.start + offset!);\n }\n\n return handles;\n }\n\n private cacheMiss(position: number) {\n // Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n // with the same logic that handles 'position' >= length.\n const _position = position >>> 0;\n\n // TODO: To bound memory usage, there should be a limit on the maximum size of\n // handle[].\n\n // TODO: To reduce MergeTree lookups, this code should opportunistically grow\n // the cache to the next MergeTree segment boundary (within the limits of\n // the handle cache).\n\n if (_position < this.start) {\n this.handles = this.getHandles(_position, this.start).concat(this.handles);\n this.start = _position;\n return this.handles[0];\n } else {\n ensureRange(_position, this.vector.getLength());\n\n this.handles = this.handles.concat(this.getHandles(this.start + this.handles.length, _position + 1));\n return this.handles[this.handles.length - 1];\n }\n }\n\n // #region IVectorConsumer\n\n itemsChanged(start: number, removedCount: number, insertedCount: number): void {\n // If positions were inserted/removed, our current policy is to trim the array\n // at the beginning of the invalidate range and lazily repopulate the handles\n // on demand.\n //\n // Some alternatives to consider that preserve the previously cached handles\n // that are still valid:\n //\n // * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n // to be Handle.unallocated, so we don't even need to look them up.)\n //\n // * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n const index = this.getIndex(start);\n if (index < this.handles.length) {\n this.handles.length = index;\n }\n }\n\n // #endregion IVectorConsumer\n}\n"]}
1
+ {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,+DAAsD;AAEtD,+CAAsD;AAEtD,mCAAsC;AAEtC;;;;;GAKG;AACH,MAAa,WAAW;IAIpB,YAA4B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAH7C,YAAO,GAAa,EAAE,CAAC;QACvB,UAAK,GAAG,CAAC,CAAC;IAEuC,CAAC;IAE1D;;;OAGG;IACK,QAAQ,CAAC,QAAgB;QAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,SAAS,CAAC,QAAgB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEtC,uFAAuF;QACvF,8BAA8B;QAE9B,oFAAoF;QACpF,qFAAqF;QACrF,uEAAuE;QAEvE,OAAO,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;YAC9B,CAAC,CAA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;QAC7E,+EAA+E;QAC/E,2BAA2B;QAE3B,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE;YACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC3E,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SAC1B;aAAM;YACH,mBAAW,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;YAEhD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;YACrG,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAChD;IACL,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACnE,8EAA8E;QAC9E,6EAA6E;QAC7E,aAAa;QACb,EAAE;QACF,4EAA4E;QAC5E,wBAAwB;QACxB,EAAE;QACF,6FAA6F;QAC7F,2EAA2E;QAC3E,EAAE;QACF,gFAAgF;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;SAC/B;IACL,CAAC;CAGJ;AAjHD,kCAiHC","sourcesContent":["/*!\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 { assert } from \"@fluidframework/common-utils\";\nimport { IVectorConsumer } from \"@tiny-calc/nano\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { ensureRange } from \"./range\";\n\n/**\n * Used by PermutationVector to cache position -> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n private handles: Handle[] = [];\n private start = 0;\n\n constructor(public readonly vector: PermutationVector) { }\n\n /**\n * Returns the index of the given position in the 'handles' array as a Uint32.\n * (If the position is not in the array, returns an integer greater than 'handles.length').\n */\n private getIndex(position: number) {\n return (position - this.start) >>> 0;\n }\n\n /**\n * Returns the handle currently assigned to the given 'position' (if any). Check\n * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n * the given position.\n *\n * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n * PermutationVector's length.\n */\n public getHandle(position: number) {\n const index = this.getIndex(position);\n\n // Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n // to a separate method.\n\n // Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n // checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n // ~40% speedup when the position is in the cache (node v12 x64).\n\n return index < this.handles.length\n ? this.handles[index]\n : this.cacheMiss(position);\n }\n\n /** Update the cache when a handle has been allocated for a given position. */\n public addHandle(position: number, handle: Handle) {\n assert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n const index = this.getIndex(position);\n if (index < this.handles.length) {\n assert(!isHandleValid(this.handles[index]),\n 0x018 /* \"Trying to insert handle into position with already valid handle!\" */);\n this.handles[index] = handle;\n }\n }\n\n /** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n private getHandles(start: number, end: number) {\n // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n // is that\n\n const handles: Handle[] = [];\n const { vector } = this;\n\n for (let pos = start; pos < end; pos++) {\n const { segment, offset } = vector.getContainingSegment(pos);\n const asPerm = segment as PermutationSegment;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n handles.push(asPerm.start + offset!);\n }\n\n return handles;\n }\n\n private cacheMiss(position: number) {\n // Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n // with the same logic that handles 'position' >= length.\n const _position = position >>> 0;\n\n // TODO: To bound memory usage, there should be a limit on the maximum size of\n // handle[].\n\n // TODO: To reduce MergeTree lookups, this code should opportunistically grow\n // the cache to the next MergeTree segment boundary (within the limits of\n // the handle cache).\n\n if (_position < this.start) {\n this.handles = this.getHandles(_position, this.start).concat(this.handles);\n this.start = _position;\n return this.handles[0];\n } else {\n ensureRange(_position, this.vector.getLength());\n\n this.handles = this.handles.concat(this.getHandles(this.start + this.handles.length, _position + 1));\n return this.handles[this.handles.length - 1];\n }\n }\n\n // #region IVectorConsumer\n\n itemsChanged(start: number, removedCount: number, insertedCount: number): void {\n // If positions were inserted/removed, our current policy is to trim the array\n // at the beginning of the invalidate range and lazily repopulate the handles\n // on demand.\n //\n // Some alternatives to consider that preserve the previously cached handles\n // that are still valid:\n //\n // * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n // to be Handle.unallocated, so we don't even need to look them up.)\n //\n // * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n const index = this.getIndex(start);\n if (index < this.handles.length) {\n this.handles.length = index;\n }\n }\n\n // #endregion IVectorConsumer\n}\n"]}
package/dist/matrix.d.ts CHANGED
@@ -89,7 +89,6 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
89
89
  */
90
90
  protected loadCore(storage: IChannelStorageService): Promise<void>;
91
91
  protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
92
- protected registerCore(): void;
93
92
  private readonly onRowDelta;
94
93
  private readonly onColDelta;
95
94
  private readonly onRowHandlesRecycled;
@@ -1 +1 @@
1
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AAM;IAIjD,gBAAgB,CAAQ,eAAe,CAAC,OAAO,EAAE,QAAQ;IA2CzD,gBAAgB,CAAQ,eAAe,CAAC,OAAO,EAAE,QAAQ;IA2CzD,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAY5E;;;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;IAchE,SAAS,CAAC,SAAS;IASnB,SAAS,CAAC,SAAS;IASnB,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO;IAyC7D,SAAS,CAAC,YAAY;IAEtB;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAmBxD,SAAS,CAAC,WAAW,CAAC,UAAU,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IA6DrG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIzB;IAGF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIzB;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAgBrB,QAAQ;IAkBf,SAAS,CAAC,cAAc;CAG3B"}
package/dist/matrix.js CHANGED
@@ -145,7 +145,6 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
145
145
  setCellCore(row, col, value, rowHandle = this.rows.getAllocatedHandle(row), colHandle = this.cols.getAllocatedHandle(col)) {
146
146
  if (this.undo !== undefined) {
147
147
  let oldValue = this.cells.getCell(rowHandle, colHandle);
148
- // eslint-disable-next-line no-null/no-null
149
148
  if (oldValue === null) {
150
149
  oldValue = undefined;
151
150
  }
@@ -231,7 +230,6 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
231
230
  for (let col = 0; col < this.colCount; col++) {
232
231
  const colHandle = this.colHandles.getHandle(col);
233
232
  const value = this.cells.getCell(rowHandle, colHandle);
234
- // eslint-disable-next-line no-null/no-null
235
233
  if (this.isAttached() && value !== undefined && value !== null) {
236
234
  this.sendSetCellOp(row, col, value, rowHandle, colHandle);
237
235
  }
@@ -263,7 +261,6 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
263
261
  for (let row = 0; row < this.rowCount; row++) {
264
262
  const rowHandle = this.rowHandles.getHandle(row);
265
263
  const value = this.cells.getCell(rowHandle, colHandle);
266
- // eslint-disable-next-line no-null/no-null
267
264
  if (this.isAttached() && value !== undefined && value !== null) {
268
265
  this.sendSetCellOp(row, col, value, rowHandle, colHandle);
269
266
  }
@@ -422,10 +419,6 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
422
419
  }
423
420
  }
424
421
  }
425
- registerCore() {
426
- this.rows.startOrUpdateCollaboration(this.runtime.clientId, 0);
427
- this.cols.startOrUpdateCollaboration(this.runtime.clientId, 0);
428
- }
429
422
  /**
430
423
  * Returns true if the latest pending write to the cell indicated by the given row/col handles
431
424
  * matches the given 'localSeq'.
@@ -1 +1 @@
1
- {"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAQtD,2EAM4C;AAE5C,iEAA2F;AAQ3F,+BAAiC;AACjC,2DAA4E;AAC5E,mDAAgD;AAChD,uCAAgD;AAChD,+CAAsD;AACtD,mDAAkD;AAClD,mCAAsC;AAEtC,iDAAoD;AA2BpD;;;;;;;;;;;GAWG;AACH,MAAa,YACT,SAAQ,iCAAY;IAepB,YAAY,OAA+B,EAAS,EAAU,EAAE,UAA8B;QAC1F,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QADiB,OAAE,GAAF,EAAE,CAAQ;QA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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;gBACpC,IAAI,CAAC,GAAG,CAAC,EAAE;oBACP,CAAC,IAAI,IAAI,CAAC;iBACb;gBAED,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;aACxE;YACD,CAAC,IAAI,KAAK,CAAC;SACd;QAED,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AAjnBD,oCAinBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set,\n row: number,\n col: number,\n value: MatrixItem<T>,\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle,\n colHandle: Handle,\n localSeq: number,\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>>\n{\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n\n // eslint-disable-next-line no-null/no-null\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n // eslint-disable-next-line no-null/no-null\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n // eslint-disable-next-line no-null/no-null\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<Serializable<T>>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n protected registerCore() {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId, 0);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId, 0);\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
1
+ {"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAQtD,2EAM4C;AAE5C,iEAA2F;AAQ3F,+BAAiC;AACjC,2DAA4E;AAC5E,mDAAgD;AAChD,uCAAgD;AAChD,+CAAsD;AACtD,mDAAkD;AAClD,mCAAsC;AAEtC,iDAAoD;AA2BpD;;;;;;;;;;;GAWG;AACH,MAAa,YACT,SAAQ,iCAAY;IAepB,YAAY,OAA+B,EAAS,EAAU,EAAE,UAA8B;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AAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;aACxE;YACD,CAAC,IAAI,KAAK,CAAC;SACd;QAED,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AAxmBD,oCAwmBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set,\n row: number,\n col: number,\n value: MatrixItem<T>,\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle,\n colHandle: Handle,\n localSeq: number,\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>>\n{\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<Serializable<T>>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "0.56.7";
8
+ export declare const pkgVersion = "0.57.1";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -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 = "0.56.7";
11
+ exports.pkgVersion = "0.57.1";
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,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.56.7\";\n"]}
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,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.57.1\";\n"]}
@@ -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;AAkC/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;AAY3C,aAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;AAE/B;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC;IACnF,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,IAAW,QAAQ,WAAyB;IAC5C,IAAW,QAAQ,WAAyB;IAErC,OAAO,CAAC,GAAG,EAAE,MAAM,EAA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AE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAe;IAEtE,IAAW,QAAQ,WAAyB;IAC5C,IAAW,QAAQ,WAAyB;IAErC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAqBvD,IAAW,cAAc,QAA+B;IAEjD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS;IAW7D;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAOvB;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAOvB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAapB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAapB,wEAAwE;IACjE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA0BnD,uEAAuE;IAChE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA0BnD,OAAO,CAAC,QAAQ;IAQT,QAAQ;WAID,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;CAG5C"}
@@ -33,7 +33,6 @@ const c0ToMorton16 = (col) => interlaceBitsX16(col) >>> 0;
33
33
  const r0c0ToMorton2x16 = (row, col) => (r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;
34
34
  /** Undo JSON serialization's coercion of 'undefined' to null. */
35
35
  const nullToUndefined = (array) => array.map((value) => {
36
- // eslint-disable-next-line no-null/no-null
37
36
  return value === null
38
37
  ? undefined
39
38
  : Array.isArray(value)
@@ -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,GAC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,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACrC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACtF,CAAC;CACJ;AA/KD,sCA+KC","sourcesContent":["/*!\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 =\n new Array(256).fill(0).map((value, i) => {\n let j = i;\n j = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n j = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n j = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n return 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) => (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) => (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. */\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> => array.map((value) => {\n // eslint-disable-next-line no-null/no-null\n return value === null\n ? undefined\n : Array.isArray(value)\n ? nullToUndefined(value)\n : value;\n});\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> implements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined> {\n constructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) { }\n\n public get rowCount() { return 0xFFFFFFFF; }\n public get colCount() { return 0xFFFFFFFF; }\n\n public getCell(row: number, col: number): T | undefined {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n const keyLo = r0c0ToMorton2x16(row, col);\n const level1 = level0[byte0(keyLo)];\n if (level1 !== undefined) {\n const level2 = level1[byte1(keyLo)];\n if (level2 !== undefined) {\n const level3 = level2[byte2(keyLo)];\n if (level3 !== undefined) {\n return level3[byte3(keyLo)];\n }\n }\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n public get matrixProducer() { return undefined as any; }\n\n public setCell(row: number, col: number, value: T | undefined) {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const keyLo = r0c0ToMorton2x16(row, col);\n\n const level0 = this.getLevel(this.root, keyHi);\n const level1 = this.getLevel(level0, byte0(keyLo));\n const level2 = this.getLevel(level1, byte1(keyLo));\n const level3 = this.getLevel(level2, byte2(keyLo));\n level3[byte3(keyLo)] = value;\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n for (let col = 0; col < 16; col++) {\n // Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n callback((rowBits | c0ToMorton16(col)) >>> 0);\n }\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInCol(col: number, callback: (key: number) => void) {\n for (let row = 0; row < 16; row++) {\n // Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n callback((r0ToMorton16(row) | col) >>> 0);\n }\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given row in the 'currentLevel'.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInRow<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n rowBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInRow(rowBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given col in the 'currentLevel'.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInCol<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n colBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInCol(colBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /** Clears the all cells contained within the specified span of rows. */\n public clearRows(rowStart: number, rowCount: number) {\n const rowEnd = rowStart + rowCount;\n for (let row = rowStart; row < rowEnd; row++) {\n const rowHi = r0ToMorton16(row >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let colHi = 0; colHi < 0x10000; colHi++) {\n const keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const rowLo = r0ToMorton16(row);\n this.forEachInRow(level0, byte0(rowLo), (level1) => {\n this.forEachInRow(level1, byte1(rowLo), (level2) => {\n this.forEachInRow(level2, byte2(rowLo), (level3) => {\n this.forEachKeyInRow(byte3(rowLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n /** Clears the all cells contained within the specifed span of cols. */\n public clearCols(colStart: number, colCount: number) {\n const colEnd = colStart + colCount;\n for (let col = colStart; col < colEnd; col++) {\n const colHi = c0ToMorton16(col >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n const keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const colLo = c0ToMorton16(col);\n this.forEachInCol(level0, byte0(colLo), (level1) => {\n this.forEachInCol(level1, byte1(colLo), (level2) => {\n this.forEachInCol(level2, byte2(colLo), (level3) => {\n this.forEachKeyInCol(byte3(colLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n private getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n const level = parent[subKey];\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return level === undefined\n ? (parent[subKey] = new Array(256).fill(undefined))\n : level;\n }\n\n public snapshot() {\n return this.root;\n }\n\n public static load<T>(data: RecurArray<T>) {\n return new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n }\n}\n"]}
1
+ {"version":3,"file":"sparsearray2d.js","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,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C,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC,CAAC,KAAK,CAAC;IAChB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACrC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACtF,CAAC;CACJ;AA/KD,sCA+KC","sourcesContent":["/*!\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 =\n new Array(256).fill(0).map((value, i) => {\n let j = i;\n j = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n j = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n j = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n return 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) => (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) => (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. */\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> => array.map((value) => {\n return value === null\n ? undefined\n : Array.isArray(value)\n ? nullToUndefined(value)\n : value;\n});\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> implements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined> {\n constructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) { }\n\n public get rowCount() { return 0xFFFFFFFF; }\n public get colCount() { return 0xFFFFFFFF; }\n\n public getCell(row: number, col: number): T | undefined {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n const keyLo = r0c0ToMorton2x16(row, col);\n const level1 = level0[byte0(keyLo)];\n if (level1 !== undefined) {\n const level2 = level1[byte1(keyLo)];\n if (level2 !== undefined) {\n const level3 = level2[byte2(keyLo)];\n if (level3 !== undefined) {\n return level3[byte3(keyLo)];\n }\n }\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n public get matrixProducer() { return undefined as any; }\n\n public setCell(row: number, col: number, value: T | undefined) {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const keyLo = r0c0ToMorton2x16(row, col);\n\n const level0 = this.getLevel(this.root, keyHi);\n const level1 = this.getLevel(level0, byte0(keyLo));\n const level2 = this.getLevel(level1, byte1(keyLo));\n const level3 = this.getLevel(level2, byte2(keyLo));\n level3[byte3(keyLo)] = value;\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n for (let col = 0; col < 16; col++) {\n // Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n callback((rowBits | c0ToMorton16(col)) >>> 0);\n }\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInCol(col: number, callback: (key: number) => void) {\n for (let row = 0; row < 16; row++) {\n // Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n callback((r0ToMorton16(row) | col) >>> 0);\n }\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given row in the 'currentLevel'.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInRow<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n rowBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInRow(rowBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given col in the 'currentLevel'.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInCol<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n colBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInCol(colBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /** Clears the all cells contained within the specified span of rows. */\n public clearRows(rowStart: number, rowCount: number) {\n const rowEnd = rowStart + rowCount;\n for (let row = rowStart; row < rowEnd; row++) {\n const rowHi = r0ToMorton16(row >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let colHi = 0; colHi < 0x10000; colHi++) {\n const keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const rowLo = r0ToMorton16(row);\n this.forEachInRow(level0, byte0(rowLo), (level1) => {\n this.forEachInRow(level1, byte1(rowLo), (level2) => {\n this.forEachInRow(level2, byte2(rowLo), (level3) => {\n this.forEachKeyInRow(byte3(rowLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n /** Clears the all cells contained within the specifed span of cols. */\n public clearCols(colStart: number, colCount: number) {\n const colEnd = colStart + colCount;\n for (let col = colStart; col < colEnd; col++) {\n const colHi = c0ToMorton16(col >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n const keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const colLo = c0ToMorton16(col);\n this.forEachInCol(level0, byte0(colLo), (level1) => {\n this.forEachInCol(level1, byte1(colLo), (level2) => {\n this.forEachInCol(level2, byte2(colLo), (level3) => {\n this.forEachKeyInCol(byte3(colLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n private getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n const level = parent[subKey];\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return level === undefined\n ? (parent[subKey] = new Array(256).fill(undefined))\n : level;\n }\n\n public snapshot() {\n return this.root;\n }\n\n public static load<T>(data: RecurArray<T>) {\n return new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"handlecache.js","sourceRoot":"","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CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;YACrG,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAChD;IACL,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACnE,8EAA8E;QAC9E,6EAA6E;QAC7E,aAAa;QACb,EAAE;QACF,4EAA4E;QAC5E,wBAAwB;QACxB,EAAE;QACF,6FAA6F;QAC7F,2EAA2E;QAC3E,EAAE;QACF,gFAAgF;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAI,KAAK,CAAC;SAChC;IACL,CAAC;CAGJ","sourcesContent":["/*!\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 { assert } from \"@fluidframework/common-utils\";\nimport { IVectorConsumer } from \"@tiny-calc/nano\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { ensureRange } from \"./range\";\n\n/**\n * Used by PermutationVector to cache position -> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n private handles: Handle[] = [];\n private start = 0;\n\n constructor(public readonly vector: PermutationVector) { }\n\n /**\n * Returns the index of the given position in the 'handles' array as a Uint32.\n * (If the position is not in the array, returns an integer greater than 'handles.length').\n */\n private getIndex(position: number) {\n return (position - this.start) >>> 0;\n }\n\n /**\n * Returns the handle currently assigned to the given 'position' (if any). Check\n * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n * the given position.\n *\n * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n * PermutationVector's length.\n */\n public getHandle(position: number) {\n const index = this.getIndex(position);\n\n // Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n // to a separate method.\n\n // Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n // checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n // ~40% speedup when the position is in the cache (node v12 x64).\n\n return index < this.handles.length\n ? this.handles[index]\n : this.cacheMiss(position);\n }\n\n /** Update the cache when a handle has been allocated for a given position. */\n public addHandle(position: number, handle: Handle) {\n assert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n const index = this.getIndex(position);\n if (index < this.handles.length) {\n assert(!isHandleValid(this.handles[index]),\n 0x018 /* \"Trying to insert handle into position with already valid handle!\" */);\n this.handles[index] = handle;\n }\n }\n\n /** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n private getHandles(start: number, end: number) {\n // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n // is that\n\n const handles: Handle[] = [];\n const { vector } = this;\n\n for (let pos = start; pos < end; pos++) {\n const { segment, offset } = vector.getContainingSegment(pos);\n const asPerm = segment as PermutationSegment;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n handles.push(asPerm.start + offset!);\n }\n\n return handles;\n }\n\n private cacheMiss(position: number) {\n // Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n // with the same logic that handles 'position' >= length.\n const _position = position >>> 0;\n\n // TODO: To bound memory usage, there should be a limit on the maximum size of\n // handle[].\n\n // TODO: To reduce MergeTree lookups, this code should opportunistically grow\n // the cache to the next MergeTree segment boundary (within the limits of\n // the handle cache).\n\n if (_position < this.start) {\n this.handles = this.getHandles(_position, this.start).concat(this.handles);\n this.start = _position;\n return this.handles[0];\n } else {\n ensureRange(_position, this.vector.getLength());\n\n this.handles = this.handles.concat(this.getHandles(this.start + this.handles.length, _position + 1));\n return this.handles[this.handles.length - 1];\n }\n }\n\n // #region IVectorConsumer\n\n itemsChanged(start: number, removedCount: number, insertedCount: number): void {\n // If positions were inserted/removed, our current policy is to trim the array\n // at the beginning of the invalidate range and lazily repopulate the handles\n // on demand.\n //\n // Some alternatives to consider that preserve the previously cached handles\n // that are still valid:\n //\n // * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n // to be Handle.unallocated, so we don't even need to look them up.)\n //\n // * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n const index = this.getIndex(start);\n if (index < this.handles.length) {\n this.handles.length = index;\n }\n }\n\n // #endregion IVectorConsumer\n}\n"]}
1
+ {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+BAA+B;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAIpB,YAA4B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAH7C,YAAO,GAAa,EAAE,CAAC;QACvB,UAAK,GAAG,CAAC,CAAC;IAEuC,CAAC;IAE1D;;;OAGG;IACK,QAAQ,CAAC,QAAgB;QAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,SAAS,CAAC,QAAgB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEtC,uFAAuF;QACvF,8BAA8B;QAE9B,oFAAoF;QACpF,qFAAqF;QACrF,uEAAuE;QAEvE,OAAO,KAAK,GAAG,IAAI,CAAC,OAAO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slint-disable no-bitwise */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IVectorConsumer } from \"@tiny-calc/nano\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { ensureRange } from \"./range\";\n\n/**\n * Used by PermutationVector to cache position -> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n private handles: Handle[] = [];\n private start = 0;\n\n constructor(public readonly vector: PermutationVector) { }\n\n /**\n * Returns the index of the given position in the 'handles' array as a Uint32.\n * (If the position is not in the array, returns an integer greater than 'handles.length').\n */\n private getIndex(position: number) {\n return (position - this.start) >>> 0;\n }\n\n /**\n * Returns the handle currently assigned to the given 'position' (if any). Check\n * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n * the given position.\n *\n * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n * PermutationVector's length.\n */\n public getHandle(position: number) {\n const index = this.getIndex(position);\n\n // Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n // to a separate method.\n\n // Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n // checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n // ~40% speedup when the position is in the cache (node v12 x64).\n\n return index < this.handles.length\n ? this.handles[index]\n : this.cacheMiss(position);\n }\n\n /** Update the cache when a handle has been allocated for a given position. */\n public addHandle(position: number, handle: Handle) {\n assert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n const index = this.getIndex(position);\n if (index < this.handles.length) {\n assert(!isHandleValid(this.handles[index]),\n 0x018 /* \"Trying to insert handle into position with already valid handle!\" */);\n this.handles[index] = handle;\n }\n }\n\n /** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n private getHandles(start: number, end: number) {\n // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n // is that\n\n const handles: Handle[] = [];\n const { vector } = this;\n\n for (let pos = start; pos < end; pos++) {\n const { segment, offset } = vector.getContainingSegment(pos);\n const asPerm = segment as PermutationSegment;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n handles.push(asPerm.start + offset!);\n }\n\n return handles;\n }\n\n private cacheMiss(position: number) {\n // Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n // with the same logic that handles 'position' >= length.\n const _position = position >>> 0;\n\n // TODO: To bound memory usage, there should be a limit on the maximum size of\n // handle[].\n\n // TODO: To reduce MergeTree lookups, this code should opportunistically grow\n // the cache to the next MergeTree segment boundary (within the limits of\n // the handle cache).\n\n if (_position < this.start) {\n this.handles = this.getHandles(_position, this.start).concat(this.handles);\n this.start = _position;\n return this.handles[0];\n } else {\n ensureRange(_position, this.vector.getLength());\n\n this.handles = this.handles.concat(this.getHandles(this.start + this.handles.length, _position + 1));\n return this.handles[this.handles.length - 1];\n }\n }\n\n // #region IVectorConsumer\n\n itemsChanged(start: number, removedCount: number, insertedCount: number): void {\n // If positions were inserted/removed, our current policy is to trim the array\n // at the beginning of the invalidate range and lazily repopulate the handles\n // on demand.\n //\n // Some alternatives to consider that preserve the previously cached handles\n // that are still valid:\n //\n // * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n // to be Handle.unallocated, so we don't even need to look them up.)\n //\n // * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n const index = this.getIndex(start);\n if (index < this.handles.length) {\n this.handles.length = index;\n }\n }\n\n // #endregion IVectorConsumer\n}\n"]}
package/lib/matrix.d.ts CHANGED
@@ -89,7 +89,6 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
89
89
  */
90
90
  protected loadCore(storage: IChannelStorageService): Promise<void>;
91
91
  protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
92
- protected registerCore(): void;
93
92
  private readonly onRowDelta;
94
93
  private readonly onColDelta;
95
94
  private readonly onRowHandlesRecycled;
@@ -1 +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,EAAE,MAAM;IAIjD,gBAAgB,CAAQ,eAAe,CAAC,OAAO,EAAE,QAAQ;IA2CzD,gBAAgB,CAAQ,eAAe,CAAC,OAAO,EAAE,QAAQ;IA2CzD,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAY5E;;;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;IAchE,SAAS,CAAC,SAAS;IASnB,SAAS,CAAC,SAAS;IASnB,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO;IAyC7D,SAAS,CAAC,YAAY;IAEtB;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAmBxD,SAAS,CAAC,WAAW,CAAC,UAAU,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IA6DrG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIzB;IAGF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIzB;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAgBrB,QAAQ;IAkBf,SAAS,CAAC,cAAc;CAG3B"}
package/lib/matrix.js CHANGED
@@ -142,7 +142,6 @@ export class SharedMatrix extends SharedObject {
142
142
  setCellCore(row, col, value, rowHandle = this.rows.getAllocatedHandle(row), colHandle = this.cols.getAllocatedHandle(col)) {
143
143
  if (this.undo !== undefined) {
144
144
  let oldValue = this.cells.getCell(rowHandle, colHandle);
145
- // eslint-disable-next-line no-null/no-null
146
145
  if (oldValue === null) {
147
146
  oldValue = undefined;
148
147
  }
@@ -228,7 +227,6 @@ export class SharedMatrix extends SharedObject {
228
227
  for (let col = 0; col < this.colCount; col++) {
229
228
  const colHandle = this.colHandles.getHandle(col);
230
229
  const value = this.cells.getCell(rowHandle, colHandle);
231
- // eslint-disable-next-line no-null/no-null
232
230
  if (this.isAttached() && value !== undefined && value !== null) {
233
231
  this.sendSetCellOp(row, col, value, rowHandle, colHandle);
234
232
  }
@@ -260,7 +258,6 @@ export class SharedMatrix extends SharedObject {
260
258
  for (let row = 0; row < this.rowCount; row++) {
261
259
  const rowHandle = this.rowHandles.getHandle(row);
262
260
  const value = this.cells.getCell(rowHandle, colHandle);
263
- // eslint-disable-next-line no-null/no-null
264
261
  if (this.isAttached() && value !== undefined && value !== null) {
265
262
  this.sendSetCellOp(row, col, value, rowHandle, colHandle);
266
263
  }
@@ -419,10 +416,6 @@ export class SharedMatrix extends SharedObject {
419
416
  }
420
417
  }
421
418
  }
422
- registerCore() {
423
- this.rows.startOrUpdateCollaboration(this.runtime.clientId, 0);
424
- this.cols.startOrUpdateCollaboration(this.runtime.clientId, 0);
425
- }
426
419
  /**
427
420
  * Returns true if the latest pending write to the cell indicated by the given row/col handles
428
421
  * matches the given 'localSeq'.
package/lib/matrix.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAQtD,OAAO,EAEH,uBAAuB,EACvB,YAAY,EACZ,YAAY,GAEf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAQ3F,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,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AuG,CAAC,CAAC;QAEnH,wFAAwF;QACxF,mDAAmD;QACnD,OAAO,eAAe,KAAK,QAAQ,CAAC;IACxC,CAAC;IAEM,QAAQ;QACX,IAAI,CAAC,GAAG,UAAU,IAAI,CAAC,OAAO,CAAC,QAAQ,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE5G,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YACpC,CAAC,IAAI,KAAK,CAAC;YACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;gBACpC,IAAI,CAAC,GAAG,CAAC,EAAE;oBACP,CAAC,IAAI,IAAI,CAAC;iBACb;gBAED,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;aACxE;YACD,CAAC,IAAI,KAAK,CAAC;SACd;QAED,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set,\n row: number,\n col: number,\n value: MatrixItem<T>,\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle,\n colHandle: Handle,\n localSeq: number,\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>>\n{\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n\n // eslint-disable-next-line no-null/no-null\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n // eslint-disable-next-line no-null/no-null\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n // eslint-disable-next-line no-null/no-null\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<Serializable<T>>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n protected registerCore() {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId, 0);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId, 0);\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n protected applyStash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AM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAE,CAAC;QAEpE,yFAAyF;QACzF,+FAA+F;QAC/F,kCAAkC;QAClC,MAAM,CAAC,CAAC,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,mCAAmC;QACnC,KAAK,CAAC,uGAAuG,CAAC,CAAC;QAEnH,wFAAwF;QACxF,mDAAmD;QACnD,OAAO,eAAe,KAAK,QAAQ,CAAC;IACxC,CAAC;IAEM,QAAQ;QACX,IAAI,CAAC,GAAG,UAAU,IAAI,CAAC,OAAO,CAAC,QAAQ,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE5G,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;YACpC,CAAC,IAAI,KAAK,CAAC;YACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;gBACpC,IAAI,CAAC,GAAG,CAAC,EAAE;oBACP,CAAC,IAAI,IAAI,CAAC;iBACb;gBAED,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;aACxE;YACD,CAAC,IAAI,KAAK,CAAC;SACd;QAED,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n Serializable,\n IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n IFluidSerializer,\n makeHandlesSerializable,\n parseHandles,\n SharedObject,\n SummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport {\n IMatrixProducer,\n IMatrixConsumer,\n IMatrixReader,\n IMatrixWriter,\n} from \"@tiny-calc/nano\";\nimport { MergeTreeDeltaType, IMergeTreeOp, SegmentGroup, ISegment } from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, PermutationSegment } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n rows = \"rows\",\n cols = \"cols\",\n cells = \"cells\",\n}\n\ninterface ISetOp<T> {\n type: MatrixOp.set,\n row: number,\n col: number,\n value: MatrixItem<T>,\n}\n\ninterface ISetOpMetadata {\n rowHandle: Handle,\n colHandle: Handle,\n localSeq: number,\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n extends SharedObject\n implements IMatrixProducer<MatrixItem<T>>,\n IMatrixReader<MatrixItem<T>>,\n IMatrixWriter<MatrixItem<T>>\n{\n private readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n public static getFactory() { return new SharedMatrixFactory(); }\n\n private readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n private readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n private cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n private pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n constructor(runtime: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this.rows = new PermutationVector(\n SnapshotPath.rows,\n this.logger,\n runtime,\n this.onRowDelta,\n this.onRowHandlesRecycled);\n\n this.cols = new PermutationVector(\n SnapshotPath.cols,\n this.logger,\n runtime,\n this.onColDelta,\n this.onColHandlesRecycled);\n }\n\n private undo?: MatrixUndoProvider<T>;\n\n /**\n * Subscribes the given IUndoConsumer to the matrix.\n */\n public openUndo(consumer: IUndoConsumer) {\n assert(this.undo === undefined,\n 0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */);\n\n this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n }\n\n // TODO: closeUndo()?\n\n private get rowHandles() { return this.rows.handleCache; }\n private get colHandles() { return this.cols.handleCache; }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n */\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n }\n\n // #region IMatrixProducer\n\n openMatrix(\n consumer: IMatrixConsumer<MatrixItem<T>>,\n ): IMatrixReader<MatrixItem<T>> {\n this.consumers.add(consumer);\n return this;\n }\n\n closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n this.consumers.delete(consumer);\n }\n\n // #endregion IMatrixProducer\n\n // #region IMatrixReader\n\n public get rowCount() { return this.rows.getLength(); }\n public get colCount() { return this.cols.getLength(); }\n\n public getCell(row: number, col: number): MatrixItem<T> {\n // Perf: When possible, bounds checking is performed inside the implementation for\n // 'getHandle()' so that it can be elided in the case of a cache hit. This\n // yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n // Map the logical (row, col) to associated storage handles.\n const rowHandle = this.rowHandles.getHandle(row);\n if (isHandleValid(rowHandle)) {\n const colHandle = this.colHandles.getHandle(col);\n if (isHandleValid(colHandle)) {\n return this.cells.getCell(rowHandle, colHandle);\n }\n } else {\n // If we early exit because the given rowHandle is unallocated, we still need to\n // bounds-check the 'col' parameter.\n ensureRange(col, this.cols.getLength());\n }\n\n return undefined;\n }\n\n public get matrixProducer(): IMatrixProducer<MatrixItem<T>> { return this; }\n\n // #endregion IMatrixReader\n\n public setCell(row: number, col: number, value: MatrixItem<T>) {\n assert(0 <= row && row < this.rowCount\n && 0 <= col && col < this.colCount,\n 0x01a /* \"Trying to set out-of-bounds cell!\" */);\n\n this.setCellCore(row, col, value);\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(row, col, 1, 1, this);\n }\n }\n\n public setCells(\n rowStart: number,\n colStart: number,\n colCount: number,\n values: readonly (MatrixItem<T>)[],\n ) {\n const rowCount = Math.ceil(values.length / colCount);\n\n assert((0 <= rowStart && rowStart < this.rowCount)\n && (0 <= colStart && colStart < this.colCount)\n && (1 <= colCount && colCount <= (this.colCount - colStart))\n && (rowCount <= (this.rowCount - rowStart)),\n 0x01b /* \"Trying to set multiple out-of-bounds cells!\" */);\n\n const endCol = colStart + colCount;\n let r = rowStart;\n let c = colStart;\n\n for (const value of values) {\n this.setCellCore(r, c, value);\n\n if (++c === endCol) {\n c = colStart;\n r++;\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n }\n }\n\n private setCellCore(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle = this.rows.getAllocatedHandle(row),\n colHandle = this.cols.getAllocatedHandle(col),\n ) {\n if (this.undo !== undefined) {\n let oldValue = this.cells.getCell(rowHandle, colHandle);\n if (oldValue === null) {\n oldValue = undefined;\n }\n\n this.undo.cellSet(\n rowHandle,\n colHandle,\n oldValue);\n }\n\n this.cells.setCell(rowHandle, colHandle, value);\n\n if (this.isAttached()) {\n this.sendSetCellOp(row, col, value, rowHandle, colHandle);\n }\n }\n\n private sendSetCellOp(\n row: number,\n col: number,\n value: MatrixItem<T>,\n rowHandle: Handle,\n colHandle: Handle,\n localSeq = this.nextLocalSeq(),\n ) {\n assert(this.isAttached(), 0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */);\n\n const op: ISetOp<T> = {\n type: MatrixOp.set,\n row,\n col,\n value,\n };\n\n const metadata: ISetOpMetadata = {\n rowHandle,\n colHandle,\n localSeq,\n };\n\n this.submitLocalMessage(op, metadata);\n this.pending.setCell(rowHandle, colHandle, localSeq);\n }\n\n private submitVectorMessage(\n currentVector: PermutationVector,\n oppositeVector: PermutationVector,\n dimension: SnapshotPath.rows | SnapshotPath.cols,\n message: any,\n ) {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n // for each submitted op it not aware of to keep them synchronized.\n const localSeq = currentVector.getCollabWindow().localSeq;\n const oppositeWindow = oppositeVector.getCollabWindow();\n\n // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n // the MergeTree submits the op with the original 'localSeq'.\n assert(localSeq >= oppositeWindow.localSeq,\n 0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */);\n\n oppositeWindow.localSeq = localSeq;\n\n // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n // Do not queue a message or track the pending op, as there will never be an ACK, etc.\n if (this.isAttached()) {\n // Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n message.target = dimension;\n\n this.submitLocalMessage(\n message,\n currentVector.peekPendingSegmentGroups(\n message.type === MergeTreeDeltaType.GROUP\n ? message.ops.length\n : 1));\n }\n }\n\n private submitColMessage(message: any) {\n this.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n }\n\n public insertCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.insert(colStart, count));\n }\n\n public removeCols(colStart: number, count: number) {\n this.submitColMessage(this.cols.remove(colStart, count));\n }\n\n private submitRowMessage(message: any) {\n this.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n }\n\n public insertRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.insert(rowStart, count));\n }\n\n public removeRows(rowStart: number, count: number) {\n this.submitRowMessage(this.rows.remove(rowStart, count));\n }\n\n /** @internal */ public _undoRemoveRows(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of rows at the original position.\n const { op, inserted } = this.rows.insertRelative(original, original.cachedLength);\n this.submitRowMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'rowsChanged'\n // callback, which occurs before the handle span is populated.\n const rowStart = this.rows.getPosition(inserted);\n this.rows.handleCache.itemsChanged(\n rowStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted rows.\n let rowHandle = inserted.start;\n const rowCount = inserted.cachedLength;\n for (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n for (let col = 0; col < this.colCount; col++) {\n const colHandle = this.colHandles.getHandle(col);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n }\n }\n\n /** @internal */ public _undoRemoveCols(segment: ISegment) {\n const original = segment as PermutationSegment;\n\n // (Re)insert the removed number of columns at the original position.\n const { op, inserted } = this.cols.insertRelative(original, original.cachedLength);\n this.submitColMessage(op);\n\n // Transfer handles and undo/redo tracking groups from the original segment to the\n // newly inserted segment.\n original.transferToReplacement(inserted);\n\n // Invalidate the handleCache in case it was populated during the 'colsChanged'\n // callback, which occurs before the handle span is populated.\n const colStart = this.cols.getPosition(inserted);\n this.cols.handleCache.itemsChanged(\n colStart,\n /* removedCount: */ 0,\n /* insertedCount: */ inserted.cachedLength);\n\n // Generate setCell ops for each populated cell in the reinserted cols.\n let colHandle = inserted.start;\n const colCount = inserted.cachedLength;\n for (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n for (let row = 0; row < this.rowCount; row++) {\n const rowHandle = this.rowHandles.getHandle(row);\n const value = this.cells.getCell(rowHandle, colHandle);\n if (this.isAttached() && value !== undefined && value !== null) {\n this.sendSetCellOp(\n row,\n col,\n value,\n rowHandle,\n colHandle);\n }\n }\n }\n\n // Avoid reentrancy by raising change notifications after the op is queued.\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n }\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));\n builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));\n builder.addBlob(SnapshotPath.cells,\n serializer.stringify([\n this.cells.snapshot(),\n this.pending.snapshot(),\n ], this.handle));\n return builder.getSummaryTree();\n }\n\n /**\n * Runs serializer on the GC data for this SharedMatrix.\n * All the IFluidHandle's stored in the cells represent routes to other objects.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n for (let row = 0; row < this.rowCount; row++) {\n for (let col = 0; col < this.colCount; col++) {\n serializer.stringify(this.getCell(row, col), this.handle);\n }\n }\n }\n\n /**\n * Advances the 'localSeq' counter for the cell data operation currently being queued.\n *\n * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n * automatically advance 'localSeq'.\n */\n private nextLocalSeq() {\n // Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n // and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n // for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n // need to bump both counters.)\n\n this.cols.getCollabWindow().localSeq++;\n return ++this.rows.getCollabWindow().localSeq;\n }\n\n protected submitLocalMessage(message: any, localOpMetadata?: any) {\n // TODO: Recommend moving this assertion into SharedObject\n // (See https://github.com/microsoft/FluidFramework/issues/2559)\n assert(this.isAttached() === true, 0x01d /* \"Trying to submit message to runtime while detached!\" */);\n\n super.submitLocalMessage(makeHandlesSerializable(message, this.serializer, this.handle), localOpMetadata);\n\n // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n assert(\n this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n 0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n );\n }\n\n protected didAttach() {\n // We've attached we need to start generating and sending ops.\n // so start collaboration and provide a default client id incase we are not connected\n if (this.isAttached()) {\n this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n }\n }\n\n protected onConnect() {\n assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n 0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */);\n\n // Update merge tree collaboration information with new client ID and then resend pending ops\n this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n this.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n }\n\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n switch (content.target) {\n case SnapshotPath.cols:\n this.submitColMessage(this.cols.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n case SnapshotPath.rows:\n this.submitRowMessage(this.rows.regeneratePendingOp(\n content as IMergeTreeOp,\n localOpMetadata as SegmentGroup | SegmentGroup[]));\n break;\n default: {\n assert(content.type === MatrixOp.set, 0x020 /* \"Unknown SharedMatrix 'op' type.\" */);\n\n const setOp = content as ISetOp<Serializable<T>>;\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If there are more pending local writes to the same row/col handle, it is important\n // to skip resubmitting this op since it is possible the row/col handle has been recycled\n // and now refers to a different position than when this op was originally submitted.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n const row = this.rows.handleToPosition(rowHandle, localSeq);\n const col = this.cols.handleToPosition(colHandle, localSeq);\n\n if (row >= 0 && col >= 0) {\n this.sendSetCellOp(\n row,\n col,\n setOp.value,\n rowHandle,\n colHandle,\n localSeq,\n );\n }\n }\n break;\n }\n }\n }\n\n protected onDisconnect() {}\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService) {\n try {\n await this.rows.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.rows),\n this.serializer);\n await this.cols.load(\n this.runtime,\n new ObjectStoragePartition(storage, SnapshotPath.cols),\n this.serializer);\n const [cellData, pendingCliSeqData] = await deserializeBlob(storage, SnapshotPath.cells, this.serializer);\n\n this.cells = SparseArray2D.load(cellData);\n this.pending = SparseArray2D.load(pendingCliSeqData);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n }\n }\n\n protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n const msg = parseHandles(rawMessage, this.serializer);\n\n const contents = msg.contents;\n\n switch (contents.target) {\n case SnapshotPath.cols:\n this.cols.applyMsg(msg);\n break;\n case SnapshotPath.rows:\n this.rows.applyMsg(msg);\n break;\n default: {\n assert(contents.type === MatrixOp.set,\n 0x021 /* \"SharedMatrix message contents have unexpected type!\" */);\n\n const { referenceSequenceNumber: refSeq, clientId } = rawMessage;\n const { row, col } = contents;\n\n if (local) {\n // We are receiving the ACK for a local pending set operation.\n const { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n // If this is the most recent write to the cell by the local client, remove our\n // entry from 'pendingCliSeqs' to resume allowing remote writes.\n if (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n this.pending.setCell(rowHandle, colHandle, undefined);\n }\n } else {\n const rowClientId = this.rows.getOrAddShortClientId(clientId);\n const adjustedRow = this.rows.adjustPosition(row, refSeq, rowClientId);\n\n if (adjustedRow !== undefined) {\n const colClientId = this.cols.getOrAddShortClientId(clientId);\n const adjustedCol = this.cols.adjustPosition(col, refSeq, colClientId);\n\n if (adjustedCol !== undefined) {\n const rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n const colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n assert(isHandleValid(rowHandle) && isHandleValid(colHandle),\n 0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */);\n\n // If there is a pending (unACKed) local write to the same cell, skip the current op\n // since it \"happened before\" the pending write.\n if (this.pending.getCell(rowHandle, colHandle) === undefined) {\n const { value } = contents;\n this.cells.setCell(rowHandle, colHandle, value);\n\n for (const consumer of this.consumers.values()) {\n consumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.rowsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n private readonly onColDelta = (position: number, removedCount: number, insertedCount: number) => {\n for (const consumer of this.consumers) {\n consumer.colsChanged(position, removedCount, insertedCount, this);\n }\n };\n\n private readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n for (const rowHandle of rowHandles) {\n this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n }\n };\n\n private readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n for (const colHandle of colHandles) {\n this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n }\n };\n\n /**\n * Returns true if the latest pending write to the cell indicated by the given row/col handles\n * matches the given 'localSeq'.\n *\n * A return value of `true` indicates that there are no later local operations queued that will\n * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n * with a different value as well as row/col removals that might recycled the given row/col handles.\n */\n private isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n // be 'undefined' or > 'localSeq'.\n assert(!(pendingLocalSeq < localSeq),\n // eslint-disable-next-line max-len\n 0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */);\n\n // If this is the most recent write to the cell by the local client, the stored localSeq\n // will be an exact match for the given 'localSeq'.\n return pendingLocalSeq === localSeq;\n }\n\n public toString() {\n let s = `client:${this.runtime.clientId}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n for (let r = 0; r < this.rowCount; r++) {\n s += ` [`;\n for (let c = 0; c < this.colCount; c++) {\n if (c > 0) {\n s += \", \";\n }\n\n s += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n }\n s += \"]\\n\";\n }\n\n return `${s}\\n`;\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "0.56.7";
8
+ export declare const pkgVersion = "0.57.1";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/matrix";
8
- export const pkgVersion = "0.56.7";
8
+ export const pkgVersion = "0.57.1";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.56.7\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,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\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OvB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAapB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAapB,wEAAwE;IACjE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA0BnD,uEAAuE;IAChE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA0BnD,OAAO,CAAC,QAAQ;IAQT,QAAQ;WAID,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;CAG5C"}
@@ -30,7 +30,6 @@ const c0ToMorton16 = (col) => interlaceBitsX16(col) >>> 0;
30
30
  const r0c0ToMorton2x16 = (row, col) => (r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;
31
31
  /** Undo JSON serialization's coercion of 'undefined' to null. */
32
32
  const nullToUndefined = (array) => array.map((value) => {
33
- // eslint-disable-next-line no-null/no-null
34
33
  return value === null
35
34
  ? undefined
36
35
  : Array.isArray(value)
@@ -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,GACnB,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;IACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,sBAAsB;IACnD,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,sBAAsB;IACnD,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC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,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;wBAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;4BAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;gCAC/C,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;oCACvC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;gCAC5B,CAAC,CAAC,CAAC;4BACP,CAAC,CAAC,CAAC;wBACP,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC,CAAC;iBACN;aACJ;SACJ;IACL,CAAC;IAEO,QAAQ,CAAI,MAAiB,EAAE,MAAc;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,+DAA+D;QAC/D,OAAO,KAAK,KAAK,SAAS;YACtB,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC,CAAC,KAAK,CAAC;IAChB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACrC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACtF,CAAC;CACJ","sourcesContent":["/*!\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 =\n new Array(256).fill(0).map((value, i) => {\n let j = i;\n j = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n j = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n j = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n return 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) => (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) => (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. */\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> => array.map((value) => {\n // eslint-disable-next-line no-null/no-null\n return value === null\n ? undefined\n : Array.isArray(value)\n ? nullToUndefined(value)\n : value;\n});\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> implements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined> {\n constructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) { }\n\n public get rowCount() { return 0xFFFFFFFF; }\n public get colCount() { return 0xFFFFFFFF; }\n\n public getCell(row: number, col: number): T | undefined {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n const keyLo = r0c0ToMorton2x16(row, col);\n const level1 = level0[byte0(keyLo)];\n if (level1 !== undefined) {\n const level2 = level1[byte1(keyLo)];\n if (level2 !== undefined) {\n const level3 = level2[byte2(keyLo)];\n if (level3 !== undefined) {\n return level3[byte3(keyLo)];\n }\n }\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n public get matrixProducer() { return undefined as any; }\n\n public setCell(row: number, col: number, value: T | undefined) {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const keyLo = r0c0ToMorton2x16(row, col);\n\n const level0 = this.getLevel(this.root, keyHi);\n const level1 = this.getLevel(level0, byte0(keyLo));\n const level2 = this.getLevel(level1, byte1(keyLo));\n const level3 = this.getLevel(level2, byte2(keyLo));\n level3[byte3(keyLo)] = value;\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n for (let col = 0; col < 16; col++) {\n // Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n callback((rowBits | c0ToMorton16(col)) >>> 0);\n }\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInCol(col: number, callback: (key: number) => void) {\n for (let row = 0; row < 16; row++) {\n // Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n callback((r0ToMorton16(row) | col) >>> 0);\n }\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given row in the 'currentLevel'.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInRow<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n rowBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInRow(rowBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given col in the 'currentLevel'.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInCol<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n colBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInCol(colBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /** Clears the all cells contained within the specified span of rows. */\n public clearRows(rowStart: number, rowCount: number) {\n const rowEnd = rowStart + rowCount;\n for (let row = rowStart; row < rowEnd; row++) {\n const rowHi = r0ToMorton16(row >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let colHi = 0; colHi < 0x10000; colHi++) {\n const keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const rowLo = r0ToMorton16(row);\n this.forEachInRow(level0, byte0(rowLo), (level1) => {\n this.forEachInRow(level1, byte1(rowLo), (level2) => {\n this.forEachInRow(level2, byte2(rowLo), (level3) => {\n this.forEachKeyInRow(byte3(rowLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n /** Clears the all cells contained within the specifed span of cols. */\n public clearCols(colStart: number, colCount: number) {\n const colEnd = colStart + colCount;\n for (let col = colStart; col < colEnd; col++) {\n const colHi = c0ToMorton16(col >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n const keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const colLo = c0ToMorton16(col);\n this.forEachInCol(level0, byte0(colLo), (level1) => {\n this.forEachInCol(level1, byte1(colLo), (level2) => {\n this.forEachInCol(level2, byte2(colLo), (level3) => {\n this.forEachKeyInCol(byte3(colLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n private getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n const level = parent[subKey];\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return level === undefined\n ? (parent[subKey] = new Array(256).fill(undefined))\n : level;\n }\n\n public snapshot() {\n return this.root;\n }\n\n public static load<T>(data: RecurArray<T>) {\n return new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n }\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,GACnB,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;IACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,sBAAsB;IACnD,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GA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,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;oBAChC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;wBAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;4BAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;gCAC/C,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;oCACvC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;gCAC5B,CAAC,CAAC,CAAC;4BACP,CAAC,CAAC,CAAC;wBACP,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC,CAAC;iBACN;aACJ;SACJ;IACL,CAAC;IAEO,QAAQ,CAAI,MAAiB,EAAE,MAAc;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,+DAA+D;QAC/D,OAAO,KAAK,KAAK,SAAS;YACtB,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC,CAAC,KAAK,CAAC;IAChB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACrC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACtF,CAAC;CACJ","sourcesContent":["/*!\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 =\n new Array(256).fill(0).map((value, i) => {\n let j = i;\n j = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n j = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n j = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n return 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) => (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) => (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. */\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> => array.map((value) => {\n return value === null\n ? undefined\n : Array.isArray(value)\n ? nullToUndefined(value)\n : value;\n});\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> implements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined> {\n constructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) { }\n\n public get rowCount() { return 0xFFFFFFFF; }\n public get colCount() { return 0xFFFFFFFF; }\n\n public getCell(row: number, col: number): T | undefined {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n const keyLo = r0c0ToMorton2x16(row, col);\n const level1 = level0[byte0(keyLo)];\n if (level1 !== undefined) {\n const level2 = level1[byte1(keyLo)];\n if (level2 !== undefined) {\n const level3 = level2[byte2(keyLo)];\n if (level3 !== undefined) {\n return level3[byte3(keyLo)];\n }\n }\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n public get matrixProducer() { return undefined as any; }\n\n public setCell(row: number, col: number, value: T | undefined) {\n const keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n const keyLo = r0c0ToMorton2x16(row, col);\n\n const level0 = this.getLevel(this.root, keyHi);\n const level1 = this.getLevel(level0, byte0(keyLo));\n const level2 = this.getLevel(level1, byte1(keyLo));\n const level3 = this.getLevel(level2, byte2(keyLo));\n level3[byte3(keyLo)] = value;\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n for (let col = 0; col < 16; col++) {\n // Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n callback((rowBits | c0ToMorton16(col)) >>> 0);\n }\n }\n\n /**\n * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachKeyInCol(col: number, callback: (key: number) => void) {\n for (let row = 0; row < 16; row++) {\n // Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n callback((r0ToMorton16(row) | col) >>> 0);\n }\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given row in the 'currentLevel'.\n *\n * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInRow<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n rowBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInRow(rowBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /**\n * Invokes the give 'callback' with the next 'level' array for each populated region\n * of the given col in the 'currentLevel'.\n *\n * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n * level being traversed.)\n */\n private forEachInCol<V extends UA<any>, U extends UA<V>>(\n currentLevel: U,\n colBits: number,\n callback: (level: V) => void,\n ) {\n this.forEachKeyInCol(colBits, (key) => {\n const nextLevel = currentLevel[key];\n if (nextLevel !== undefined) {\n callback(nextLevel);\n }\n });\n }\n\n /** Clears the all cells contained within the specified span of rows. */\n public clearRows(rowStart: number, rowCount: number) {\n const rowEnd = rowStart + rowCount;\n for (let row = rowStart; row < rowEnd; row++) {\n const rowHi = r0ToMorton16(row >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let colHi = 0; colHi < 0x10000; colHi++) {\n const keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const rowLo = r0ToMorton16(row);\n this.forEachInRow(level0, byte0(rowLo), (level1) => {\n this.forEachInRow(level1, byte1(rowLo), (level2) => {\n this.forEachInRow(level2, byte2(rowLo), (level3) => {\n this.forEachKeyInRow(byte3(rowLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n /** Clears the all cells contained within the specifed span of cols. */\n public clearCols(colStart: number, colCount: number) {\n const colEnd = colStart + colCount;\n for (let col = colStart; col < colEnd; col++) {\n const colHi = c0ToMorton16(col >>> 16);\n\n // The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n for (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n const keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n const level0 = this.root[keyHi];\n if (level0 !== undefined) {\n // The remainder of the tree is divided in 16 x 16 tiles.\n const colLo = c0ToMorton16(col);\n this.forEachInCol(level0, byte0(colLo), (level1) => {\n this.forEachInCol(level1, byte1(colLo), (level2) => {\n this.forEachInCol(level2, byte2(colLo), (level3) => {\n this.forEachKeyInCol(byte3(colLo), (key) => {\n level3[key] = undefined;\n });\n });\n });\n });\n }\n }\n }\n }\n\n private getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n const level = parent[subKey];\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return level === undefined\n ? (parent[subKey] = new Array(256).fill(undefined))\n : level;\n }\n\n public snapshot() {\n return this.root;\n }\n\n public static load<T>(data: RecurArray<T>) {\n return new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "0.56.7",
3
+ "version": "0.57.1",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -57,23 +57,23 @@
57
57
  "@fluidframework/common-definitions": "^0.20.1",
58
58
  "@fluidframework/common-utils": "^0.32.1",
59
59
  "@fluidframework/core-interfaces": "^0.42.0",
60
- "@fluidframework/datastore-definitions": "^0.56.7",
61
- "@fluidframework/merge-tree": "^0.56.7",
60
+ "@fluidframework/datastore-definitions": "^0.57.1",
61
+ "@fluidframework/merge-tree": "^0.57.1",
62
62
  "@fluidframework/protocol-base": "^0.1034.0",
63
63
  "@fluidframework/protocol-definitions": "^0.1026.0",
64
- "@fluidframework/runtime-definitions": "^0.56.7",
65
- "@fluidframework/runtime-utils": "^0.56.7",
66
- "@fluidframework/shared-object-base": "^0.56.7",
67
- "@fluidframework/telemetry-utils": "^0.56.7",
64
+ "@fluidframework/runtime-definitions": "^0.57.1",
65
+ "@fluidframework/runtime-utils": "^0.57.1",
66
+ "@fluidframework/shared-object-base": "^0.57.1",
67
+ "@fluidframework/telemetry-utils": "^0.57.1",
68
68
  "@tiny-calc/nano": "0.0.0-alpha.5",
69
69
  "tslib": "^1.10.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@fluid-internal/test-dds-utils": "^0.56.7",
72
+ "@fluid-internal/test-dds-utils": "^0.57.1",
73
73
  "@fluidframework/build-common": "^0.23.0",
74
- "@fluidframework/eslint-config-fluid": "^0.25.0",
75
- "@fluidframework/mocha-test-setup": "^0.56.7",
76
- "@fluidframework/test-runtime-utils": "^0.56.7",
74
+ "@fluidframework/eslint-config-fluid": "^0.26.0",
75
+ "@fluidframework/mocha-test-setup": "^0.57.1",
76
+ "@fluidframework/test-runtime-utils": "^0.57.1",
77
77
  "@microsoft/api-extractor": "^7.16.1",
78
78
  "@rushstack/eslint-config": "^2.5.1",
79
79
  "@tiny-calc/micro": "0.0.0-alpha.5",
@@ -125,7 +125,7 @@ export class HandleCache implements IVectorConsumer<Handle> {
125
125
 
126
126
  const index = this.getIndex(start);
127
127
  if (index < this.handles.length) {
128
- this.handles.length = index;
128
+ this.handles.length = index;
129
129
  }
130
130
  }
131
131
 
package/src/matrix.ts CHANGED
@@ -232,8 +232,6 @@ export class SharedMatrix<T = any>
232
232
  ) {
233
233
  if (this.undo !== undefined) {
234
234
  let oldValue = this.cells.getCell(rowHandle, colHandle);
235
-
236
- // eslint-disable-next-line no-null/no-null
237
235
  if (oldValue === null) {
238
236
  oldValue = undefined;
239
237
  }
@@ -362,7 +360,6 @@ export class SharedMatrix<T = any>
362
360
  for (let col = 0; col < this.colCount; col++) {
363
361
  const colHandle = this.colHandles.getHandle(col);
364
362
  const value = this.cells.getCell(rowHandle, colHandle);
365
- // eslint-disable-next-line no-null/no-null
366
363
  if (this.isAttached() && value !== undefined && value !== null) {
367
364
  this.sendSetCellOp(
368
365
  row,
@@ -406,7 +403,6 @@ export class SharedMatrix<T = any>
406
403
  for (let row = 0; row < this.rowCount; row++) {
407
404
  const rowHandle = this.rowHandles.getHandle(row);
408
405
  const value = this.cells.getCell(rowHandle, colHandle);
409
- // eslint-disable-next-line no-null/no-null
410
406
  if (this.isAttached() && value !== undefined && value !== null) {
411
407
  this.sendSetCellOp(
412
408
  row,
@@ -621,11 +617,6 @@ export class SharedMatrix<T = any>
621
617
  }
622
618
  }
623
619
 
624
- protected registerCore() {
625
- this.rows.startOrUpdateCollaboration(this.runtime.clientId, 0);
626
- this.cols.startOrUpdateCollaboration(this.runtime.clientId, 0);
627
- }
628
-
629
620
  // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.
630
621
  private readonly onRowDelta = (position: number, removedCount: number, insertedCount: number) => {
631
622
  for (const consumer of this.consumers) {
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/matrix";
9
- export const pkgVersion = "0.56.7";
9
+ export const pkgVersion = "0.57.1";
@@ -44,7 +44,6 @@ type RecurArray<T> = RecurArrayHelper<T>[];
44
44
 
45
45
  /** Undo JSON serialization's coercion of 'undefined' to null. */
46
46
  const nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> => array.map((value) => {
47
- // eslint-disable-next-line no-null/no-null
48
47
  return value === null
49
48
  ? undefined
50
49
  : Array.isArray(value)