@fluidframework/matrix 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191457

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +4 -3
  3. package/dist/handlecache.js +3 -3
  4. package/dist/handlecache.js.map +1 -1
  5. package/dist/handletable.d.ts +8 -1
  6. package/dist/handletable.d.ts.map +1 -1
  7. package/dist/handletable.js +11 -3
  8. package/dist/handletable.js.map +1 -1
  9. package/dist/matrix.d.ts.map +1 -1
  10. package/dist/matrix.js +17 -18
  11. package/dist/matrix.js.map +1 -1
  12. package/dist/packageVersion.d.ts +1 -1
  13. package/dist/packageVersion.js +1 -1
  14. package/dist/packageVersion.js.map +1 -1
  15. package/dist/permutationvector.d.ts.map +1 -1
  16. package/dist/permutationvector.js +11 -8
  17. package/dist/permutationvector.js.map +1 -1
  18. package/dist/serialization.js +2 -2
  19. package/dist/serialization.js.map +1 -1
  20. package/dist/sparsearray2d.d.ts.map +1 -1
  21. package/dist/sparsearray2d.js +1 -0
  22. package/dist/sparsearray2d.js.map +1 -1
  23. package/dist/undoprovider.js +8 -9
  24. package/dist/undoprovider.js.map +1 -1
  25. package/lib/handlecache.js +1 -1
  26. package/lib/handlecache.js.map +1 -1
  27. package/lib/handletable.d.ts +8 -1
  28. package/lib/handletable.d.ts.map +1 -1
  29. package/lib/handletable.js +11 -3
  30. package/lib/handletable.js.map +1 -1
  31. package/lib/matrix.d.ts.map +1 -1
  32. package/lib/matrix.js +3 -4
  33. package/lib/matrix.js.map +1 -1
  34. package/lib/packageVersion.d.ts +1 -1
  35. package/lib/packageVersion.js +1 -1
  36. package/lib/packageVersion.js.map +1 -1
  37. package/lib/permutationvector.d.ts.map +1 -1
  38. package/lib/permutationvector.js +6 -3
  39. package/lib/permutationvector.js.map +1 -1
  40. package/lib/serialization.js +1 -1
  41. package/lib/serialization.js.map +1 -1
  42. package/lib/sparsearray2d.d.ts.map +1 -1
  43. package/lib/sparsearray2d.js +1 -0
  44. package/lib/sparsearray2d.js.map +1 -1
  45. package/lib/undoprovider.js +5 -6
  46. package/lib/undoprovider.js.map +1 -1
  47. package/package.json +27 -31
  48. package/src/handlecache.ts +1 -1
  49. package/src/handletable.ts +22 -2
  50. package/src/matrix.ts +2 -1
  51. package/src/packageVersion.ts +1 -1
  52. package/src/permutationvector.ts +3 -4
  53. package/src/serialization.ts +1 -1
  54. package/src/sparsearray2d.ts +1 -0
  55. package/src/undoprovider.ts +1 -1
  56. package/dist/bspSet.d.ts +0 -125
  57. package/dist/bspSet.d.ts.map +0 -1
  58. package/dist/bspSet.js +0 -425
  59. package/dist/bspSet.js.map +0 -1
  60. package/dist/productSet.d.ts +0 -61
  61. package/dist/productSet.d.ts.map +0 -1
  62. package/dist/productSet.js +0 -679
  63. package/dist/productSet.js.map +0 -1
  64. package/dist/split.d.ts +0 -41
  65. package/dist/split.d.ts.map +0 -1
  66. package/dist/split.js +0 -127
  67. package/dist/split.js.map +0 -1
  68. package/lib/bspSet.d.ts +0 -125
  69. package/lib/bspSet.d.ts.map +0 -1
  70. package/lib/bspSet.js +0 -402
  71. package/lib/bspSet.js.map +0 -1
  72. package/lib/productSet.d.ts +0 -61
  73. package/lib/productSet.d.ts.map +0 -1
  74. package/lib/productSet.js +0 -665
  75. package/lib/productSet.js.map +0 -1
  76. package/lib/split.d.ts +0 -41
  77. package/lib/split.d.ts.map +0 -1
  78. package/lib/split.js +0 -116
  79. package/lib/split.js.map +0 -1
  80. package/src/bspSet.ts +0 -722
  81. package/src/productSet.ts +0 -1038
  82. package/src/split.ts +0 -171
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # @fluidframework/matrix
2
2
 
3
+ ## 2.0.0-internal.6.3.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.0.0-internal.6.2.0
8
+
9
+ ### Minor Changes
10
+
11
+ - Remove use of @fluidframework/common-definitions ([#16638](https://github.com/microsoft/FluidFramework/issues/16638)) [a8c81509c9](https://github.com/microsoft/FluidFramework/commits/a8c81509c9bf09cfb2092ebcf7265205f9eb6dbf)
12
+
13
+ The **@fluidframework/common-definitions** package is being deprecated, so the following interfaces and types are now
14
+ imported from the **@fluidframework/core-interfaces** package:
15
+
16
+ - interface IDisposable
17
+ - interface IErrorEvent
18
+ - interface IErrorEvent
19
+ - interface IEvent
20
+ - interface IEventProvider
21
+ - interface ILoggingError
22
+ - interface ITaggedTelemetryPropertyType
23
+ - interface ITelemetryBaseEvent
24
+ - interface ITelemetryBaseLogger
25
+ - interface ITelemetryErrorEvent
26
+ - interface ITelemetryGenericEvent
27
+ - interface ITelemetryLogger
28
+ - interface ITelemetryPerformanceEvent
29
+ - interface ITelemetryProperties
30
+ - type ExtendEventProvider
31
+ - type IEventThisPlaceHolder
32
+ - type IEventTransformer
33
+ - type ReplaceIEventThisPlaceHolder
34
+ - type ReplaceIEventThisPlaceHolder
35
+ - type TelemetryEventCategory
36
+ - type TelemetryEventPropertyType
37
+
38
+ ## 2.0.0-internal.6.1.0
39
+
40
+ Dependency updates only.
41
+
42
+ ## 2.0.0-internal.6.0.0
43
+
44
+ ### Major Changes
45
+
46
+ - Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
47
+
48
+ Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
49
+
50
+ ## 2.0.0-internal.5.4.0
51
+
52
+ Dependency updates only.
53
+
3
54
  ## 2.0.0-internal.5.3.0
4
55
 
5
56
  Dependency updates only.
package/README.md CHANGED
@@ -13,9 +13,10 @@ When taking a dependency on a Fluid Framework library, we recommend using a `^`
13
13
  While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
14
14
  library consumers should always prefer `^`.
15
15
 
16
- Note that when depending on a library version of the form 2.0.0-internal.x.y.z, called the Fluid internal version
17
- scheme, you must use a `>= <` dependency range. Standard `^` and `~` ranges will not work as expected. See the
18
- [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
16
+ Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
17
+ you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
18
+ Standard `^` and `~` ranges will not work as expected.
19
+ See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
19
20
  package for more information including tools to convert between version schemes.
20
21
 
21
22
  <!-- prettier-ignore-end -->
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.HandleCache = void 0;
8
8
  /* eslint-disable no-bitwise */
9
- const common_utils_1 = require("@fluidframework/common-utils");
9
+ const core_utils_1 = require("@fluidframework/core-utils");
10
10
  const handletable_1 = require("./handletable");
11
11
  const range_1 = require("./range");
12
12
  /**
@@ -47,10 +47,10 @@ class HandleCache {
47
47
  }
48
48
  /** Update the cache when a handle has been allocated for a given position. */
49
49
  addHandle(position, handle) {
50
- (0, common_utils_1.assert)((0, handletable_1.isHandleValid)(handle), 0x017 /* "Trying to add invalid handle!" */);
50
+ (0, core_utils_1.assert)((0, handletable_1.isHandleValid)(handle), 0x017 /* "Trying to add invalid handle!" */);
51
51
  const index = this.getIndex(position);
52
52
  if (index < this.handles.length) {
53
- (0, common_utils_1.assert)(!(0, handletable_1.isHandleValid)(this.handles[index]), 0x018 /* "Trying to insert handle into position with already valid handle!" */);
53
+ (0, core_utils_1.assert)(!(0, handletable_1.isHandleValid)(this.handles[index]), 0x018 /* "Trying to insert handle into position with already valid handle!" */);
54
54
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AAM,CACjC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAChE,CAAC;YACF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAC7C;IACF,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACtE,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;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;SAC5B;IACF,CAAC;CAGD;AAnHD,kCAmHC","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\tprivate handles: Handle[] = [];\n\tprivate start = 0;\n\n\tconstructor(public readonly vector: PermutationVector) {}\n\n\t/**\n\t * Returns the index of the given position in the 'handles' array as a Uint32.\n\t * (If the position is not in the array, returns an integer greater than 'handles.length').\n\t */\n\tprivate getIndex(position: number) {\n\t\treturn (position - this.start) >>> 0;\n\t}\n\n\t/**\n\t * Returns the handle currently assigned to the given 'position' (if any). Check\n\t * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n\t * the given position.\n\t *\n\t * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n\t * PermutationVector's length.\n\t */\n\tpublic getHandle(position: number) {\n\t\tconst index = this.getIndex(position);\n\n\t\t// Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n\t\t// to a separate method.\n\n\t\t// Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n\t\t// checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n\t\t// ~40% speedup when the position is in the cache (node v12 x64).\n\n\t\treturn index < this.handles.length ? this.handles[index] : this.cacheMiss(position);\n\t}\n\n\t/** Update the cache when a handle has been allocated for a given position. */\n\tpublic addHandle(position: number, handle: Handle) {\n\t\tassert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n\t\tconst index = this.getIndex(position);\n\t\tif (index < this.handles.length) {\n\t\t\tassert(\n\t\t\t\t!isHandleValid(this.handles[index]),\n\t\t\t\t0x018 /* \"Trying to insert handle into position with already valid handle!\" */,\n\t\t\t);\n\t\t\tthis.handles[index] = handle;\n\t\t}\n\t}\n\n\t/** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n\tprivate getHandles(start: number, end: number) {\n\t\t// TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n\t\t// is that\n\n\t\tconst handles: Handle[] = [];\n\t\tconst { vector } = this;\n\n\t\tfor (let pos = start; pos < end; pos++) {\n\t\t\tconst { segment, offset } = vector.getContainingSegment(pos);\n\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\thandles.push(asPerm.start + offset!);\n\t\t}\n\n\t\treturn handles;\n\t}\n\n\tprivate cacheMiss(position: number) {\n\t\t// Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n\t\t// with the same logic that handles 'position' >= length.\n\t\tconst _position = position >>> 0;\n\n\t\t// TODO: To bound memory usage, there should be a limit on the maximum size of\n\t\t// handle[].\n\n\t\t// TODO: To reduce MergeTree lookups, this code should opportunistically grow\n\t\t// the cache to the next MergeTree segment boundary (within the limits of\n\t\t// the handle cache).\n\n\t\tif (_position < this.start) {\n\t\t\tthis.handles = this.getHandles(_position, this.start).concat(this.handles);\n\t\t\tthis.start = _position;\n\t\t\treturn this.handles[0];\n\t\t} else {\n\t\t\tensureRange(_position, this.vector.getLength());\n\n\t\t\tthis.handles = this.handles.concat(\n\t\t\t\tthis.getHandles(this.start + this.handles.length, _position + 1),\n\t\t\t);\n\t\t\treturn this.handles[this.handles.length - 1];\n\t\t}\n\t}\n\n\t// #region IVectorConsumer\n\n\titemsChanged(start: number, removedCount: number, insertedCount: number): void {\n\t\t// If positions were inserted/removed, our current policy is to trim the array\n\t\t// at the beginning of the invalidate range and lazily repopulate the handles\n\t\t// on demand.\n\t\t//\n\t\t// Some alternatives to consider that preserve the previously cached handles\n\t\t// that are still valid:\n\t\t//\n\t\t// * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n\t\t// to be Handle.unallocated, so we don't even need to look them up.)\n\t\t//\n\t\t// * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n\t\tconst index = this.getIndex(start);\n\t\tif (index < this.handles.length) {\n\t\t\tthis.handles.length = index;\n\t\t}\n\t}\n\n\t// #endregion IVectorConsumer\n}\n"]}
1
+ {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,2DAAoD;AAEpD,+CAAsD;AAEtD,mCAAsC;AAEtC;;;;;GAKG;AACH,MAAa,WAAW;IAIvB,YAA4B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAH7C,YAAO,GAAa,EAAE,CAAC;QACvB,UAAK,GAA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A6E;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;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;SAC5B;IACF,CAAC;CAGD;AAnHD,kCAmHC","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/core-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\tprivate handles: Handle[] = [];\n\tprivate start = 0;\n\n\tconstructor(public readonly vector: PermutationVector) {}\n\n\t/**\n\t * Returns the index of the given position in the 'handles' array as a Uint32.\n\t * (If the position is not in the array, returns an integer greater than 'handles.length').\n\t */\n\tprivate getIndex(position: number) {\n\t\treturn (position - this.start) >>> 0;\n\t}\n\n\t/**\n\t * Returns the handle currently assigned to the given 'position' (if any). Check\n\t * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n\t * the given position.\n\t *\n\t * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the\n\t * PermutationVector's length.\n\t */\n\tpublic getHandle(position: number) {\n\t\tconst index = this.getIndex(position);\n\n\t\t// Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n\t\t// to a separate method.\n\n\t\t// Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n\t\t// checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n\t\t// ~40% speedup when the position is in the cache (node v12 x64).\n\n\t\treturn index < this.handles.length ? this.handles[index] : this.cacheMiss(position);\n\t}\n\n\t/** Update the cache when a handle has been allocated for a given position. */\n\tpublic addHandle(position: number, handle: Handle) {\n\t\tassert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n\t\tconst index = this.getIndex(position);\n\t\tif (index < this.handles.length) {\n\t\t\tassert(\n\t\t\t\t!isHandleValid(this.handles[index]),\n\t\t\t\t0x018 /* \"Trying to insert handle into position with already valid handle!\" */,\n\t\t\t);\n\t\t\tthis.handles[index] = handle;\n\t\t}\n\t}\n\n\t/** Used by 'CacheMiss()' to retrieve handles for a range of positions. */\n\tprivate getHandles(start: number, end: number) {\n\t\t// TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n\t\t// is that\n\n\t\tconst handles: Handle[] = [];\n\t\tconst { vector } = this;\n\n\t\tfor (let pos = start; pos < end; pos++) {\n\t\t\tconst { segment, offset } = vector.getContainingSegment(pos);\n\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\thandles.push(asPerm.start + offset!);\n\t\t}\n\n\t\treturn handles;\n\t}\n\n\tprivate cacheMiss(position: number) {\n\t\t// Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n\t\t// with the same logic that handles 'position' >= length.\n\t\tconst _position = position >>> 0;\n\n\t\t// TODO: To bound memory usage, there should be a limit on the maximum size of\n\t\t// handle[].\n\n\t\t// TODO: To reduce MergeTree lookups, this code should opportunistically grow\n\t\t// the cache to the next MergeTree segment boundary (within the limits of\n\t\t// the handle cache).\n\n\t\tif (_position < this.start) {\n\t\t\tthis.handles = this.getHandles(_position, this.start).concat(this.handles);\n\t\t\tthis.start = _position;\n\t\t\treturn this.handles[0];\n\t\t} else {\n\t\t\tensureRange(_position, this.vector.getLength());\n\n\t\t\tthis.handles = this.handles.concat(\n\t\t\t\tthis.getHandles(this.start + this.handles.length, _position + 1),\n\t\t\t);\n\t\t\treturn this.handles[this.handles.length - 1];\n\t\t}\n\t}\n\n\t// #region IVectorConsumer\n\n\titemsChanged(start: number, removedCount: number, insertedCount: number): void {\n\t\t// If positions were inserted/removed, our current policy is to trim the array\n\t\t// at the beginning of the invalidate range and lazily repopulate the handles\n\t\t// on demand.\n\t\t//\n\t\t// Some alternatives to consider that preserve the previously cached handles\n\t\t// that are still valid:\n\t\t//\n\t\t// * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n\t\t// to be Handle.unallocated, so we don't even need to look them up.)\n\t\t//\n\t\t// * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n\t\tconst index = this.getIndex(start);\n\t\tif (index < this.handles.length) {\n\t\t\tthis.handles.length = index;\n\t\t}\n\t}\n\n\t// #endregion IVectorConsumer\n}\n"]}
@@ -3,9 +3,16 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export declare const enum Handle {
6
+ /**
7
+ * Sentinel representing the absence of a valid handle.
8
+ */
9
+ none = 0,
6
10
  /** Minimum valid handle. */
7
11
  valid = 1,
8
- /** Sentinel representing an unallocated Handle. */
12
+ /**
13
+ * Sentinel representing an unallocated Handle. Used by PermutationVector
14
+ * to delay allocate handles when previously empty row/cols become populated.
15
+ */
9
16
  unallocated = -2147483648
10
17
  }
11
18
  export declare const isHandleValid: (handle: Handle) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"handletable.d.ts","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,MAAM;IACvB,4BAA4B;IAC5B,KAAK,IAAI;IAET,mDAAmD;IACnD,WAAW,cAAc;CACzB;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,YAA2B,CAAC;AAExE;;GAEG;AACH,qBAAa,WAAW,CAAC,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AO,KAAK,IAAI,GAEf;IACD,OAAO,KAAK,IAAI,QAEf;IAEM,iBAAiB;WAIV,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;CAG1C"}
@@ -27,10 +27,18 @@ class HandleTable {
27
27
  * Allocates and returns the next available handle. Note that freed handles are recycled.
28
28
  */
29
29
  allocate() {
30
- var _a;
30
+ // Get the handle to the next free slot.
31
31
  const free = this.next;
32
- this.next = (_a = this.handles[free]) !== null && _a !== void 0 ? _a : free + 1;
33
- this.handles[free] = 0;
32
+ // Update 'next' to point to the new head of the free list. We use the contents of
33
+ // recycled slots to store the free list. The contents of the handles[free] will point
34
+ // to the next available slot. If there are no free slots (i.e., 'handles' is full),
35
+ // the slot will point to 'handles.length'. In this case, the handles array will grow
36
+ // and we update 'next' to point to the new end of the array.
37
+ this.next = this.handles[free] ?? free + 1;
38
+ // Out of paranoia, overwrite the contents of the newly allocated free slot with an
39
+ // invalid handle value. This may help catch/diagnose bugs in the event the free list
40
+ // becomes corrupted.
41
+ this.handles[free] = 0 /* none */;
34
42
  return free;
35
43
  }
36
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"handletable.js","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,iBAAgB,CAAC;AAA3D,QAAA,aAAa,iBAA8C;AAExE;;GAEG;AACH,MAAa,WAAW;IACvB,4FAA4F;IAC5F,2FAA2F;IAC3F,sFAAsF;IACtF,YAAoC,UAA0B,CAAC,CAAC,CAAC;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE9D,KAAK;QACX,qFAAqF;QACrF,uFAAuF;QACvF,oBAAoB;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;I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IAEM,MAAM,CAAC,IAAI,CAAI,IAAoB;QACzC,OAAO,IAAI,WAAW,CAAI,IAAI,CAAC,CAAC;IACjC,CAAC;CACD;AAxED,kCAwEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum Handle {\n\t/** Minimum valid handle. */\n\tvalid = 1,\n\n\t/** Sentinel representing an unallocated Handle. */\n\tunallocated = -0x80000000,\n}\n\nexport const isHandleValid = (handle: Handle) => handle >= Handle.valid;\n\n/**\n * A handle table provides a fast mapping from an integer `handle` to a value `T`.\n */\nexport class HandleTable<T> {\n\t// Note: the first slot of the 'handles' array is reserved to store the pointer to the first\n\t// free handle. We initialize this slot with a pointer to slot '1', which will cause\n\t// us to delay allocate the following slot in the array on the first allocation.\n\tpublic constructor(private readonly handles: (Handle | T)[] = [1]) {}\n\n\tpublic clear() {\n\t\t// Restore the HandleTable's initial state by deleting all items in the handles array\n\t\t// and then re-inserting the value '1' in the 0th slot. (See comment at `handles` decl\n\t\t// for explanation.)\n\t\tthis.handles.splice(0, this.handles.length, 1);\n\t}\n\n\t/**\n\t * Allocates and returns the next available handle. Note that freed handles are recycled.\n\t */\n\tpublic allocate(): Handle {\n\t\tconst free = this.next;\n\t\tthis.next = (this.handles[free] as Handle) ?? free + 1;\n\t\tthis.handles[free] = 0;\n\t\treturn free;\n\t}\n\n\t/**\n\t * Allocates and returns the next available `count` handles.\n\t */\n\tpublic allocateMany(count: Handle) {\n\t\tconst handles = new Uint32Array(count);\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\thandles[i] = this.allocate();\n\t\t}\n\t\treturn handles;\n\t}\n\n\t/**\n\t * Returns the given handle to the free list.\n\t */\n\tpublic free(handle: Handle) {\n\t\tthis.handles[handle] = this.next;\n\t\tthis.next = handle;\n\t}\n\n\t/**\n\t * Get the value `T` associated with the given handle, if any.\n\t */\n\tpublic get(handle: Handle): T {\n\t\treturn this.handles[handle] as T;\n\t}\n\n\t/**\n\t * Set the value `T` associated with the given handle.\n\t */\n\tpublic set(handle: Handle, value: T) {\n\t\tthis.handles[handle] = value;\n\t}\n\n\t// Private helpers to get/set the head of the free list, which is stored in the 0th slot\n\t// of the handle array.\n\tprivate get next() {\n\t\treturn this.handles[0] as Handle;\n\t}\n\tprivate set next(handle: Handle) {\n\t\tthis.handles[0] = handle;\n\t}\n\n\tpublic getSummaryContent() {\n\t\treturn this.handles;\n\t}\n\n\tpublic static load<T>(data: (Handle | T)[]) {\n\t\treturn new HandleTable<T>(data);\n\t}\n}\n"]}
1
+ {"version":3,"file":"handletable.js","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkBI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,iBAAgB,CAAC;AAA3D,QAAA,aAAa,iBAA8C;AAExE;;GAEG;AACH,MAAa,WAAW;IACvB,4FAA4F;IAC5F,2FAA2F;IAC3F,sFAAsF;IACtF,YAAoC,UAA0B,CAAC,CAAC,CAAC;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE9D,KAAK;QACX,qFAAqF;QACrF,uFAAuF;QACvF,oBAAoB;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,wCAAwC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEvB,mFAAmF;QACnF,uFAAuF;QACvF,qFAAqF;QACrF,sFAAsF;QACtF,6DAA6D;QAC7D,IAAI,CAAC,IAAI,GAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAY,IAAI,IAAI,GAAG,CAAC,CAAC;QAEvD,mFAAmF;QACnF,sFAAsF;QACtF,qBAAqB;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,eAAc,CAAC;QAEjC,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,KAAa;QAChC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;YAC/B,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC7B;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,MAAc;QACzB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAM,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,MAAc,EAAE,KAAQ;QAClC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED,wFAAwF;IACxF,uBAAuB;IACvB,IAAY,IAAI;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAW,CAAC;IAClC,CAAC;IACD,IAAY,IAAI,CAAC,MAAc;QAC9B,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC1B,CAAC;IAEM,iBAAiB;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAoB;QACzC,OAAO,IAAI,WAAW,CAAI,IAAI,CAAC,CAAC;IACjC,CAAC;CACD;AApFD,kCAoFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum Handle {\n\t/**\n\t * Sentinel representing the absence of a valid handle.\n\t */\n\tnone = 0,\n\n\t/** Minimum valid handle. */\n\tvalid = 1,\n\n\t/**\n\t * Sentinel representing an unallocated Handle. Used by PermutationVector\n\t * to delay allocate handles when previously empty row/cols become populated.\n\t */\n\tunallocated = -0x80000000,\n}\n\nexport const isHandleValid = (handle: Handle) => handle >= Handle.valid;\n\n/**\n * A handle table provides a fast mapping from an integer `handle` to a value `T`.\n */\nexport class HandleTable<T> {\n\t// Note: the first slot of the 'handles' array is reserved to store the pointer to the first\n\t// free handle. We initialize this slot with a pointer to slot '1', which will cause\n\t// us to delay allocate the following slot in the array on the first allocation.\n\tpublic constructor(private readonly handles: (Handle | T)[] = [1]) {}\n\n\tpublic clear() {\n\t\t// Restore the HandleTable's initial state by deleting all items in the handles array\n\t\t// and then re-inserting the value '1' in the 0th slot. (See comment at `handles` decl\n\t\t// for explanation.)\n\t\tthis.handles.splice(0, this.handles.length, 1);\n\t}\n\n\t/**\n\t * Allocates and returns the next available handle. Note that freed handles are recycled.\n\t */\n\tpublic allocate(): Handle {\n\t\t// Get the handle to the next free slot.\n\t\tconst free = this.next;\n\n\t\t// Update 'next' to point to the new head of the free list. We use the contents of\n\t\t// recycled slots to store the free list. The contents of the handles[free] will point\n\t\t// to the next available slot. If there are no free slots (i.e., 'handles' is full),\n\t\t// the slot will point to 'handles.length'. In this case, the handles array will grow\n\t\t// and we update 'next' to point to the new end of the array.\n\t\tthis.next = (this.handles[free] as Handle) ?? free + 1;\n\n\t\t// Out of paranoia, overwrite the contents of the newly allocated free slot with an\n\t\t// invalid handle value. This may help catch/diagnose bugs in the event the free list\n\t\t// becomes corrupted.\n\t\tthis.handles[free] = Handle.none;\n\n\t\treturn free;\n\t}\n\n\t/**\n\t * Allocates and returns the next available `count` handles.\n\t */\n\tpublic allocateMany(count: Handle) {\n\t\tconst handles = new Uint32Array(count);\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\thandles[i] = this.allocate();\n\t\t}\n\t\treturn handles;\n\t}\n\n\t/**\n\t * Returns the given handle to the free list.\n\t */\n\tpublic free(handle: Handle) {\n\t\tthis.handles[handle] = this.next;\n\t\tthis.next = handle;\n\t}\n\n\t/**\n\t * Get the value `T` associated with the given handle, if any.\n\t */\n\tpublic get(handle: Handle): T {\n\t\treturn this.handles[handle] as T;\n\t}\n\n\t/**\n\t * Set the value `T` associated with the given handle.\n\t */\n\tpublic set(handle: Handle, value: T) {\n\t\tthis.handles[handle] = value;\n\t}\n\n\t// Private helpers to get/set the head of the free list, which is stored in the 0th slot\n\t// of the handle array.\n\tprivate get next() {\n\t\treturn this.handles[0] as Handle;\n\t}\n\tprivate set next(handle: Handle) {\n\t\tthis.handles[0] = handle;\n\t}\n\n\tpublic getSummaryContent() {\n\t\treturn this.handles;\n\t}\n\n\tpublic static load<T>(data: (Handle | T)[]) {\n\t\treturn new HandleTable<T>(data);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,gBAAgB,EAGhB,YAAY,EACZ,iBAAiB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAKN,YAAY,EACZ,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAwBxC;;;GAGG;AACH,oBAAY,UAAU,CAAC,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,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,CAAC,OAAO,EAAE,sBAAsB;IAyBxD,SAAS,CAAC,WAAW,CACpB,UAAU,EAAE,yBAAyB,EACrC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO;IA+DzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAGF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAKnC;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAiBrB,QAAQ;IAoBf;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;CAiD/C"}
package/dist/matrix.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SharedMatrix = void 0;
8
- const common_utils_1 = require("@fluidframework/common-utils");
8
+ const core_utils_1 = require("@fluidframework/core-utils");
9
9
  const shared_object_base_1 = require("@fluidframework/shared-object-base");
10
10
  const runtime_utils_1 = require("@fluidframework/runtime-utils");
11
11
  const merge_tree_1 = require("@fluidframework/merge-tree");
@@ -70,7 +70,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
70
70
  * Subscribes the given IUndoConsumer to the matrix.
71
71
  */
72
72
  openUndo(consumer) {
73
- (0, common_utils_1.assert)(this.undo === undefined, 0x019 /* "SharedMatrix.openUndo() supports at most a single IUndoConsumer." */);
73
+ (0, core_utils_1.assert)(this.undo === undefined, 0x019 /* "SharedMatrix.openUndo() supports at most a single IUndoConsumer." */);
74
74
  this.undo = new undoprovider_1.MatrixUndoProvider(consumer, this, this.rows, this.cols);
75
75
  }
76
76
  // TODO: closeUndo()?
@@ -126,7 +126,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
126
126
  }
127
127
  // #endregion IMatrixReader
128
128
  setCell(row, col, value) {
129
- (0, common_utils_1.assert)(0 <= row && row < this.rowCount && 0 <= col && col < this.colCount, 0x01a /* "Trying to set out-of-bounds cell!" */);
129
+ (0, core_utils_1.assert)(0 <= row && row < this.rowCount && 0 <= col && col < this.colCount, 0x01a /* "Trying to set out-of-bounds cell!" */);
130
130
  this.setCellCore(row, col, value);
131
131
  // Avoid reentrancy by raising change notifications after the op is queued.
132
132
  for (const consumer of this.consumers.values()) {
@@ -135,7 +135,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
135
135
  }
136
136
  setCells(rowStart, colStart, colCount, values) {
137
137
  const rowCount = Math.ceil(values.length / colCount);
138
- (0, common_utils_1.assert)(0 <= rowStart &&
138
+ (0, core_utils_1.assert)(0 <= rowStart &&
139
139
  rowStart < this.rowCount &&
140
140
  0 <= colStart &&
141
141
  colStart < this.colCount &&
@@ -171,7 +171,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
171
171
  }
172
172
  }
173
173
  sendSetCellOp(row, col, value, rowHandle, colHandle, localSeq = this.nextLocalSeq(), rowsRefSeq = this.rows.getCollabWindow().currentSeq, colsRefSeq = this.cols.getCollabWindow().currentSeq) {
174
- (0, common_utils_1.assert)(this.isAttached(), 0x1e2 /* "Caller must ensure 'isAttached()' before calling 'sendSetCellOp'." */);
174
+ (0, core_utils_1.assert)(this.isAttached(), 0x1e2 /* "Caller must ensure 'isAttached()' before calling 'sendSetCellOp'." */);
175
175
  const op = {
176
176
  type: ops_1.MatrixOp.set,
177
177
  row,
@@ -196,7 +196,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
196
196
  const oppositeWindow = oppositeVector.getCollabWindow();
197
197
  // Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,
198
198
  // the MergeTree submits the op with the original 'localSeq'.
199
- (0, common_utils_1.assert)(localSeq >= oppositeWindow.localSeq, 0x01c /* "The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector." */);
199
+ (0, core_utils_1.assert)(localSeq >= oppositeWindow.localSeq, 0x01c /* "The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector." */);
200
200
  oppositeWindow.localSeq = localSeq;
201
201
  // If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.
202
202
  // Do not queue a message or track the pending op, as there will never be an ACK, etc.
@@ -299,22 +299,21 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
299
299
  submitLocalMessage(message, localOpMetadata) {
300
300
  // TODO: Recommend moving this assertion into SharedObject
301
301
  // (See https://github.com/microsoft/FluidFramework/issues/2559)
302
- (0, common_utils_1.assert)(this.isAttached() === true, 0x01d /* "Trying to submit message to runtime while detached!" */);
302
+ (0, core_utils_1.assert)(this.isAttached() === true, 0x01d /* "Trying to submit message to runtime while detached!" */);
303
303
  super.submitLocalMessage((0, shared_object_base_1.makeHandlesSerializable)(message, this.serializer, this.handle), localOpMetadata);
304
304
  // Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').
305
- (0, common_utils_1.assert)(this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq, 0x01e /* "Row and col collab window 'localSeq' desynchronized!" */);
305
+ (0, core_utils_1.assert)(this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq, 0x01e /* "Row and col collab window 'localSeq' desynchronized!" */);
306
306
  }
307
307
  didAttach() {
308
- var _a, _b;
309
308
  // We've attached we need to start generating and sending ops.
310
309
  // so start collaboration and provide a default client id incase we are not connected
311
310
  if (this.isAttached()) {
312
- this.rows.startOrUpdateCollaboration((_a = this.runtime.clientId) !== null && _a !== void 0 ? _a : "attached");
313
- this.cols.startOrUpdateCollaboration((_b = this.runtime.clientId) !== null && _b !== void 0 ? _b : "attached");
311
+ this.rows.startOrUpdateCollaboration(this.runtime.clientId ?? "attached");
312
+ this.cols.startOrUpdateCollaboration(this.runtime.clientId ?? "attached");
314
313
  }
315
314
  }
316
315
  onConnect() {
317
- (0, common_utils_1.assert)(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating, 0x01f /* "Row and col collab window 'collaborating' status desynchronized!" */);
316
+ (0, core_utils_1.assert)(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating, 0x01f /* "Row and col collab window 'collaborating' status desynchronized!" */);
318
317
  // Update merge tree collaboration information with new client ID and then resend pending ops
319
318
  this.rows.startOrUpdateCollaboration(this.runtime.clientId);
320
319
  this.cols.startOrUpdateCollaboration(this.runtime.clientId);
@@ -336,7 +335,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
336
335
  this.submitRowMessage(this.rows.regeneratePendingOp(content, localOpMetadata));
337
336
  break;
338
337
  default: {
339
- (0, common_utils_1.assert)(content.type === ops_1.MatrixOp.set, 0x020 /* "Unknown SharedMatrix 'op' type." */);
338
+ (0, core_utils_1.assert)(content.type === ops_1.MatrixOp.set, 0x020 /* "Unknown SharedMatrix 'op' type." */);
340
339
  const setOp = content;
341
340
  const { rowHandle, colHandle, localSeq, rowsRefSeq, colsRefSeq } = localOpMetadata;
342
341
  // If there are more pending local writes to the same row/col handle, it is important
@@ -380,7 +379,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
380
379
  this.rows.applyMsg(msg, local);
381
380
  break;
382
381
  default: {
383
- (0, common_utils_1.assert)(contents.type === ops_1.MatrixOp.set, 0x021 /* "SharedMatrix message contents have unexpected type!" */);
382
+ (0, core_utils_1.assert)(contents.type === ops_1.MatrixOp.set, 0x021 /* "SharedMatrix message contents have unexpected type!" */);
384
383
  const { row, col } = contents;
385
384
  if (local) {
386
385
  // We are receiving the ACK for a local pending set operation.
@@ -398,7 +397,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
398
397
  if (adjustedCol !== undefined) {
399
398
  const rowHandle = this.rows.getAllocatedHandle(adjustedRow);
400
399
  const colHandle = this.cols.getAllocatedHandle(adjustedCol);
401
- (0, common_utils_1.assert)((0, handletable_1.isHandleValid)(rowHandle) && (0, handletable_1.isHandleValid)(colHandle), 0x022 /* "SharedMatrix row and/or col handles are invalid!" */);
400
+ (0, core_utils_1.assert)((0, handletable_1.isHandleValid)(rowHandle) && (0, handletable_1.isHandleValid)(colHandle), 0x022 /* "SharedMatrix row and/or col handles are invalid!" */);
402
401
  // If there is a pending (unACKed) local write to the same cell, skip the current op
403
402
  // since it "happened before" the pending write.
404
403
  if (this.pending.getCell(rowHandle, colHandle) === undefined) {
@@ -428,7 +427,7 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
428
427
  // Note while we're awaiting the ACK for a local set, it's possible for the row/col to be
429
428
  // locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will
430
429
  // be 'undefined' or > 'localSeq'.
431
- (0, common_utils_1.assert)(!(pendingLocalSeq < localSeq), 0x023 /* "The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op." */);
430
+ (0, core_utils_1.assert)(!(pendingLocalSeq < localSeq), 0x023 /* "The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op." */);
432
431
  // If this is the most recent write to the cell by the local client, the stored localSeq
433
432
  // will be an exact match for the given 'localSeq'.
434
433
  return pendingLocalSeq === localSeq;
@@ -458,12 +457,12 @@ class SharedMatrix extends shared_object_base_1.SharedObject {
458
457
  const metadata = currentVector.applyStashedOp(op);
459
458
  const localSeq = currentVector.getCollabWindow().localSeq;
460
459
  const oppositeWindow = oppositeVector.getCollabWindow();
461
- (0, common_utils_1.assert)(localSeq > oppositeWindow.localSeq, 0x2d9);
460
+ (0, core_utils_1.assert)(localSeq > oppositeWindow.localSeq, 0x2d9);
462
461
  oppositeWindow.localSeq = localSeq;
463
462
  return metadata;
464
463
  }
465
464
  else {
466
- (0, common_utils_1.assert)(content.type === ops_1.MatrixOp.set, 0x2da /* "Unknown SharedMatrix 'op' type." */);
465
+ (0, core_utils_1.assert)(content.type === ops_1.MatrixOp.set, 0x2da /* "Unknown SharedMatrix 'op' type." */);
467
466
  const setOp = content;
468
467
  const rowHandle = this.rows.getAllocatedHandle(setOp.row);
469
468
  const colHandle = this.cols.getAllocatedHandle(setOp.col);
@@ -1 +1 @@
1
- {"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AK,CAAC,uCAAuC,CAAC,CAAC;YAErF,MAAM,KAAK,GAAG,OAAoB,CAAC;YACnC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC;YAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC;YAC1D,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC5B,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACxD,IAAI,QAAQ,KAAK,IAAI,EAAE;oBACtB,QAAQ,GAAG,SAAS,CAAC;iBACrB;gBAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;aAClD;YAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAmB;gBAChC,SAAS;gBACT,SAAS;gBACT,QAAQ;gBACR,UAAU;gBACV,UAAU;aACV,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;SAChB;IACF,CAAC;CACD;AAltBD,oCAktBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tSerializable,\n\tIChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidSerializer,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tSharedObject,\n\tSummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IMatrixProducer, IMatrixConsumer, IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\nimport {\n\tMergeTreeDeltaType,\n\tIMergeTreeOp,\n\tSegmentGroup,\n\tClient,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, reinsertSegmentIntoVector } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\trows = \"rows\",\n\tcols = \"cols\",\n\tcells = \"cells\",\n}\n\ninterface ISetOp<T> {\n\ttype: MatrixOp.set;\n\trow: number;\n\tcol: number;\n\tvalue: MatrixItem<T>;\n}\n\ninterface ISetOpMetadata {\n\trowHandle: Handle;\n\tcolHandle: Handle;\n\tlocalSeq: number;\n\trowsRefSeq: number;\n\tcolsRefSeq: number;\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n\textends SharedObject\n\timplements\n\t\tIMatrixProducer<MatrixItem<T>>,\n\t\tIMatrixReader<MatrixItem<T>>,\n\t\tIMatrixWriter<MatrixItem<T>>\n{\n\tprivate readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n\tpublic static getFactory() {\n\t\treturn new SharedMatrixFactory();\n\t}\n\n\tprivate readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n\tprivate readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n\tprivate cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n\tprivate pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n\tconstructor(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_matrix_\");\n\n\t\tthis.rows = new PermutationVector(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onRowDelta,\n\t\t\tthis.onRowHandlesRecycled,\n\t\t);\n\n\t\tthis.cols = new PermutationVector(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onColDelta,\n\t\t\tthis.onColHandlesRecycled,\n\t\t);\n\t}\n\n\tprivate undo?: MatrixUndoProvider<T>;\n\n\t/**\n\t * Subscribes the given IUndoConsumer to the matrix.\n\t */\n\tpublic openUndo(consumer: IUndoConsumer) {\n\t\tassert(\n\t\t\tthis.undo === undefined,\n\t\t\t0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */,\n\t\t);\n\n\t\tthis.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n\t}\n\n\t// TODO: closeUndo()?\n\n\tprivate get rowHandles() {\n\t\treturn this.rows.handleCache;\n\t}\n\tprivate get colHandles() {\n\t\treturn this.cols.handleCache;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n\t}\n\n\t// #region IMatrixProducer\n\n\topenMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>> {\n\t\tthis.consumers.add(consumer);\n\t\treturn this;\n\t}\n\n\tcloseMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n\t\tthis.consumers.delete(consumer);\n\t}\n\n\t// #endregion IMatrixProducer\n\n\t// #region IMatrixReader\n\n\tpublic get rowCount() {\n\t\treturn this.rows.getLength();\n\t}\n\tpublic get colCount() {\n\t\treturn this.cols.getLength();\n\t}\n\n\tpublic getCell(row: number, col: number): MatrixItem<T> {\n\t\t// Perf: When possible, bounds checking is performed inside the implementation for\n\t\t// 'getHandle()' so that it can be elided in the case of a cache hit. This\n\t\t// yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n\t\t// Map the logical (row, col) to associated storage handles.\n\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\tif (isHandleValid(rowHandle)) {\n\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\tif (isHandleValid(colHandle)) {\n\t\t\t\treturn this.cells.getCell(rowHandle, colHandle);\n\t\t\t}\n\t\t} else {\n\t\t\t// If we early exit because the given rowHandle is unallocated, we still need to\n\t\t\t// bounds-check the 'col' parameter.\n\t\t\tensureRange(col, this.cols.getLength());\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer(): IMatrixProducer<MatrixItem<T>> {\n\t\treturn this;\n\t}\n\n\t// #endregion IMatrixReader\n\n\tpublic setCell(row: number, col: number, value: MatrixItem<T>) {\n\t\tassert(\n\t\t\t0 <= row && row < this.rowCount && 0 <= col && col < this.colCount,\n\t\t\t0x01a /* \"Trying to set out-of-bounds cell!\" */,\n\t\t);\n\n\t\tthis.setCellCore(row, col, value);\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(row, col, 1, 1, this);\n\t\t}\n\t}\n\n\tpublic setCells(\n\t\trowStart: number,\n\t\tcolStart: number,\n\t\tcolCount: number,\n\t\tvalues: readonly MatrixItem<T>[],\n\t) {\n\t\tconst rowCount = Math.ceil(values.length / colCount);\n\n\t\tassert(\n\t\t\t0 <= rowStart &&\n\t\t\t\trowStart < this.rowCount &&\n\t\t\t\t0 <= colStart &&\n\t\t\t\tcolStart < this.colCount &&\n\t\t\t\t1 <= colCount &&\n\t\t\t\tcolCount <= this.colCount - colStart &&\n\t\t\t\trowCount <= this.rowCount - rowStart,\n\t\t\t0x01b /* \"Trying to set multiple out-of-bounds cells!\" */,\n\t\t);\n\n\t\tconst endCol = colStart + colCount;\n\t\tlet r = rowStart;\n\t\tlet c = colStart;\n\n\t\tfor (const value of values) {\n\t\t\tthis.setCellCore(r, c, value);\n\n\t\t\tif (++c === endCol) {\n\t\t\t\tc = colStart;\n\t\t\t\tr++;\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprivate setCellCore(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle = this.rows.getAllocatedHandle(row),\n\t\tcolHandle = this.cols.getAllocatedHandle(col),\n\t) {\n\t\tif (this.undo !== undefined) {\n\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\tif (oldValue === null) {\n\t\t\t\toldValue = undefined;\n\t\t\t}\n\n\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t}\n\n\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\tif (this.isAttached()) {\n\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t}\n\t}\n\n\tprivate sendSetCellOp(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle: Handle,\n\t\tcolHandle: Handle,\n\t\tlocalSeq = this.nextLocalSeq(),\n\t\trowsRefSeq = this.rows.getCollabWindow().currentSeq,\n\t\tcolsRefSeq = this.cols.getCollabWindow().currentSeq,\n\t) {\n\t\tassert(\n\t\t\tthis.isAttached(),\n\t\t\t0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */,\n\t\t);\n\n\t\tconst op: ISetOp<T> = {\n\t\t\ttype: MatrixOp.set,\n\t\t\trow,\n\t\t\tcol,\n\t\t\tvalue,\n\t\t};\n\n\t\tconst metadata: ISetOpMetadata = {\n\t\t\trowHandle,\n\t\t\tcolHandle,\n\t\t\tlocalSeq,\n\t\t\trowsRefSeq,\n\t\t\tcolsRefSeq,\n\t\t};\n\n\t\tthis.submitLocalMessage(op, metadata);\n\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t}\n\n\tprivate submitVectorMessage(\n\t\tcurrentVector: PermutationVector,\n\t\toppositeVector: PermutationVector,\n\t\tdimension: SnapshotPath.rows | SnapshotPath.cols,\n\t\tmessage: any,\n\t) {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n\t\t// for each submitted op it not aware of to keep them synchronized.\n\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t// Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n\t\t// the MergeTree submits the op with the original 'localSeq'.\n\t\tassert(\n\t\t\tlocalSeq >= oppositeWindow.localSeq,\n\t\t\t0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */,\n\t\t);\n\n\t\toppositeWindow.localSeq = localSeq;\n\n\t\t// If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n\t\t// Do not queue a message or track the pending op, as there will never be an ACK, etc.\n\t\tif (this.isAttached()) {\n\t\t\t// Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n\t\t\tmessage.target = dimension;\n\n\t\t\tthis.submitLocalMessage(\n\t\t\t\tmessage,\n\t\t\t\tcurrentVector.peekPendingSegmentGroups(\n\t\t\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate submitColMessage(message: any) {\n\t\tthis.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n\t}\n\n\tpublic insertCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.insert(colStart, count));\n\t}\n\n\tpublic removeCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.remove(colStart, count));\n\t}\n\n\tprivate submitRowMessage(message: any) {\n\t\tthis.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n\t}\n\n\tpublic insertRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.insert(rowStart, count));\n\t}\n\n\tpublic removeRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.remove(rowStart, count));\n\t}\n\n\t/** @internal */ public _undoRemoveRows(rowStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.rows, rowStart, spec);\n\t\tthis.submitRowMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted rows.\n\t\tlet rowHandle = inserted.start;\n\t\tconst rowCount = inserted.cachedLength;\n\t\tfor (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n\t\t}\n\t}\n\n\t/** @internal */ public _undoRemoveCols(colStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.cols, colStart, spec);\n\t\tthis.submitColMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted cols.\n\t\tlet colHandle = inserted.start;\n\t\tconst colCount = inserted.cachedLength;\n\t\tfor (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n\t\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.rows.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.cols.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.cells,\n\t\t\tserializer.stringify([this.cells.snapshot(), this.pending.snapshot()], this.handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer on the GC data for this SharedMatrix.\n\t * All the IFluidHandle's stored in the cells represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tserializer.stringify(this.getCell(row, col), this.handle);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advances the 'localSeq' counter for the cell data operation currently being queued.\n\t *\n\t * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n\t * automatically advance 'localSeq'.\n\t */\n\tprivate nextLocalSeq() {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n\t\t// for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n\t\t// need to bump both counters.)\n\n\t\tthis.cols.getCollabWindow().localSeq++;\n\t\treturn ++this.rows.getCollabWindow().localSeq;\n\t}\n\n\tprotected submitLocalMessage(message: any, localOpMetadata?: any) {\n\t\t// TODO: Recommend moving this assertion into SharedObject\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/2559)\n\t\tassert(\n\t\t\tthis.isAttached() === true,\n\t\t\t0x01d /* \"Trying to submit message to runtime while detached!\" */,\n\t\t);\n\n\t\tsuper.submitLocalMessage(\n\t\t\tmakeHandlesSerializable(message, this.serializer, this.handle),\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\t// Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n\t\t\t0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n\t\t);\n\t}\n\n\tprotected didAttach() {\n\t\t// We've attached we need to start generating and sending ops.\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\tprotected onConnect() {\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n\t\t\t0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */,\n\t\t);\n\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t}\n\n\tprivate rebasePosition(\n\t\tclient: Client,\n\t\tpos: number,\n\t\treferenceSequenceNumber: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tconst { clientId } = client.getCollabWindow();\n\t\tconst { segment, offset } = client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{ referenceSequenceNumber, clientId: client.getLongClientId(clientId) },\n\t\t\tlocalSeq,\n\t\t);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn client.findReconnectionPosition(segment, localSeq) + offset;\n\t}\n\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tswitch (content.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.submitColMessage(\n\t\t\t\t\tthis.cols.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.submitRowMessage(\n\t\t\t\t\tthis.rows.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontent.type === MatrixOp.set,\n\t\t\t\t\t0x020 /* \"Unknown SharedMatrix 'op' type.\" */,\n\t\t\t\t);\n\n\t\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\t\tconst { rowHandle, colHandle, localSeq, rowsRefSeq, colsRefSeq } =\n\t\t\t\t\tlocalOpMetadata as ISetOpMetadata;\n\n\t\t\t\t// If there are more pending local writes to the same row/col handle, it is important\n\t\t\t\t// to skip resubmitting this op since it is possible the row/col handle has been recycled\n\t\t\t\t// and now refers to a different position than when this op was originally submitted.\n\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\tconst row = this.rebasePosition(this.rows, setOp.row, rowsRefSeq, localSeq);\n\t\t\t\t\tconst col = this.rebasePosition(this.cols, setOp.col, colsRefSeq, localSeq);\n\n\t\t\t\t\tif (row !== undefined && col !== undefined && row >= 0 && col >= 0) {\n\t\t\t\t\t\tthis.sendSetCellOp(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tcol,\n\t\t\t\t\t\t\tsetOp.value,\n\t\t\t\t\t\t\trowHandle,\n\t\t\t\t\t\t\tcolHandle,\n\t\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\t\trowsRefSeq,\n\t\t\t\t\t\t\tcolsRefSeq,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\ttry {\n\t\t\tawait this.rows.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.rows),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tawait this.cols.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.cols),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tconst [cellData, pendingCliSeqData] = await deserializeBlob(\n\t\t\t\tstorage,\n\t\t\t\tSnapshotPath.cells,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\tthis.cells = SparseArray2D.load(cellData);\n\t\t\tthis.pending = SparseArray2D.load(pendingCliSeqData);\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\trawMessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tconst msg = parseHandles(rawMessage, this.serializer);\n\n\t\tconst contents = msg.contents;\n\n\t\tswitch (contents.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.cols.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.rows.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontents.type === MatrixOp.set,\n\t\t\t\t\t0x021 /* \"SharedMatrix message contents have unexpected type!\" */,\n\t\t\t\t);\n\n\t\t\t\tconst { row, col } = contents;\n\n\t\t\t\tif (local) {\n\t\t\t\t\t// We are receiving the ACK for a local pending set operation.\n\t\t\t\t\tconst { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n\t\t\t\t\t// If this is the most recent write to the cell by the local client, remove our\n\t\t\t\t\t// entry from 'pendingCliSeqs' to resume allowing remote writes.\n\t\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\t\tthis.pending.setCell(rowHandle, colHandle, undefined);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst adjustedRow = this.rows.adjustPosition(row, rawMessage);\n\n\t\t\t\t\tif (adjustedRow !== undefined) {\n\t\t\t\t\t\tconst adjustedCol = this.cols.adjustPosition(col, rawMessage);\n\n\t\t\t\t\t\tif (adjustedCol !== undefined) {\n\t\t\t\t\t\t\tconst rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n\t\t\t\t\t\t\tconst colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t\t\t\t\t\t0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If there is a pending (unACKed) local write to the same cell, skip the current op\n\t\t\t\t\t\t\t// since it \"happened before\" the pending write.\n\t\t\t\t\t\t\tif (this.pending.getCell(rowHandle, colHandle) === undefined) {\n\t\t\t\t\t\t\t\tconst { value } = contents;\n\t\t\t\t\t\t\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\t\t\t\t\t\t\tfor (const consumer of this.consumers.values()) {\n\t\t\t\t\t\t\t\t\tconsumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n\tprivate readonly onRowDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.rowsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n\tprivate readonly onColDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.colsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\tprivate readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n\t\tfor (const rowHandle of rowHandles) {\n\t\t\tthis.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t\tthis.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t}\n\t};\n\n\tprivate readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n\t\tfor (const colHandle of colHandles) {\n\t\t\tthis.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t\tthis.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t}\n\t};\n\n\t/**\n\t * Returns true if the latest pending write to the cell indicated by the given row/col handles\n\t * matches the given 'localSeq'.\n\t *\n\t * A return value of `true` indicates that there are no later local operations queued that will\n\t * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n\t * with a different value as well as row/col removals that might recycled the given row/col handles.\n\t */\n\tprivate isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n\t\t// Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n\t\t// locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n\t\t// be 'undefined' or > 'localSeq'.\n\t\tassert(\n\t\t\t!(pendingLocalSeq < localSeq),\n\t\t\t0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */,\n\t\t);\n\n\t\t// If this is the most recent write to the cell by the local client, the stored localSeq\n\t\t// will be an exact match for the given 'localSeq'.\n\t\treturn pendingLocalSeq === localSeq;\n\t}\n\n\tpublic toString() {\n\t\tlet s = `client:${\n\t\t\tthis.runtime.clientId\n\t\t}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n\t\tfor (let r = 0; r < this.rowCount; r++) {\n\t\t\ts += ` [`;\n\t\t\tfor (let c = 0; c < this.colCount; c++) {\n\t\t\t\tif (c > 0) {\n\t\t\t\t\ts += \", \";\n\t\t\t\t}\n\n\t\t\t\ts += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n\t\t\t}\n\t\t\ts += \"]\\n\";\n\t\t}\n\n\t\treturn `${s}\\n`;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): unknown {\n\t\tif (content.target === SnapshotPath.cols || content.target === SnapshotPath.rows) {\n\t\t\tconst op = content as IMergeTreeOp;\n\t\t\tconst currentVector = content.target === SnapshotPath.cols ? this.cols : this.rows;\n\t\t\tconst oppositeVector = content.target === SnapshotPath.cols ? this.rows : this.cols;\n\t\t\tconst metadata = currentVector.applyStashedOp(op);\n\t\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t\tassert(\n\t\t\t\tlocalSeq > oppositeWindow.localSeq,\n\t\t\t\t0x2d9,\n\t\t\t\t/* \"The 'localSeq' of the vector applying stashed op must > the 'localSeq' of the other vector.\" */\n\t\t\t);\n\n\t\t\toppositeWindow.localSeq = localSeq;\n\n\t\t\treturn metadata;\n\t\t} else {\n\t\t\tassert(content.type === MatrixOp.set, 0x2da /* \"Unknown SharedMatrix 'op' type.\" */);\n\n\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\tconst rowHandle = this.rows.getAllocatedHandle(setOp.row);\n\t\t\tconst colHandle = this.cols.getAllocatedHandle(setOp.col);\n\t\t\tconst rowsRefSeq = this.rows.getCollabWindow().currentSeq;\n\t\t\tconst colsRefSeq = this.cols.getCollabWindow().currentSeq;\n\t\t\tif (this.undo !== undefined) {\n\t\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (oldValue === null) {\n\t\t\t\t\toldValue = undefined;\n\t\t\t\t}\n\n\t\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t\t}\n\n\t\t\tthis.cells.setCell(rowHandle, colHandle, setOp.value);\n\t\t\tconst localSeq = this.nextLocalSeq();\n\t\t\tconst metadata: ISetOpMetadata = {\n\t\t\t\trowHandle,\n\t\t\t\tcolHandle,\n\t\t\t\tlocalSeq,\n\t\t\t\trowsRefSeq,\n\t\t\t\tcolsRefSeq,\n\t\t\t};\n\n\t\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t\t\treturn metadata;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAQpD,2EAM4C;AAE5C,iEAA2F;AAE3F,2DAMoC;AACpC,+BAAiC;AACjC,2DAAmF;AACnF,mDAAgD;AAChD,uCAAgD;AAChD,+CAAsD;AACtD,mDAAkD;AAClD,mCAAsC;AAEtC,iDAAoD;AA8BpD;;;;;;;;;;;GAWG;AACH,MAAa,YACZ,SAAQ,iCAAY;IAkBpB,YACC,OAA+B,EACxB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;QAHzC,OAAE,GAAF,EAAE,CAAQ;QAdD,cAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;QAS/D,UAAK,GAAG,IAAI,6BAAa,EAAiB,CAAC,CAAC,sBAAsB;QAClE,YAAO,GAAG,IAAI,6BAAa,EAAU,CAAC,CAAC,yBAAyB;QA4jBxE,sFAAsF;QACrE,eAAU,GAAG,CAC7B,QAAgB,EAChB,YAAoB,EACpB,aAAqB,EACpB,EAAE;YACH,KAAK,MAAM,QAAQ,IA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AAO,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAmB;gBAChC,SAAS;gBACT,SAAS;gBACT,QAAQ;gBACR,UAAU;gBACV,UAAU;aACV,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;SAChB;IACF,CAAC;CACD;AAltBD,oCAktBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tSerializable,\n\tIChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidSerializer,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tSharedObject,\n\tSummarySerializer,\n} from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IMatrixProducer, IMatrixConsumer, IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\nimport {\n\tMergeTreeDeltaType,\n\tIMergeTreeOp,\n\tSegmentGroup,\n\tClient,\n\tIJSONSegment,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixOp } from \"./ops\";\nimport { PermutationVector, reinsertSegmentIntoVector } from \"./permutationvector\";\nimport { SparseArray2D } from \"./sparsearray2d\";\nimport { SharedMatrixFactory } from \"./runtime\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { ensureRange } from \"./range\";\nimport { IUndoConsumer } from \"./types\";\nimport { MatrixUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n\trows = \"rows\",\n\tcols = \"cols\",\n\tcells = \"cells\",\n}\n\ninterface ISetOp<T> {\n\ttype: MatrixOp.set;\n\trow: number;\n\tcol: number;\n\tvalue: MatrixItem<T>;\n}\n\ninterface ISetOpMetadata {\n\trowHandle: Handle;\n\tcolHandle: Handle;\n\tlocalSeq: number;\n\trowsRefSeq: number;\n\tcolsRefSeq: number;\n}\n\n/**\n * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,\n * excluding null. (However, nulls may be embedded inside objects and arrays.)\n */\n// eslint-disable-next-line @rushstack/no-new-null -- Using 'null' to disallow 'null'.\nexport type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;\n\n/**\n * A SharedMatrix holds a rectangular 2D array of values. Supported operations\n * include setting values and inserting/removing rows and columns.\n *\n * Matrix values may be any Fluid serializable type, which is the set of JSON\n * serializable types extended to include IFluidHandles.\n *\n * Fluid's SharedMatrix implementation works equally well for dense and sparse\n * matrix data and physically stores data in Z-order to leverage CPU caches and\n * prefetching when reading in either row or column major order. (See README.md\n * for more details.)\n */\nexport class SharedMatrix<T = any>\n\textends SharedObject\n\timplements\n\t\tIMatrixProducer<MatrixItem<T>>,\n\t\tIMatrixReader<MatrixItem<T>>,\n\t\tIMatrixWriter<MatrixItem<T>>\n{\n\tprivate readonly consumers = new Set<IMatrixConsumer<MatrixItem<T>>>();\n\n\tpublic static getFactory() {\n\t\treturn new SharedMatrixFactory();\n\t}\n\n\tprivate readonly rows: PermutationVector; // Map logical row to storage handle (if any)\n\tprivate readonly cols: PermutationVector; // Map logical col to storage handle (if any)\n\n\tprivate cells = new SparseArray2D<MatrixItem<T>>(); // Stores cell values.\n\tprivate pending = new SparseArray2D<number>(); // Tracks pending writes.\n\n\tconstructor(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_matrix_\");\n\n\t\tthis.rows = new PermutationVector(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onRowDelta,\n\t\t\tthis.onRowHandlesRecycled,\n\t\t);\n\n\t\tthis.cols = new PermutationVector(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.logger,\n\t\t\truntime,\n\t\t\tthis.onColDelta,\n\t\t\tthis.onColHandlesRecycled,\n\t\t);\n\t}\n\n\tprivate undo?: MatrixUndoProvider<T>;\n\n\t/**\n\t * Subscribes the given IUndoConsumer to the matrix.\n\t */\n\tpublic openUndo(consumer: IUndoConsumer) {\n\t\tassert(\n\t\t\tthis.undo === undefined,\n\t\t\t0x019 /* \"SharedMatrix.openUndo() supports at most a single IUndoConsumer.\" */,\n\t\t);\n\n\t\tthis.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);\n\t}\n\n\t// TODO: closeUndo()?\n\n\tprivate get rowHandles() {\n\t\treturn this.rows.handleCache;\n\t}\n\tprivate get colHandles() {\n\t\treturn this.cols.handleCache;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedMatrixFactory.Type) as SharedMatrix<T>;\n\t}\n\n\t// #region IMatrixProducer\n\n\topenMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>> {\n\t\tthis.consumers.add(consumer);\n\t\treturn this;\n\t}\n\n\tcloseMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void {\n\t\tthis.consumers.delete(consumer);\n\t}\n\n\t// #endregion IMatrixProducer\n\n\t// #region IMatrixReader\n\n\tpublic get rowCount() {\n\t\treturn this.rows.getLength();\n\t}\n\tpublic get colCount() {\n\t\treturn this.cols.getLength();\n\t}\n\n\tpublic getCell(row: number, col: number): MatrixItem<T> {\n\t\t// Perf: When possible, bounds checking is performed inside the implementation for\n\t\t// 'getHandle()' so that it can be elided in the case of a cache hit. This\n\t\t// yields an ~40% improvement in the case of a cache hit (node v12 x64)\n\n\t\t// Map the logical (row, col) to associated storage handles.\n\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\tif (isHandleValid(rowHandle)) {\n\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\tif (isHandleValid(colHandle)) {\n\t\t\t\treturn this.cells.getCell(rowHandle, colHandle);\n\t\t\t}\n\t\t} else {\n\t\t\t// If we early exit because the given rowHandle is unallocated, we still need to\n\t\t\t// bounds-check the 'col' parameter.\n\t\t\tensureRange(col, this.cols.getLength());\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer(): IMatrixProducer<MatrixItem<T>> {\n\t\treturn this;\n\t}\n\n\t// #endregion IMatrixReader\n\n\tpublic setCell(row: number, col: number, value: MatrixItem<T>) {\n\t\tassert(\n\t\t\t0 <= row && row < this.rowCount && 0 <= col && col < this.colCount,\n\t\t\t0x01a /* \"Trying to set out-of-bounds cell!\" */,\n\t\t);\n\n\t\tthis.setCellCore(row, col, value);\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(row, col, 1, 1, this);\n\t\t}\n\t}\n\n\tpublic setCells(\n\t\trowStart: number,\n\t\tcolStart: number,\n\t\tcolCount: number,\n\t\tvalues: readonly MatrixItem<T>[],\n\t) {\n\t\tconst rowCount = Math.ceil(values.length / colCount);\n\n\t\tassert(\n\t\t\t0 <= rowStart &&\n\t\t\t\trowStart < this.rowCount &&\n\t\t\t\t0 <= colStart &&\n\t\t\t\tcolStart < this.colCount &&\n\t\t\t\t1 <= colCount &&\n\t\t\t\tcolCount <= this.colCount - colStart &&\n\t\t\t\trowCount <= this.rowCount - rowStart,\n\t\t\t0x01b /* \"Trying to set multiple out-of-bounds cells!\" */,\n\t\t);\n\n\t\tconst endCol = colStart + colCount;\n\t\tlet r = rowStart;\n\t\tlet c = colStart;\n\n\t\tfor (const value of values) {\n\t\t\tthis.setCellCore(r, c, value);\n\n\t\t\tif (++c === endCol) {\n\t\t\t\tc = colStart;\n\t\t\t\tr++;\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, colStart, rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprivate setCellCore(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle = this.rows.getAllocatedHandle(row),\n\t\tcolHandle = this.cols.getAllocatedHandle(col),\n\t) {\n\t\tif (this.undo !== undefined) {\n\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\tif (oldValue === null) {\n\t\t\t\toldValue = undefined;\n\t\t\t}\n\n\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t}\n\n\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\tif (this.isAttached()) {\n\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t}\n\t}\n\n\tprivate sendSetCellOp(\n\t\trow: number,\n\t\tcol: number,\n\t\tvalue: MatrixItem<T>,\n\t\trowHandle: Handle,\n\t\tcolHandle: Handle,\n\t\tlocalSeq = this.nextLocalSeq(),\n\t\trowsRefSeq = this.rows.getCollabWindow().currentSeq,\n\t\tcolsRefSeq = this.cols.getCollabWindow().currentSeq,\n\t) {\n\t\tassert(\n\t\t\tthis.isAttached(),\n\t\t\t0x1e2 /* \"Caller must ensure 'isAttached()' before calling 'sendSetCellOp'.\" */,\n\t\t);\n\n\t\tconst op: ISetOp<T> = {\n\t\t\ttype: MatrixOp.set,\n\t\t\trow,\n\t\t\tcol,\n\t\t\tvalue,\n\t\t};\n\n\t\tconst metadata: ISetOpMetadata = {\n\t\t\trowHandle,\n\t\t\tcolHandle,\n\t\t\tlocalSeq,\n\t\t\trowsRefSeq,\n\t\t\tcolsRefSeq,\n\t\t};\n\n\t\tthis.submitLocalMessage(op, metadata);\n\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t}\n\n\tprivate submitVectorMessage(\n\t\tcurrentVector: PermutationVector,\n\t\toppositeVector: PermutationVector,\n\t\tdimension: SnapshotPath.rows | SnapshotPath.cols,\n\t\tmessage: any,\n\t) {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally advance each MergeTree's 'localSeq' counter\n\t\t// for each submitted op it not aware of to keep them synchronized.\n\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t// Note that the comparison is '>=' because, in the case the MergeTree is regenerating ops for reconnection,\n\t\t// the MergeTree submits the op with the original 'localSeq'.\n\t\tassert(\n\t\t\tlocalSeq >= oppositeWindow.localSeq,\n\t\t\t0x01c /* \"The 'localSeq' of the vector submitting an op must >= the 'localSeq' of the other vector.\" */,\n\t\t);\n\n\t\toppositeWindow.localSeq = localSeq;\n\n\t\t// If the SharedMatrix is local, it's state will be submitted via a Snapshot when initially connected.\n\t\t// Do not queue a message or track the pending op, as there will never be an ACK, etc.\n\t\tif (this.isAttached()) {\n\t\t\t// Record whether this `op` targets rows or cols. (See dispatch in `processCore()`)\n\t\t\tmessage.target = dimension;\n\n\t\t\tthis.submitLocalMessage(\n\t\t\t\tmessage,\n\t\t\t\tcurrentVector.peekPendingSegmentGroups(\n\t\t\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate submitColMessage(message: any) {\n\t\tthis.submitVectorMessage(this.cols, this.rows, SnapshotPath.cols, message);\n\t}\n\n\tpublic insertCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.insert(colStart, count));\n\t}\n\n\tpublic removeCols(colStart: number, count: number) {\n\t\tthis.submitColMessage(this.cols.remove(colStart, count));\n\t}\n\n\tprivate submitRowMessage(message: any) {\n\t\tthis.submitVectorMessage(this.rows, this.cols, SnapshotPath.rows, message);\n\t}\n\n\tpublic insertRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.insert(rowStart, count));\n\t}\n\n\tpublic removeRows(rowStart: number, count: number) {\n\t\tthis.submitRowMessage(this.rows.remove(rowStart, count));\n\t}\n\n\t/** @internal */ public _undoRemoveRows(rowStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.rows, rowStart, spec);\n\t\tthis.submitRowMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted rows.\n\t\tlet rowHandle = inserted.start;\n\t\tconst rowCount = inserted.cachedLength;\n\t\tfor (let row = rowStart; row < rowStart + rowCount; row++, rowHandle++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tconst colHandle = this.colHandles.getHandle(col);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(rowStart, /* colStart: */ 0, rowCount, this.colCount, this);\n\t\t}\n\t}\n\n\t/** @internal */ public _undoRemoveCols(colStart: number, spec: IJSONSegment) {\n\t\tconst { op, inserted } = reinsertSegmentIntoVector(this.cols, colStart, spec);\n\t\tthis.submitColMessage(op);\n\n\t\t// Generate setCell ops for each populated cell in the reinserted cols.\n\t\tlet colHandle = inserted.start;\n\t\tconst colCount = inserted.cachedLength;\n\t\tfor (let col = colStart; col < colStart + colCount; col++, colHandle++) {\n\t\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\t\tconst rowHandle = this.rowHandles.getHandle(row);\n\t\t\t\tconst value = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (this.isAttached() && value !== undefined && value !== null) {\n\t\t\t\t\tthis.sendSetCellOp(row, col, value, rowHandle, colHandle);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Avoid reentrancy by raising change notifications after the op is queued.\n\t\tfor (const consumer of this.consumers.values()) {\n\t\t\tconsumer.cellsChanged(/* rowStart: */ 0, colStart, this.rowCount, colCount, this);\n\t\t}\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.rows,\n\t\t\tthis.rows.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.cols,\n\t\t\tthis.cols.summarize(this.runtime, this.handle, serializer),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.cells,\n\t\t\tserializer.stringify([this.cells.snapshot(), this.pending.snapshot()], this.handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer on the GC data for this SharedMatrix.\n\t * All the IFluidHandle's stored in the cells represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\tfor (let row = 0; row < this.rowCount; row++) {\n\t\t\tfor (let col = 0; col < this.colCount; col++) {\n\t\t\t\tserializer.stringify(this.getCell(row, col), this.handle);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advances the 'localSeq' counter for the cell data operation currently being queued.\n\t *\n\t * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will\n\t * automatically advance 'localSeq'.\n\t */\n\tprivate nextLocalSeq() {\n\t\t// Ideally, we would have a single 'localSeq' counter that is shared between both PermutationVectors\n\t\t// and the SharedMatrix's cell data. Instead, we externally bump each MergeTree's 'localSeq' counter\n\t\t// for SharedMatrix ops it's not aware of to keep them synchronized. (For cell data operations, we\n\t\t// need to bump both counters.)\n\n\t\tthis.cols.getCollabWindow().localSeq++;\n\t\treturn ++this.rows.getCollabWindow().localSeq;\n\t}\n\n\tprotected submitLocalMessage(message: any, localOpMetadata?: any) {\n\t\t// TODO: Recommend moving this assertion into SharedObject\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/2559)\n\t\tassert(\n\t\t\tthis.isAttached() === true,\n\t\t\t0x01d /* \"Trying to submit message to runtime while detached!\" */,\n\t\t);\n\n\t\tsuper.submitLocalMessage(\n\t\t\tmakeHandlesSerializable(message, this.serializer, this.handle),\n\t\t\tlocalOpMetadata,\n\t\t);\n\n\t\t// Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,\n\t\t\t0x01e /* \"Row and col collab window 'localSeq' desynchronized!\" */,\n\t\t);\n\t}\n\n\tprotected didAttach() {\n\t\t// We've attached we need to start generating and sending ops.\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\tprotected onConnect() {\n\t\tassert(\n\t\t\tthis.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating,\n\t\t\t0x01f /* \"Row and col collab window 'collaborating' status desynchronized!\" */,\n\t\t);\n\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.rows.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t\tthis.cols.startOrUpdateCollaboration(this.runtime.clientId as string);\n\t}\n\n\tprivate rebasePosition(\n\t\tclient: Client,\n\t\tpos: number,\n\t\treferenceSequenceNumber: number,\n\t\tlocalSeq: number,\n\t): number | undefined {\n\t\tconst { clientId } = client.getCollabWindow();\n\t\tconst { segment, offset } = client.getContainingSegment(\n\t\t\tpos,\n\t\t\t{ referenceSequenceNumber, clientId: client.getLongClientId(clientId) },\n\t\t\tlocalSeq,\n\t\t);\n\t\tif (segment === undefined || offset === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn client.findReconnectionPosition(segment, localSeq) + offset;\n\t}\n\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tswitch (content.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.submitColMessage(\n\t\t\t\t\tthis.cols.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.submitRowMessage(\n\t\t\t\t\tthis.rows.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontent.type === MatrixOp.set,\n\t\t\t\t\t0x020 /* \"Unknown SharedMatrix 'op' type.\" */,\n\t\t\t\t);\n\n\t\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\t\tconst { rowHandle, colHandle, localSeq, rowsRefSeq, colsRefSeq } =\n\t\t\t\t\tlocalOpMetadata as ISetOpMetadata;\n\n\t\t\t\t// If there are more pending local writes to the same row/col handle, it is important\n\t\t\t\t// to skip resubmitting this op since it is possible the row/col handle has been recycled\n\t\t\t\t// and now refers to a different position than when this op was originally submitted.\n\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\tconst row = this.rebasePosition(this.rows, setOp.row, rowsRefSeq, localSeq);\n\t\t\t\t\tconst col = this.rebasePosition(this.cols, setOp.col, colsRefSeq, localSeq);\n\n\t\t\t\t\tif (row !== undefined && col !== undefined && row >= 0 && col >= 0) {\n\t\t\t\t\t\tthis.sendSetCellOp(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tcol,\n\t\t\t\t\t\t\tsetOp.value,\n\t\t\t\t\t\t\trowHandle,\n\t\t\t\t\t\t\tcolHandle,\n\t\t\t\t\t\t\tlocalSeq,\n\t\t\t\t\t\t\trowsRefSeq,\n\t\t\t\t\t\t\tcolsRefSeq,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\ttry {\n\t\t\tawait this.rows.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.rows),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tawait this.cols.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.cols),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tconst [cellData, pendingCliSeqData] = await deserializeBlob(\n\t\t\t\tstorage,\n\t\t\t\tSnapshotPath.cells,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\tthis.cells = SparseArray2D.load(cellData);\n\t\t\tthis.pending = SparseArray2D.load(pendingCliSeqData);\n\t\t} catch (error) {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"MatrixLoadFailed\" }, error);\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\trawMessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tconst msg = parseHandles(rawMessage, this.serializer);\n\n\t\tconst contents = msg.contents;\n\n\t\tswitch (contents.target) {\n\t\t\tcase SnapshotPath.cols:\n\t\t\t\tthis.cols.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tcase SnapshotPath.rows:\n\t\t\t\tthis.rows.applyMsg(msg, local);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tassert(\n\t\t\t\t\tcontents.type === MatrixOp.set,\n\t\t\t\t\t0x021 /* \"SharedMatrix message contents have unexpected type!\" */,\n\t\t\t\t);\n\n\t\t\t\tconst { row, col } = contents;\n\n\t\t\t\tif (local) {\n\t\t\t\t\t// We are receiving the ACK for a local pending set operation.\n\t\t\t\t\tconst { rowHandle, colHandle, localSeq } = localOpMetadata as ISetOpMetadata;\n\n\t\t\t\t\t// If this is the most recent write to the cell by the local client, remove our\n\t\t\t\t\t// entry from 'pendingCliSeqs' to resume allowing remote writes.\n\t\t\t\t\tif (this.isLatestPendingWrite(rowHandle, colHandle, localSeq)) {\n\t\t\t\t\t\tthis.pending.setCell(rowHandle, colHandle, undefined);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst adjustedRow = this.rows.adjustPosition(row, rawMessage);\n\n\t\t\t\t\tif (adjustedRow !== undefined) {\n\t\t\t\t\t\tconst adjustedCol = this.cols.adjustPosition(col, rawMessage);\n\n\t\t\t\t\t\tif (adjustedCol !== undefined) {\n\t\t\t\t\t\t\tconst rowHandle = this.rows.getAllocatedHandle(adjustedRow);\n\t\t\t\t\t\t\tconst colHandle = this.cols.getAllocatedHandle(adjustedCol);\n\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t\t\t\t\t\t0x022 /* \"SharedMatrix row and/or col handles are invalid!\" */,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If there is a pending (unACKed) local write to the same cell, skip the current op\n\t\t\t\t\t\t\t// since it \"happened before\" the pending write.\n\t\t\t\t\t\t\tif (this.pending.getCell(rowHandle, colHandle) === undefined) {\n\t\t\t\t\t\t\t\tconst { value } = contents;\n\t\t\t\t\t\t\t\tthis.cells.setCell(rowHandle, colHandle, value);\n\n\t\t\t\t\t\t\t\tfor (const consumer of this.consumers.values()) {\n\t\t\t\t\t\t\t\t\tconsumer.cellsChanged(adjustedRow, adjustedCol, 1, 1, this);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.\n\tprivate readonly onRowDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.rowsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\t// Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.\n\tprivate readonly onColDelta = (\n\t\tposition: number,\n\t\tremovedCount: number,\n\t\tinsertedCount: number,\n\t) => {\n\t\tfor (const consumer of this.consumers) {\n\t\t\tconsumer.colsChanged(position, removedCount, insertedCount, this);\n\t\t}\n\t};\n\n\tprivate readonly onRowHandlesRecycled = (rowHandles: Handle[]) => {\n\t\tfor (const rowHandle of rowHandles) {\n\t\t\tthis.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t\tthis.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);\n\t\t}\n\t};\n\n\tprivate readonly onColHandlesRecycled = (colHandles: Handle[]) => {\n\t\tfor (const colHandle of colHandles) {\n\t\t\tthis.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t\tthis.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);\n\t\t}\n\t};\n\n\t/**\n\t * Returns true if the latest pending write to the cell indicated by the given row/col handles\n\t * matches the given 'localSeq'.\n\t *\n\t * A return value of `true` indicates that there are no later local operations queued that will\n\t * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell\n\t * with a different value as well as row/col removals that might recycled the given row/col handles.\n\t */\n\tprivate isLatestPendingWrite(rowHandle: Handle, colHandle: Handle, localSeq: number) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst pendingLocalSeq = this.pending.getCell(rowHandle, colHandle)!;\n\n\t\t// Note while we're awaiting the ACK for a local set, it's possible for the row/col to be\n\t\t// locally removed and the row/col handles recycled. If this happens, the pendingLocalSeq will\n\t\t// be 'undefined' or > 'localSeq'.\n\t\tassert(\n\t\t\t!(pendingLocalSeq < localSeq),\n\t\t\t0x023 /* \"The 'localSeq' of pending write (if any) must be <= the localSeq of the currently processed op.\" */,\n\t\t);\n\n\t\t// If this is the most recent write to the cell by the local client, the stored localSeq\n\t\t// will be an exact match for the given 'localSeq'.\n\t\treturn pendingLocalSeq === localSeq;\n\t}\n\n\tpublic toString() {\n\t\tlet s = `client:${\n\t\t\tthis.runtime.clientId\n\t\t}\\nrows: ${this.rows.toString()}\\ncols: ${this.cols.toString()}\\n\\n`;\n\n\t\tfor (let r = 0; r < this.rowCount; r++) {\n\t\t\ts += ` [`;\n\t\t\tfor (let c = 0; c < this.colCount; c++) {\n\t\t\t\tif (c > 0) {\n\t\t\t\t\ts += \", \";\n\t\t\t\t}\n\n\t\t\t\ts += `${this.serializer.stringify(this.getCell(r, c), this.handle)}`;\n\t\t\t}\n\t\t\ts += \"]\\n\";\n\t\t}\n\n\t\treturn `${s}\\n`;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): unknown {\n\t\tif (content.target === SnapshotPath.cols || content.target === SnapshotPath.rows) {\n\t\t\tconst op = content as IMergeTreeOp;\n\t\t\tconst currentVector = content.target === SnapshotPath.cols ? this.cols : this.rows;\n\t\t\tconst oppositeVector = content.target === SnapshotPath.cols ? this.rows : this.cols;\n\t\t\tconst metadata = currentVector.applyStashedOp(op);\n\t\t\tconst localSeq = currentVector.getCollabWindow().localSeq;\n\t\t\tconst oppositeWindow = oppositeVector.getCollabWindow();\n\n\t\t\tassert(\n\t\t\t\tlocalSeq > oppositeWindow.localSeq,\n\t\t\t\t0x2d9,\n\t\t\t\t/* \"The 'localSeq' of the vector applying stashed op must > the 'localSeq' of the other vector.\" */\n\t\t\t);\n\n\t\t\toppositeWindow.localSeq = localSeq;\n\n\t\t\treturn metadata;\n\t\t} else {\n\t\t\tassert(content.type === MatrixOp.set, 0x2da /* \"Unknown SharedMatrix 'op' type.\" */);\n\n\t\t\tconst setOp = content as ISetOp<T>;\n\t\t\tconst rowHandle = this.rows.getAllocatedHandle(setOp.row);\n\t\t\tconst colHandle = this.cols.getAllocatedHandle(setOp.col);\n\t\t\tconst rowsRefSeq = this.rows.getCollabWindow().currentSeq;\n\t\t\tconst colsRefSeq = this.cols.getCollabWindow().currentSeq;\n\t\t\tif (this.undo !== undefined) {\n\t\t\t\tlet oldValue = this.cells.getCell(rowHandle, colHandle);\n\t\t\t\tif (oldValue === null) {\n\t\t\t\t\toldValue = undefined;\n\t\t\t\t}\n\n\t\t\t\tthis.undo.cellSet(rowHandle, colHandle, oldValue);\n\t\t\t}\n\n\t\t\tthis.cells.setCell(rowHandle, colHandle, setOp.value);\n\t\t\tconst localSeq = this.nextLocalSeq();\n\t\t\tconst metadata: ISetOpMetadata = {\n\t\t\t\trowHandle,\n\t\t\t\tcolHandle,\n\t\t\t\tlocalSeq,\n\t\t\t\trowsRefSeq,\n\t\t\t\tcolsRefSeq,\n\t\t\t};\n\n\t\t\tthis.pending.setCell(rowHandle, colHandle, localSeq);\n\t\t\treturn metadata;\n\t\t}\n\t}\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "2.0.0-dev.5.3.2.178189";
8
+ export declare const pkgVersion = "2.0.0-dev.6.4.0.191457";
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 = "2.0.0-dev.5.3.2.178189";
11
+ exports.pkgVersion = "2.0.0-dev.6.4.0.191457";
12
12
  //# sourceMappingURL=packageVersion.js.map