@fluidframework/matrix 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258

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 (84) hide show
  1. package/CHANGELOG.md +63 -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 +1 -2
  16. package/dist/permutationvector.d.ts.map +1 -1
  17. package/dist/permutationvector.js +11 -8
  18. package/dist/permutationvector.js.map +1 -1
  19. package/dist/serialization.js +2 -2
  20. package/dist/serialization.js.map +1 -1
  21. package/dist/sparsearray2d.d.ts.map +1 -1
  22. package/dist/sparsearray2d.js +1 -0
  23. package/dist/sparsearray2d.js.map +1 -1
  24. package/dist/undoprovider.js +8 -9
  25. package/dist/undoprovider.js.map +1 -1
  26. package/lib/handlecache.js +1 -1
  27. package/lib/handlecache.js.map +1 -1
  28. package/lib/handletable.d.ts +8 -1
  29. package/lib/handletable.d.ts.map +1 -1
  30. package/lib/handletable.js +11 -3
  31. package/lib/handletable.js.map +1 -1
  32. package/lib/matrix.d.ts.map +1 -1
  33. package/lib/matrix.js +3 -4
  34. package/lib/matrix.js.map +1 -1
  35. package/lib/packageVersion.d.ts +1 -1
  36. package/lib/packageVersion.js +1 -1
  37. package/lib/packageVersion.js.map +1 -1
  38. package/lib/permutationvector.d.ts +1 -2
  39. package/lib/permutationvector.d.ts.map +1 -1
  40. package/lib/permutationvector.js +6 -3
  41. package/lib/permutationvector.js.map +1 -1
  42. package/lib/serialization.js +1 -1
  43. package/lib/serialization.js.map +1 -1
  44. package/lib/sparsearray2d.d.ts.map +1 -1
  45. package/lib/sparsearray2d.js +1 -0
  46. package/lib/sparsearray2d.js.map +1 -1
  47. package/lib/undoprovider.js +5 -6
  48. package/lib/undoprovider.js.map +1 -1
  49. package/package.json +29 -33
  50. package/src/handlecache.ts +1 -1
  51. package/src/handletable.ts +22 -2
  52. package/src/matrix.ts +2 -1
  53. package/src/packageVersion.ts +1 -1
  54. package/src/permutationvector.ts +4 -6
  55. package/src/serialization.ts +1 -1
  56. package/src/sparsearray2d.ts +1 -0
  57. package/src/undoprovider.ts +1 -1
  58. package/dist/bspSet.d.ts +0 -125
  59. package/dist/bspSet.d.ts.map +0 -1
  60. package/dist/bspSet.js +0 -425
  61. package/dist/bspSet.js.map +0 -1
  62. package/dist/productSet.d.ts +0 -61
  63. package/dist/productSet.d.ts.map +0 -1
  64. package/dist/productSet.js +0 -679
  65. package/dist/productSet.js.map +0 -1
  66. package/dist/split.d.ts +0 -41
  67. package/dist/split.d.ts.map +0 -1
  68. package/dist/split.js +0 -127
  69. package/dist/split.js.map +0 -1
  70. package/lib/bspSet.d.ts +0 -125
  71. package/lib/bspSet.d.ts.map +0 -1
  72. package/lib/bspSet.js +0 -402
  73. package/lib/bspSet.js.map +0 -1
  74. package/lib/productSet.d.ts +0 -61
  75. package/lib/productSet.d.ts.map +0 -1
  76. package/lib/productSet.js +0 -665
  77. package/lib/productSet.js.map +0 -1
  78. package/lib/split.d.ts +0 -41
  79. package/lib/split.d.ts.map +0 -1
  80. package/lib/split.js +0 -116
  81. package/lib/split.js.map +0 -1
  82. package/src/bspSet.ts +0 -722
  83. package/src/productSet.ts +0 -1038
  84. package/src/split.ts +0 -171
@@ -1 +1 @@
1
- {"version":3,"file":"sparsearray2d.js","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,8EAA8E;AAC9E,6EAA6E;AAC7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CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACxF,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACxC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACnF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\n\n// Build a lookup table that maps a uint8 to the corresponding uint16 where 0s\n// are interleaved between the original bits. (e.g., 1111... -> 01010101...).\n//\n// (Lookup table ~17% faster than inlining the bit-twiddling on Node v12 x64)\n// (Array<T> ~2% faster than typed array on Node v12 x64)\nconst x8ToInterlacedX16 = new Array(256).fill(0).map((value, i) => {\n\tlet j = i;\n\tj = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n\tj = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n\tj = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n\treturn j;\n});\n\n// Selects individual bytes from a given 32b integer. The left shift are used to\n// clear upper bits (faster than using masks on Node 10 x64).\nconst byte0 = (x32: number) => x32 >>> 24;\nconst byte1 = (x32: number) => (x32 << 8) >>> 24;\nconst byte2 = (x32: number) => (x32 << 16) >>> 24;\nconst byte3 = (x32: number) => (x32 << 24) >>> 24;\n\n// Given a uint16 returns the corresponding uint32 integer where 0s are\n// interleaved between the original bits. (e.g., 1111... -> 01010101...).\nconst interlaceBitsX16 = (x16: number) =>\n\t(x8ToInterlacedX16[byte2(x16)] << 16) | x8ToInterlacedX16[byte3(x16)];\n\nconst r0ToMorton16 = (row: number) => (interlaceBitsX16(row) << 1) >>> 0;\nconst c0ToMorton16 = (col: number) => interlaceBitsX16(col) >>> 0;\n\n// Given a 2D uint16 coordinate returns the corresponding unt32 Morton coded\n// coordinate. (See https://en.wikipedia.org/wiki/Z-order_curve)\nconst r0c0ToMorton2x16 = (row: number, col: number) =>\n\t(r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;\n\ntype RecurArrayHelper<T> = RecurArray<T> | T;\ntype RecurArray<T> = RecurArrayHelper<T>[];\n\n/** Undo JSON serialization's coercion of 'undefined' to null. */\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> =>\n\tarray.map((value) => {\n\t\treturn value === null ? undefined : Array.isArray(value) ? nullToUndefined(value) : value;\n\t});\n\ntype UA<T> = (T | undefined)[];\n\n/**\n * A sparse 4 billion x 4 billion array stored as 16x16 tiles.\n */\nexport class SparseArray2D<T>\n\timplements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined>\n{\n\tconstructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) {}\n\n\tpublic get rowCount() {\n\t\treturn 0xffffffff;\n\t}\n\tpublic get colCount() {\n\t\treturn 0xffffffff;\n\t}\n\n\tpublic getCell(row: number, col: number): T | undefined {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst level0 = this.root[keyHi];\n\t\tif (level0 !== undefined) {\n\t\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\t\t\tconst level1 = level0[byte0(keyLo)];\n\t\t\tif (level1 !== undefined) {\n\t\t\t\tconst level2 = level1[byte1(keyLo)];\n\t\t\t\tif (level2 !== undefined) {\n\t\t\t\t\tconst level3 = level2[byte2(keyLo)];\n\t\t\t\t\tif (level3 !== undefined) {\n\t\t\t\t\t\treturn level3[byte3(keyLo)];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn undefined as any;\n\t}\n\n\tpublic setCell(row: number, col: number, value: T | undefined) {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\n\t\tconst level0 = this.getLevel(this.root, keyHi);\n\t\tconst level1 = this.getLevel(level0, byte0(keyLo));\n\t\tconst level2 = this.getLevel(level1, byte1(keyLo));\n\t\tconst level3 = this.getLevel(level2, byte2(keyLo));\n\t\tlevel3[byte3(keyLo)] = value;\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n\t\tfor (let col = 0; col < 16; col++) {\n\t\t\t// Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n\t\t\tcallback((rowBits | c0ToMorton16(col)) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInCol(col: number, callback: (key: number) => void) {\n\t\tfor (let row = 0; row < 16; row++) {\n\t\t\t// Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n\t\t\tcallback((r0ToMorton16(row) | col) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given row in the 'currentLevel'.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInRow<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\trowBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInRow(rowBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given col in the 'currentLevel'.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInCol<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\tcolBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInCol(colBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Clears the all cells contained within the specified span of rows. */\n\tpublic clearRows(rowStart: number, rowCount: number) {\n\t\tconst rowEnd = rowStart + rowCount;\n\t\tfor (let row = rowStart; row < rowEnd; row++) {\n\t\t\tconst rowHi = r0ToMorton16(row >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let colHi = 0; colHi < 0x10000; colHi++) {\n\t\t\t\tconst keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst rowLo = r0ToMorton16(row);\n\t\t\t\t\tthis.forEachInRow(level0, byte0(rowLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInRow(level1, byte1(rowLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInRow(level2, byte2(rowLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInRow(byte3(rowLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Clears the all cells contained within the specifed span of cols. */\n\tpublic clearCols(colStart: number, colCount: number) {\n\t\tconst colEnd = colStart + colCount;\n\t\tfor (let col = colStart; col < colEnd; col++) {\n\t\t\tconst colHi = c0ToMorton16(col >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n\t\t\t\tconst keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst colLo = c0ToMorton16(col);\n\t\t\t\t\tthis.forEachInCol(level0, byte0(colLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInCol(level1, byte1(colLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInCol(level2, byte2(colLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInCol(byte3(colLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n\t\tconst level = parent[subKey];\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn level === undefined ? (parent[subKey] = new Array(256).fill(undefined)) : level;\n\t}\n\n\tpublic snapshot() {\n\t\treturn this.root;\n\t}\n\n\tpublic static load<T>(data: RecurArray<T>) {\n\t\treturn new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n\t}\n}\n"]}
1
+ {"version":3,"file":"sparsearray2d.js","sourceRoot":"","sources":["../src/sparsearray2d.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,yDAAy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AC,CAAC,KAAK,CAAC;IACxF,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAmB;QACxC,OAAO,IAAI,aAAa,CAAI,eAAe,CAAI,IAAI,CAA6B,CAAC,CAAC;IACnF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { IMatrixReader, IMatrixWriter } from \"@tiny-calc/nano\";\n\n// Build a lookup table that maps a uint8 to the corresponding uint16 where 0s\n// are interleaved between the original bits. (e.g., 1111... -> 01010101...).\n//\n// (Lookup table ~17% faster than inlining the bit-twiddling on Node v12 x64)\n// (Array<T> ~2% faster than typed array on Node v12 x64)\nconst x8ToInterlacedX16 = new Array(256).fill(0).map((value, i) => {\n\tlet j = i;\n\tj = (j | (j << 4)) & 0x0f0f; // .... 7654 .... 3210\n\tj = (j | (j << 2)) & 0x3333; // ..76 ..54 ..32 ..10\n\tj = (j | (j << 1)) & 0x5555; // .7.6 .5.4 .3.2 .1.0\n\treturn j;\n});\n\n// Selects individual bytes from a given 32b integer. The left shift are used to\n// clear upper bits (faster than using masks on Node 10 x64).\nconst byte0 = (x32: number) => x32 >>> 24;\nconst byte1 = (x32: number) => (x32 << 8) >>> 24;\nconst byte2 = (x32: number) => (x32 << 16) >>> 24;\nconst byte3 = (x32: number) => (x32 << 24) >>> 24;\n\n// Given a uint16 returns the corresponding uint32 integer where 0s are\n// interleaved between the original bits. (e.g., 1111... -> 01010101...).\nconst interlaceBitsX16 = (x16: number) =>\n\t(x8ToInterlacedX16[byte2(x16)] << 16) | x8ToInterlacedX16[byte3(x16)];\n\nconst r0ToMorton16 = (row: number) => (interlaceBitsX16(row) << 1) >>> 0;\nconst c0ToMorton16 = (col: number) => interlaceBitsX16(col) >>> 0;\n\n// Given a 2D uint16 coordinate returns the corresponding unt32 Morton coded\n// coordinate. (See https://en.wikipedia.org/wiki/Z-order_curve)\nconst r0c0ToMorton2x16 = (row: number, col: number) =>\n\t(r0ToMorton16(row) | c0ToMorton16(col)) >>> 0;\n\ntype RecurArrayHelper<T> = RecurArray<T> | T;\ntype RecurArray<T> = RecurArrayHelper<T>[];\n\n/** Undo JSON serialization's coercion of 'undefined' to null. */\n// eslint-disable-next-line @rushstack/no-new-null -- Private use of 'null' to preserve 'undefined'\nconst nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> =>\n\tarray.map((value) => {\n\t\treturn value === null ? undefined : Array.isArray(value) ? nullToUndefined(value) : value;\n\t});\n\ntype UA<T> = (T | undefined)[];\n\n/**\n * A sparse 4 billion x 4 billion array stored as 16x16 tiles.\n */\nexport class SparseArray2D<T>\n\timplements IMatrixReader<T | undefined>, IMatrixWriter<T | undefined>\n{\n\tconstructor(private readonly root: UA<UA<UA<UA<UA<T>>>>> = [undefined]) {}\n\n\tpublic get rowCount() {\n\t\treturn 0xffffffff;\n\t}\n\tpublic get colCount() {\n\t\treturn 0xffffffff;\n\t}\n\n\tpublic getCell(row: number, col: number): T | undefined {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst level0 = this.root[keyHi];\n\t\tif (level0 !== undefined) {\n\t\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\t\t\tconst level1 = level0[byte0(keyLo)];\n\t\t\tif (level1 !== undefined) {\n\t\t\t\tconst level2 = level1[byte1(keyLo)];\n\t\t\t\tif (level2 !== undefined) {\n\t\t\t\t\tconst level3 = level2[byte2(keyLo)];\n\t\t\t\t\tif (level3 !== undefined) {\n\t\t\t\t\t\treturn level3[byte3(keyLo)];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic get matrixProducer() {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn undefined as any;\n\t}\n\n\tpublic setCell(row: number, col: number, value: T | undefined) {\n\t\tconst keyHi = r0c0ToMorton2x16(row >>> 16, col >>> 16);\n\t\tconst keyLo = r0c0ToMorton2x16(row, col);\n\n\t\tconst level0 = this.getLevel(this.root, keyHi);\n\t\tconst level1 = this.getLevel(level0, byte0(keyLo));\n\t\tconst level2 = this.getLevel(level1, byte1(keyLo));\n\t\tconst level3 = this.getLevel(level2, byte2(keyLo));\n\t\tlevel3[byte3(keyLo)] = value;\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated row.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInRow(rowBits: number, callback: (key: number) => void) {\n\t\tfor (let col = 0; col < 16; col++) {\n\t\t\t// Perf: Potentially faster to replace 'c0ToMorton16()' with a short look up table?\n\t\t\tcallback((rowBits | c0ToMorton16(col)) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the given 'callback' for each key in a 16 x 16 tile at the indicated col.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachKeyInCol(col: number, callback: (key: number) => void) {\n\t\tfor (let row = 0; row < 16; row++) {\n\t\t\t// Perf: Potentially faster to replace 'r0ToMorton16()' with a short look up table?\n\t\t\tcallback((r0ToMorton16(row) | col) >>> 0);\n\t\t}\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given row in the 'currentLevel'.\n\t *\n\t * (Note that 'rowBits' is the appropriate byte from 'r0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInRow<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\trowBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInRow(rowBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Invokes the give 'callback' with the next 'level' array for each populated region\n\t * of the given col in the 'currentLevel'.\n\t *\n\t * (Note that 'colBits' is the appropriate byte from 'c0ToMorton16' for the current\n\t * level being traversed.)\n\t */\n\tprivate forEachInCol<V extends UA<any>, U extends UA<V>>(\n\t\tcurrentLevel: U,\n\t\tcolBits: number,\n\t\tcallback: (level: V) => void,\n\t) {\n\t\tthis.forEachKeyInCol(colBits, (key) => {\n\t\t\tconst nextLevel = currentLevel[key];\n\t\t\tif (nextLevel !== undefined) {\n\t\t\t\tcallback(nextLevel);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Clears the all cells contained within the specified span of rows. */\n\tpublic clearRows(rowStart: number, rowCount: number) {\n\t\tconst rowEnd = rowStart + rowCount;\n\t\tfor (let row = rowStart; row < rowEnd; row++) {\n\t\t\tconst rowHi = r0ToMorton16(row >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let colHi = 0; colHi < 0x10000; colHi++) {\n\t\t\t\tconst keyHi = (rowHi | c0ToMorton16(colHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst rowLo = r0ToMorton16(row);\n\t\t\t\t\tthis.forEachInRow(level0, byte0(rowLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInRow(level1, byte1(rowLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInRow(level2, byte2(rowLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInRow(byte3(rowLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Clears the all cells contained within the specifed span of cols. */\n\tpublic clearCols(colStart: number, colCount: number) {\n\t\tconst colEnd = colStart + colCount;\n\t\tfor (let col = colStart; col < colEnd; col++) {\n\t\t\tconst colHi = c0ToMorton16(col >>> 16);\n\n\t\t\t// The top level of tree is a 64k x 64k tile. We need to scan all 64k entries.\n\t\t\tfor (let rowHi = 0; rowHi < 0x10000; rowHi++) {\n\t\t\t\tconst keyHi = (colHi | r0ToMorton16(rowHi)) >>> 0;\n\t\t\t\tconst level0 = this.root[keyHi];\n\t\t\t\tif (level0 !== undefined) {\n\t\t\t\t\t// The remainder of the tree is divided in 16 x 16 tiles.\n\t\t\t\t\tconst colLo = c0ToMorton16(col);\n\t\t\t\t\tthis.forEachInCol(level0, byte0(colLo), (level1) => {\n\t\t\t\t\t\tthis.forEachInCol(level1, byte1(colLo), (level2) => {\n\t\t\t\t\t\t\tthis.forEachInCol(level2, byte2(colLo), (level3) => {\n\t\t\t\t\t\t\t\tthis.forEachKeyInCol(byte3(colLo), (key) => {\n\t\t\t\t\t\t\t\t\tlevel3[key] = undefined;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getLevel<T>(parent: UA<UA<T>>, subKey: number) {\n\t\tconst level = parent[subKey];\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn level === undefined ? (parent[subKey] = new Array(256).fill(undefined)) : level;\n\t}\n\n\tpublic snapshot() {\n\t\treturn this.root;\n\t}\n\n\tpublic static load<T>(data: RecurArray<T>) {\n\t\treturn new SparseArray2D<T>(nullToUndefined<T>(data) as SparseArray2D<T>[\"root\"]);\n\t}\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert } from "@fluidframework/common-utils";
5
+ import { assert } from "@fluidframework/core-utils";
6
6
  import { MergeTreeDeltaType, appendToMergeTreeDeltaRevertibles, revertMergeTreeDeltaRevertibles, discardMergeTreeDeltaRevertible, TrackingGroup, } from "@fluidframework/merge-tree";
7
7
  import { isHandleValid } from "./handletable";
8
8
  export class VectorUndoProvider {
@@ -11,12 +11,11 @@ export class VectorUndoProvider {
11
11
  this.driver = driver;
12
12
  }
13
13
  record(deltaArgs) {
14
- var _a, _b, _c, _d;
15
14
  if (deltaArgs.deltaSegments.length > 0) {
16
15
  // If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking
17
16
  // group so that we can preserve the original segment ranges as a single op/group as we move
18
17
  // ops between the undo <-> redo stacks.
19
- const revertibles = (_a = this.currentGroup) !== null && _a !== void 0 ? _a : [];
18
+ const revertibles = this.currentGroup ?? [];
20
19
  appendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);
21
20
  // For SharedMatrix, each IRevertibles always holds a single row/col operation.
22
21
  // Therefore, 'currentOp' must either be undefined or equal to the current op.
@@ -34,7 +33,7 @@ export class VectorUndoProvider {
34
33
  // so the new segment takes them over. there is no efficient look-up for this.
35
34
  // the tracking group provides one.
36
35
  const trackingGroup = (removeTrackingGroup =
37
- (_b = this.currentRemoveTrackingGroup) !== null && _b !== void 0 ? _b : new TrackingGroup());
36
+ this.currentRemoveTrackingGroup ?? new TrackingGroup());
38
37
  deltaArgs.deltaSegments.forEach((d) => d.segment.trackingCollection.link(trackingGroup));
39
38
  }
40
39
  switch (deltaArgs.operation) {
@@ -51,8 +50,8 @@ export class VectorUndoProvider {
51
50
  // another revertible until `IRevertable.revert()` finishes the current op and clears this
52
51
  // field.
53
52
  if (this.currentGroup !== undefined) {
54
- (_c = this.currentOp) !== null && _c !== void 0 ? _c : (this.currentOp = deltaArgs.operation);
55
- (_d = this.currentRemoveTrackingGroup) !== null && _d !== void 0 ? _d : (this.currentRemoveTrackingGroup = removeTrackingGroup);
53
+ this.currentOp ?? (this.currentOp = deltaArgs.operation);
54
+ this.currentRemoveTrackingGroup ?? (this.currentRemoveTrackingGroup = removeTrackingGroup);
56
55
  }
57
56
  }
58
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EACN,kBAAkB,EAGlB,iCAAiC,EACjC,+BAA+B,EAE/B,+BAA+B,EAC/B,aAAa,GAEb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AAItD,MAAM,OAAO,kBAAkB;IAQ9B,YACkB,OAAsB,EACtB,MAAiC;QADjC,YAAO,GAAP,OAAO,CAAe;QACtB,WAAM,GAAN,MAAM,CAA2B;IAChD,CAAC;IAEG,MAAM,CAAC,SAAsC;;QACnD,IAAI,SAAS,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,8FAA8F;YAC9F,4FAA4F;YAC5F,wCAAwC;YACxC,MAAM,WAAW,GAA+B,MAAA,IAAI,CAAC,YAAY,mCAAI,EAAE,CAAC;YACxE,iCAAiC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAE1D,+EAA+E;YAC/E,8EAA8E;YAC9E,MAAM,CACL,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EACtE,KAAK,CAAC,0DAA0D,CAChE,CAAC;YACF,IAAI,mBAA8C,CAAC;YACnD,IAAI,SAAS,CAAC,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;gBACtD,gDAAgD;gBAChD,4BAA4B;gBAC5B,8EAA8E;gBAC9E,2EAA2E;gBAC3E,qFAAqF;gBACrF,6FAA6F;gBAC7F,uCAAuC;gBACvC,+EAA+E;gBAC/E,+EAA+E;gBAC/E,oCAAoC;gBACpC,MAAM,aAAa,GAAG,CAAC,mBA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OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tMergeTreeDeltaType,\n\tMergeTreeDeltaRevertible,\n\tIMergeTreeDeltaCallbackArgs,\n\tappendToMergeTreeDeltaRevertibles,\n\trevertMergeTreeDeltaRevertibles,\n\tMergeTreeRevertibleDriver,\n\tdiscardMergeTreeDeltaRevertible,\n\tTrackingGroup,\n\tITrackingGroup,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: MergeTreeDeltaRevertible[];\n\tprivate currentOp?: MergeTreeDeltaType;\n\tprivate currentRemoveTrackingGroup?: TrackingGroup;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly driver: MergeTreeRevertibleDriver,\n\t) {}\n\n\tpublic record(deltaArgs: IMergeTreeDeltaCallbackArgs) {\n\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst revertibles: MergeTreeDeltaRevertible[] = this.currentGroup ?? [];\n\t\t\tappendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === deltaArgs.operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\t\t\tlet removeTrackingGroup: TrackingGroup | undefined;\n\t\t\tif (deltaArgs.operation === MergeTreeDeltaType.REMOVE) {\n\t\t\t\t// for removed segment we need a tracking group.\n\t\t\t\t// this is for a few reason:\n\t\t\t\t// 1. the handle for the row/column on the removed segment is still allocated,\n\t\t\t\t//\t\tand needs to be in order to process unacked ops sent before the remove.\n\t\t\t\t// 2. handles are freed on unlink(zamboni), but that also clears the row/column data.\n\t\t\t\t//\t\twhich we don't want to happen, so we can re-insert the cells when the row/col comes back.\n\t\t\t\t//\t\tthe tracking group prevents unlink.\n\t\t\t\t// 3. when we re-insert we need to find the old segment and clear their handles\n\t\t\t\t//\t\tso the new segment takes them over. there is no efficient look-up for this.\n\t\t\t\t//\t\tthe tracking group provides one.\n\t\t\t\tconst trackingGroup = (removeTrackingGroup =\n\t\t\t\t\tthis.currentRemoveTrackingGroup ?? new TrackingGroup());\n\t\t\t\tdeltaArgs.deltaSegments.forEach((d) =>\n\t\t\t\t\td.segment.trackingCollection.link(trackingGroup),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tswitch (deltaArgs.operation) {\n\t\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== deltaArgs.operation) {\n\t\t\t\t\t\tthis.pushRevertible(revertibles, removeTrackingGroup);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp ??= deltaArgs.operation;\n\t\t\t\tthis.currentRemoveTrackingGroup ??= removeTrackingGroup;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\trevertibles: MergeTreeDeltaRevertible[],\n\t\tremovedTrackingGroup: ITrackingGroup | undefined,\n\t) {\n\t\tconst reverter = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = [];\n\n\t\t\t\ttry {\n\t\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\t\tconst tracked = removedTrackingGroup.tracked[0];\n\t\t\t\t\t\t\tremovedTrackingGroup.unlink(tracked);\n\t\t\t\t\t\t\t// if there are groups tracked, this in a revert of a remove.\n\t\t\t\t\t\t\t// this means we are about to re-insert the row/column\n\t\t\t\t\t\t\t// with the same handle. We reuse the handle so the row/columns cells\n\t\t\t\t\t\t\t// get re-inserted too.\n\t\t\t\t\t\t\t// since a new segment will have the handle, we need to\n\t\t\t\t\t\t\t// remove it from the removed segment which was tracked\n\t\t\t\t\t\t\t(tracked as PermutationSegment).reset();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trevertMergeTreeDeltaRevertibles(this.driver, revertibles);\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t\tthis.currentRemoveTrackingGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\tremovedTrackingGroup.unlink(removedTrackingGroup.tracked[0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdiscardMergeTreeDeltaRevertible(revertibles);\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(reverter);\n\n\t\treturn reverter;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveRows(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeRows(start, end - start);\n\t\t\t},\n\t\t});\n\t\tcols.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveCols(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeCols(start, end - start);\n\t\t\t},\n\t\t});\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACN,kBAAkB,EAGlB,iCAAiC,EACjC,+BAA+B,EAE/B,+BAA+B,EAC/B,aAAa,GAEb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AAItD,MAAM,OAAO,kBAAkB;IAQ9B,YACkB,OAAsB,EACtB,MAAiC;QADjC,YAAO,GAAP,OAAO,CAAe;QACtB,WAAM,GAAN,MAAM,CAA2B;IAChD,CAAC;IAEG,MAAM,CAAC,SAAsC;QACnD,IAAI,SAAS,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,8FAA8F;YAC9F,4FAA4F;YAC5F,wCAAwC;YACxC,MAAM,WAAW,GAA+B,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;YACxE,iCAAiC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAE1D,+EAA+E;YAC/E,8EAA8E;YAC9E,MAAM,CACL,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EACtE,KAAK,CAAC,0DAA0D,CAChE,CAAC;YACF,IAAI,mBAA8C,CAAC;YACnD,IAAI,SAAS,CAAC,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;gBACtD,gDAAgD;gBAChD,4BAA4B;gBAC5B,8EAA8E;gBAC9E,2EAA2E;gBAC3E,qFAAqF;gBACrF,6FAA6F;gBAC7F,uCAAuC;gBACvC,+EAA+E;gBAC/E,+EAA+E;gBAC/E,oCAAoC;gBACpC,MAAM,aAAa,GA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AC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tMergeTreeDeltaType,\n\tMergeTreeDeltaRevertible,\n\tIMergeTreeDeltaCallbackArgs,\n\tappendToMergeTreeDeltaRevertibles,\n\trevertMergeTreeDeltaRevertibles,\n\tMergeTreeRevertibleDriver,\n\tdiscardMergeTreeDeltaRevertible,\n\tTrackingGroup,\n\tITrackingGroup,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: MergeTreeDeltaRevertible[];\n\tprivate currentOp?: MergeTreeDeltaType;\n\tprivate currentRemoveTrackingGroup?: TrackingGroup;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly driver: MergeTreeRevertibleDriver,\n\t) {}\n\n\tpublic record(deltaArgs: IMergeTreeDeltaCallbackArgs) {\n\t\tif (deltaArgs.deltaSegments.length > 0) {\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst revertibles: MergeTreeDeltaRevertible[] = this.currentGroup ?? [];\n\t\t\tappendToMergeTreeDeltaRevertibles(deltaArgs, revertibles);\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === deltaArgs.operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\t\t\tlet removeTrackingGroup: TrackingGroup | undefined;\n\t\t\tif (deltaArgs.operation === MergeTreeDeltaType.REMOVE) {\n\t\t\t\t// for removed segment we need a tracking group.\n\t\t\t\t// this is for a few reason:\n\t\t\t\t// 1. the handle for the row/column on the removed segment is still allocated,\n\t\t\t\t//\t\tand needs to be in order to process unacked ops sent before the remove.\n\t\t\t\t// 2. handles are freed on unlink(zamboni), but that also clears the row/column data.\n\t\t\t\t//\t\twhich we don't want to happen, so we can re-insert the cells when the row/col comes back.\n\t\t\t\t//\t\tthe tracking group prevents unlink.\n\t\t\t\t// 3. when we re-insert we need to find the old segment and clear their handles\n\t\t\t\t//\t\tso the new segment takes them over. there is no efficient look-up for this.\n\t\t\t\t//\t\tthe tracking group provides one.\n\t\t\t\tconst trackingGroup = (removeTrackingGroup =\n\t\t\t\t\tthis.currentRemoveTrackingGroup ?? new TrackingGroup());\n\t\t\t\tdeltaArgs.deltaSegments.forEach((d) =>\n\t\t\t\t\td.segment.trackingCollection.link(trackingGroup),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tswitch (deltaArgs.operation) {\n\t\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== deltaArgs.operation) {\n\t\t\t\t\t\tthis.pushRevertible(revertibles, removeTrackingGroup);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp ??= deltaArgs.operation;\n\t\t\t\tthis.currentRemoveTrackingGroup ??= removeTrackingGroup;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\trevertibles: MergeTreeDeltaRevertible[],\n\t\tremovedTrackingGroup: ITrackingGroup | undefined,\n\t) {\n\t\tconst reverter = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = [];\n\n\t\t\t\ttry {\n\t\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\t\tconst tracked = removedTrackingGroup.tracked[0];\n\t\t\t\t\t\t\tremovedTrackingGroup.unlink(tracked);\n\t\t\t\t\t\t\t// if there are groups tracked, this in a revert of a remove.\n\t\t\t\t\t\t\t// this means we are about to re-insert the row/column\n\t\t\t\t\t\t\t// with the same handle. We reuse the handle so the row/columns cells\n\t\t\t\t\t\t\t// get re-inserted too.\n\t\t\t\t\t\t\t// since a new segment will have the handle, we need to\n\t\t\t\t\t\t\t// remove it from the removed segment which was tracked\n\t\t\t\t\t\t\t(tracked as PermutationSegment).reset();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trevertMergeTreeDeltaRevertibles(this.driver, revertibles);\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t\tthis.currentRemoveTrackingGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\tif (removedTrackingGroup !== undefined) {\n\t\t\t\t\twhile (removedTrackingGroup.size > 0) {\n\t\t\t\t\t\tremovedTrackingGroup.unlink(removedTrackingGroup.tracked[0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdiscardMergeTreeDeltaRevertible(revertibles);\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(reverter);\n\n\t\treturn reverter;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveRows(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeRows(start, end - start);\n\t\t\t},\n\t\t});\n\t\tcols.undo = new VectorUndoProvider(consumer, {\n\t\t\tannotateRange() {\n\t\t\t\tthrow new Error(\"not implemented\");\n\t\t\t},\n\t\t\tinsertFromSpec(pos, spec) {\n\t\t\t\tmatrix._undoRemoveCols(pos, spec);\n\t\t\t},\n\t\t\tremoveRange(start, end) {\n\t\t\t\tmatrix.removeCols(start, end - start);\n\t\t\t},\n\t\t});\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "2.0.0-dev.5.2.0.169897",
3
+ "version": "2.0.0-dev.6.4.0.191258",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -14,7 +14,7 @@
14
14
  "main": "dist/index.js",
15
15
  "module": "lib/index.js",
16
16
  "types": "dist/index.d.ts",
17
- "nyc": {
17
+ "c8": {
18
18
  "all": true,
19
19
  "cache-dir": "nyc/.cache",
20
20
  "exclude-after-remap": false,
@@ -31,37 +31,37 @@
31
31
  "temp-directory": "nyc/.nyc_output"
32
32
  },
33
33
  "dependencies": {
34
- "@fluidframework/common-definitions": "^0.20.1",
35
- "@fluidframework/common-utils": "^1.1.1",
36
- "@fluidframework/core-interfaces": "2.0.0-dev.5.2.0.169897",
37
- "@fluidframework/datastore-definitions": "2.0.0-dev.5.2.0.169897",
38
- "@fluidframework/driver-utils": "2.0.0-dev.5.2.0.169897",
39
- "@fluidframework/merge-tree": "2.0.0-dev.5.2.0.169897",
34
+ "@fluid-internal/client-utils": "2.0.0-dev.6.4.0.191258",
35
+ "@fluidframework/core-interfaces": "2.0.0-dev.6.4.0.191258",
36
+ "@fluidframework/core-utils": "2.0.0-dev.6.4.0.191258",
37
+ "@fluidframework/datastore-definitions": "2.0.0-dev.6.4.0.191258",
38
+ "@fluidframework/driver-utils": "2.0.0-dev.6.4.0.191258",
39
+ "@fluidframework/merge-tree": "2.0.0-dev.6.4.0.191258",
40
40
  "@fluidframework/protocol-definitions": "^1.1.0",
41
- "@fluidframework/runtime-definitions": "2.0.0-dev.5.2.0.169897",
42
- "@fluidframework/runtime-utils": "2.0.0-dev.5.2.0.169897",
43
- "@fluidframework/shared-object-base": "2.0.0-dev.5.2.0.169897",
44
- "@fluidframework/telemetry-utils": "2.0.0-dev.5.2.0.169897",
41
+ "@fluidframework/runtime-definitions": "2.0.0-dev.6.4.0.191258",
42
+ "@fluidframework/runtime-utils": "2.0.0-dev.6.4.0.191258",
43
+ "@fluidframework/shared-object-base": "2.0.0-dev.6.4.0.191258",
44
+ "@fluidframework/telemetry-utils": "2.0.0-dev.6.4.0.191258",
45
45
  "@tiny-calc/nano": "0.0.0-alpha.5",
46
46
  "events": "^3.1.0",
47
47
  "tslib": "^1.10.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@fluid-internal/test-dds-utils": "2.0.0-dev.5.2.0.169897",
51
- "@fluid-tools/benchmark": "^0.47.0",
52
- "@fluid-tools/build-cli": "^0.20.0-169245",
53
- "@fluidframework/build-common": "^1.2.0",
54
- "@fluidframework/build-tools": "^0.20.0-169245",
55
- "@fluidframework/eslint-config-fluid": "^2.0.0",
56
- "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0-internal.5.0.0",
57
- "@fluidframework/mocha-test-setup": "2.0.0-dev.5.2.0.169897",
58
- "@fluidframework/test-runtime-utils": "2.0.0-dev.5.2.0.169897",
50
+ "@fluid-internal/test-dds-utils": "2.0.0-dev.6.4.0.191258",
51
+ "@fluid-tools/benchmark": "^0.48.0",
52
+ "@fluid-tools/build-cli": "^0.22.0",
53
+ "@fluidframework/build-common": "^2.0.0",
54
+ "@fluidframework/build-tools": "^0.22.0",
55
+ "@fluidframework/eslint-config-fluid": "^2.1.0",
56
+ "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0-internal.6.3.0",
57
+ "@fluidframework/mocha-test-setup": "2.0.0-dev.6.4.0.191258",
58
+ "@fluidframework/test-runtime-utils": "2.0.0-dev.6.4.0.191258",
59
59
  "@microsoft/api-extractor": "^7.34.4",
60
60
  "@tiny-calc/micro": "0.0.0-alpha.5",
61
61
  "@types/mocha": "^9.1.1",
62
- "@types/node": "^14.18.38",
62
+ "@types/node": "^16.18.38",
63
63
  "best-random": "^1.0.0",
64
- "concurrently": "^7.6.0",
64
+ "c8": "^7.7.1",
65
65
  "copyfiles": "^2.4.1",
66
66
  "cross-env": "^7.0.3",
67
67
  "eslint": "~8.6.0",
@@ -70,13 +70,11 @@
70
70
  "mocha-json-output-reporter": "^2.0.1",
71
71
  "mocha-multi-reporters": "^1.5.1",
72
72
  "moment": "^2.21.0",
73
- "nyc": "^15.1.0",
74
73
  "prettier": "~2.6.2",
75
74
  "rimraf": "^4.4.0",
76
- "source-map-support": "^0.5.16",
77
- "ts-node": "^8.6.2",
75
+ "ts-node": "^10.9.1",
78
76
  "typescript": "~4.5.5",
79
- "uuid": "^8.3.1"
77
+ "uuid": "^9.0.0"
80
78
  },
81
79
  "typeValidation": {
82
80
  "broken": {}
@@ -92,7 +90,7 @@
92
90
  "build:genver": "gen-version",
93
91
  "build:test": "tsc --project ./src/test/tsconfig.json",
94
92
  "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
95
- "clean": "rimraf dist lib bench/dist *.tsbuildinfo *.build.log",
93
+ "clean": "rimraf --glob 'dist' 'lib' 'bench/dist' '*.tsbuildinfo' '*.build.log' '_api-extractor-temp' 'nyc'",
96
94
  "eslint": "eslint --format stylish src",
97
95
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
98
96
  "format": "npm run prettier:fix",
@@ -100,16 +98,14 @@
100
98
  "lint:fix": "npm run prettier:fix && npm run eslint:fix",
101
99
  "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
102
100
  "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
103
- "stress": "mocha --recursive dist/test/**/*.spec.js --exit -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict --fgrep stress-loop",
104
101
  "test": "npm run test:mocha",
105
- "test:coverage": "nyc npm test -- --reporter xunit --reporter-option output=nyc/junit-report.xml --exit",
102
+ "test:coverage": "c8 npm test",
106
103
  "test:memory": "mocha --config src/test/memory/.mocharc.js",
107
104
  "test:memory-profiling:report": "mocha --config src/test/memory/.mocharc.js",
108
- "test:mocha": "npm run stress -- --invert",
109
- "test:mocha:multireport": "cross-env FLUID_TEST_MULTIREPORT=1 npm run test:mocha",
105
+ "test:mocha": "mocha --recursive 'dist/test/**/*.spec.js' --exit -r node_modules/@fluidframework/mocha-test-setup",
110
106
  "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
111
107
  "tsc": "tsc",
112
108
  "typetests:gen": "fluid-type-test-generator",
113
- "typetests:prepare": "flub generate typetests --prepare --dir . --pin"
109
+ "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
114
110
  }
115
111
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  /* eslint-disable no-bitwise */
7
7
 
8
- import { assert } from "@fluidframework/common-utils";
8
+ import { assert } from "@fluidframework/core-utils";
9
9
  import { IVectorConsumer } from "@tiny-calc/nano";
10
10
  import { Handle, isHandleValid } from "./handletable";
11
11
  import { PermutationVector, PermutationSegment } from "./permutationvector";
@@ -4,10 +4,18 @@
4
4
  */
5
5
 
6
6
  export const enum Handle {
7
+ /**
8
+ * Sentinel representing the absence of a valid handle.
9
+ */
10
+ none = 0,
11
+
7
12
  /** Minimum valid handle. */
8
13
  valid = 1,
9
14
 
10
- /** Sentinel representing an unallocated Handle. */
15
+ /**
16
+ * Sentinel representing an unallocated Handle. Used by PermutationVector
17
+ * to delay allocate handles when previously empty row/cols become populated.
18
+ */
11
19
  unallocated = -0x80000000,
12
20
  }
13
21
 
@@ -33,9 +41,21 @@ export class HandleTable<T> {
33
41
  * Allocates and returns the next available handle. Note that freed handles are recycled.
34
42
  */
35
43
  public allocate(): Handle {
44
+ // Get the handle to the next free slot.
36
45
  const free = this.next;
46
+
47
+ // Update 'next' to point to the new head of the free list. We use the contents of
48
+ // recycled slots to store the free list. The contents of the handles[free] will point
49
+ // to the next available slot. If there are no free slots (i.e., 'handles' is full),
50
+ // the slot will point to 'handles.length'. In this case, the handles array will grow
51
+ // and we update 'next' to point to the new end of the array.
37
52
  this.next = (this.handles[free] as Handle) ?? free + 1;
38
- this.handles[free] = 0;
53
+
54
+ // Out of paranoia, overwrite the contents of the newly allocated free slot with an
55
+ // invalid handle value. This may help catch/diagnose bugs in the event the free list
56
+ // becomes corrupted.
57
+ this.handles[free] = Handle.none;
58
+
39
59
  return free;
40
60
  }
41
61
 
package/src/matrix.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/common-utils";
6
+ import { assert } from "@fluidframework/core-utils";
7
7
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
8
8
  import {
9
9
  IFluidDataStoreRuntime,
@@ -63,6 +63,7 @@ interface ISetOpMetadata {
63
63
  * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,
64
64
  * excluding null. (However, nulls may be embedded inside objects and arrays.)
65
65
  */
66
+ // eslint-disable-next-line @rushstack/no-new-null -- Using 'null' to disallow 'null'.
66
67
  export type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;
67
68
 
68
69
  /**
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/matrix";
9
- export const pkgVersion = "2.0.0-dev.5.2.0.169897";
9
+ export const pkgVersion = "2.0.0-dev.6.4.0.191258";
@@ -3,13 +3,12 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/common-utils";
7
- import { ChildLogger } from "@fluidframework/telemetry-utils";
6
+ import { assert } from "@fluidframework/core-utils";
7
+ import { createChildLogger } from "@fluidframework/telemetry-utils";
8
8
  import {
9
9
  IFluidDataStoreRuntime,
10
10
  IChannelStorageService,
11
11
  } from "@fluidframework/datastore-definitions";
12
- import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
13
12
  import {
14
13
  BaseSegment,
15
14
  ISegment,
@@ -21,7 +20,7 @@ import {
21
20
  MergeTreeMaintenanceType,
22
21
  IJSONSegment,
23
22
  } from "@fluidframework/merge-tree";
24
- import { IFluidHandle } from "@fluidframework/core-interfaces";
23
+ import { ITelemetryBaseLogger, IFluidHandle } from "@fluidframework/core-interfaces";
25
24
  import { IFluidSerializer } from "@fluidframework/shared-object-base";
26
25
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
27
26
  import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
@@ -137,11 +136,10 @@ export class PermutationVector extends Client {
137
136
  ) {
138
137
  super(
139
138
  PermutationSegment.fromJSONObject,
140
- ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`),
139
+ createChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),
141
140
  {
142
141
  ...runtime.options,
143
142
  newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.
144
- mergeTreeUseNewLengthCalculations: true,
145
143
  },
146
144
  ); // (See https://github.com/microsoft/FluidFramework/issues/84)
147
145
 
@@ -7,7 +7,7 @@ import { Serializable, IChannelStorageService } from "@fluidframework/datastore-
7
7
  import { IFluidHandle } from "@fluidframework/core-interfaces";
8
8
  import { BlobTreeEntry } from "@fluidframework/driver-utils";
9
9
  import { IFluidSerializer } from "@fluidframework/shared-object-base";
10
- import { bufferToString } from "@fluidframework/common-utils";
10
+ import { bufferToString } from "@fluid-internal/client-utils";
11
11
 
12
12
  export const serializeBlob = (
13
13
  handle: IFluidHandle,
@@ -44,6 +44,7 @@ type RecurArrayHelper<T> = RecurArray<T> | T;
44
44
  type RecurArray<T> = RecurArrayHelper<T>[];
45
45
 
46
46
  /** Undo JSON serialization's coercion of 'undefined' to null. */
47
+ // eslint-disable-next-line @rushstack/no-new-null -- Private use of 'null' to preserve 'undefined'
47
48
  const nullToUndefined = <T>(array: RecurArray<T | null>): RecurArray<T | undefined> =>
48
49
  array.map((value) => {
49
50
  return value === null ? undefined : Array.isArray(value) ? nullToUndefined(value) : value;
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/common-utils";
6
+ import { assert } from "@fluidframework/core-utils";
7
7
  import {
8
8
  MergeTreeDeltaType,
9
9
  MergeTreeDeltaRevertible,
package/dist/bspSet.d.ts DELETED
@@ -1,125 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- /** An interface for representing a readonly pair */
6
- export declare type Pair<S, T = S> = readonly [S, T];
7
- export declare const pair: <S, T = S>(left: S, right: T) => Pair<S, T>;
8
- export declare enum SetKind {
9
- Dense = 0,
10
- Empty = 1
11
- }
12
- interface TreeNode<Left, Right> {
13
- readonly left: Left;
14
- readonly right: Right;
15
- }
16
- interface KeyNode<Key, Exact> {
17
- readonly key: Key;
18
- readonly pathKey: Key;
19
- readonly isExact: Exact;
20
- }
21
- export declare type Empty = SetKind.Empty;
22
- /** The term *Dense* means that a given subset contains all the elements of its particular
23
- * bounds. E.g. the whole set would be dense w.r.t. the bounds of the whole space. Or
24
- * if a set represents an interval [a, b), then it would be dense, if there are no holes in it,
25
- * i.e. the set is represented exactly using the current bounds.
26
- */
27
- export declare type Dense = SetKind.Dense;
28
- export declare const dense = SetKind.Dense;
29
- export declare const empty = SetKind.Empty;
30
- declare type KeyUnexact<Key> = KeyNode<Key, false>;
31
- /** In the BSP-set, each node carries with it implicit bounds just by the position in the tree.
32
- * Furthermore, it can carry around a key. The key can either be an approximation, i.e. an upper bound
33
- * or it can be *exact*. Exact means, that the whole set can be exactly represented in terms of just the key.
34
- *
35
- * One might wonder, why we don't prune the tree at this point. This has to do with the fact that we are
36
- * representing arbitrary sets and so even though one of two sets could be represented exactly the other
37
- * might not be able to yet. In this case we need to unfold the key by splitting further. In order to avoid
38
- * excessive splitting and pruning, we just carry around the key but allow the tree to also be materialized, on-demand.
39
- */
40
- declare type KeyExact<Key> = KeyNode<Key, true>;
41
- declare type KeyUndefined = KeyNode<undefined, false>;
42
- declare type KeyDefined<Key> = KeyUnexact<Key> | KeyExact<Key>;
43
- declare type BalancePropertyHelper<Key, Left, Right> = TreeNode<UntypedSparse<Key> | Left, UntypedSparse<Key> | Right>;
44
- declare type TreeDefined<Key> = BalancePropertyHelper<Key, Empty, Dense> | BalancePropertyHelper<Key, Dense, Empty>;
45
- declare type TreeUndefined = TreeNode<undefined, undefined>;
46
- declare type KeyDefinednessProperty<Key> = KeyDefined<Key> | KeyUndefined;
47
- export declare type UntypedSparse<Key> = (KeyDefinednessProperty<Key> & TreeDefined<Key>) | (KeyDefined<Key> & TreeUndefined);
48
- /** The term *untyped* refers to the tree representation of a BSP set. Because BSP set trees are only compared in terms
49
- * of their structure, we need to ensure that cuts occur at the same exact points across all possible sets. This is
50
- * enforced by the fact, that at construction time, we attach an `Id` to each BSP set and only allow operations to
51
- * occur on sets with the same `Id`.
52
- *
53
- * The BSP set becomes *untyped*, when we drop that `Id`; now it is possible to operate on sets that are incompatible.
54
- * Doing this, however, allows us to store the set operations only once per set as opposed to carrying them around with
55
- * every node.
56
- */
57
- export declare type UntypedBspSet<Key> = Empty | Dense | UntypedSparse<Key>;
58
- /** A set is considred *sparse*, if we know that w.r.t. to it's bounds it is neither empty, nor dense. */
59
- interface Sparse<Key extends Cachable<Key>, Id> {
60
- setOperations: SetOperations<Key, Id>;
61
- root: UntypedSparse<Key>;
62
- }
63
- export declare type BspSet<Key extends Cachable<Key>, Id> = Empty | Dense | Sparse<Key, Id>;
64
- export interface KeyCache<T> {
65
- depth?: number;
66
- split?: Pair<Pair<CachedKey<T>, number>>;
67
- }
68
- export declare type CachedKey<T> = T & KeyCache<T>;
69
- export declare type Cachable<T> = Disjoint<keyof T, keyof KeyCache<T>>;
70
- export declare type Disjoint<T, U> = [T, U] extends [Exclude<T, U>, Exclude<U, T>] ? any : never;
71
- export declare type RequireAtLeastOne<T> = {
72
- [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
73
- }[keyof T];
74
- /** This is a concrete set operations implementation, tagged with an arbitrary id. */
75
- export interface SetOperations<Key extends Cachable<Key>, Id> {
76
- /** Id here is just a phantom type, so that we can associate the various set instances together */
77
- readonly id: Id;
78
- /** Split the key into two. This will only be called when the current key is incomparable with an element.
79
- * E.g. this would never be called if the key is already a 1x1 rectangle. */
80
- readonly split: (key: CachedKey<Key>) => Pair<Pair<CachedKey<Key>, number>>;
81
- /** Tells, if a given key can be split further */
82
- readonly canSplit: (key: CachedKey<Key>) => boolean;
83
- /** Tells if two keys overlap at all. */
84
- readonly meets: (key1: Key, key2: Key) => boolean;
85
- /** Intersect the keys, if it is possible to exactly respresent their intersection.
86
- * An implementation is never required to compute the intersection as this is just an optimization.
87
- * Precondition: It is guaranteed that the keys meet and that they are incomparable.
88
- */
89
- readonly intersect: (key1: Key, key2: Key) => Key | undefined;
90
- /** Unions the keys, if it is possible to exactly represent their union.
91
- * An implementation is never required to compute the union as this is just an optimization.
92
- * Precondition: It is guaranteed that the keys are incomparable.
93
- */
94
- readonly union: (key1: Key, key2: Key) => Key | undefined;
95
- /** Computes the set difference between two keys, if it is possible to exactly represent their set difference.
96
- * An implementation is never required to compute the difference as this is just an optimization.
97
- * Precondition: It is guaranteed that the keys meet.
98
- */
99
- readonly except: (key1: Key, key2: Key) => Key | undefined;
100
- /** Compare two keys */
101
- readonly compare: (key1: Key, key2: Key) => -1 | 0 | 1 | undefined;
102
- /** The top element of the set. */
103
- readonly top: Key;
104
- }
105
- export declare const cacheKeySplitting: <Key>(splitFunction: (key: CachedKey<Key>) => Pair<Pair<CachedKey<Key>, number>, Pair<CachedKey<Key>, number>>, top: CachedKey<Key>, maxDepth?: number) => (key: CachedKey<Key>) => Pair<Pair<CachedKey<Key>, number>, Pair<CachedKey<Key>, number>>;
106
- export declare function fromUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, root: UntypedBspSet<Key>): BspSet<Key, Id>;
107
- export declare function lazy<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, pathKey: Key, key: Key): UntypedBspSet<Key>;
108
- export declare function createFromKey<Key extends Cachable<Key>, Id>(uncachedSetOperations: SetOperations<Key, Id>): (key: Key) => BspSet<Key, Id>;
109
- export declare function unionUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, left: UntypedBspSet<Key>, right: UntypedBspSet<Key>): UntypedBspSet<Key>;
110
- export declare function union<Key extends Cachable<Key>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>): BspSet<Key, Id>;
111
- export declare function intersectUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, left: UntypedBspSet<Key>, right: UntypedBspSet<Key>): UntypedBspSet<Key>;
112
- export declare function intersect<Key extends Cachable<Key>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>): BspSet<Key, Id>;
113
- export declare function meetsUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, left: UntypedBspSet<Key>, right: UntypedBspSet<Key>): boolean;
114
- export declare function meets<Key extends Cachable<Key>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>): boolean;
115
- export declare function exceptUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, left: UntypedBspSet<Key>, right: UntypedBspSet<Key>): UntypedBspSet<Key>;
116
- export declare function except<Key extends Cachable<Key>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>): BspSet<Key, Id>;
117
- export declare function combineCmp(left: -1 | 0 | 1 | undefined, right: -1 | 0 | 1 | undefined): 0 | 1 | -1 | undefined;
118
- export declare function compareUntyped<Key extends Cachable<Key>, Id>(setOperations: SetOperations<Key, Id>, left: UntypedBspSet<Key>, right: UntypedBspSet<Key>): -1 | 0 | 1 | undefined;
119
- export declare function compare<Key extends Cachable<Key>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>): 0 | 1 | -1 | undefined;
120
- export declare const symmetricDiff: <Key extends Disjoint<keyof Key, keyof KeyCache<T>>, Id>(left: BspSet<Key, Id>, right: BspSet<Key, Id>) => BspSet<Key, Id>;
121
- export declare const complement: <Key extends Disjoint<keyof Key, keyof KeyCache<T>>, Id>(set: BspSet<Key, Id>) => BspSet<Key, Id>;
122
- export declare function getNodeCount<Key extends Cachable<Key>, Id>(set: BspSet<Key, Id>): number;
123
- export declare function forEachKey<Key extends Cachable<Key>, Id>(set: Empty | Sparse<Key, Id>, f: (key: Key) => boolean): boolean;
124
- export {};
125
- //# sourceMappingURL=bspSet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bspSet.d.ts","sourceRoot":"","sources":["../src/bspSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,oDAAoD;AACpD,oBAAY,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7C,eAAO,MAAM,IAAI,6CAA6D,CAAC;AAK/E,oBAAY,OAAO;IAClB,KAAK,IAAA;IACL,KAAK,IAAA;CACL;AAED,UAAU,QAAQ,CAAC,IAAI,EAAE,KAAK;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACtB;AAED,UAAU,OAAO,CAAC,GAAG,EAAE,KAAK;IAC3B,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;CACxB;AAED,oBAAY,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;AAElC;;;;GAIG;AACH,oBAAY,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;AAElC,eAAO,MAAM,KAAK,gBAAgB,CAAC;AACnC,eAAO,MAAM,KAAK,gBAAgB,CAAC;AAEnC,aAAK,UAAU,CAAC,GAAG,IAAI,OAAO,CAAC,GAA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