@fluidframework/sequence 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.224419
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +9 -11
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +449 -0
- package/README.md +364 -183
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/sequence.api.md +741 -0
- package/dist/{defaultMap.js → defaultMap.cjs} +29 -22
- package/dist/defaultMap.cjs.map +1 -0
- package/dist/defaultMap.d.ts +7 -6
- package/dist/defaultMap.d.ts.map +1 -1
- package/dist/defaultMapInterfaces.cjs +7 -0
- package/dist/defaultMapInterfaces.cjs.map +1 -0
- package/dist/defaultMapInterfaces.d.ts +44 -12
- package/dist/defaultMapInterfaces.d.ts.map +1 -1
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +14 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/intervalCollection.cjs +1159 -0
- package/dist/intervalCollection.cjs.map +1 -0
- package/dist/intervalCollection.d.ts +461 -162
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.cjs +66 -0
- package/dist/intervalIndex/endpointInRangeIndex.cjs.map +1 -0
- package/dist/intervalIndex/endpointInRangeIndex.d.ts +34 -0
- package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -0
- package/dist/intervalIndex/endpointIndex.cjs +47 -0
- package/dist/intervalIndex/endpointIndex.cjs.map +1 -0
- package/dist/intervalIndex/endpointIndex.d.ts +38 -0
- package/dist/intervalIndex/endpointIndex.d.ts.map +1 -0
- package/dist/intervalIndex/idIntervalIndex.cjs +44 -0
- package/dist/intervalIndex/idIntervalIndex.cjs.map +1 -0
- package/dist/intervalIndex/idIntervalIndex.d.ts +18 -0
- package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -0
- package/dist/intervalIndex/index.cjs +24 -0
- package/dist/intervalIndex/index.cjs.map +1 -0
- package/dist/intervalIndex/index.d.ts +13 -0
- package/dist/intervalIndex/index.d.ts.map +1 -0
- package/dist/{defaultMapInterfaces.js → intervalIndex/intervalIndex.cjs} +1 -1
- package/dist/intervalIndex/intervalIndex.cjs.map +1 -0
- package/dist/intervalIndex/intervalIndex.d.ts +30 -0
- package/dist/intervalIndex/intervalIndex.d.ts.map +1 -0
- package/dist/intervalIndex/intervalIndexUtils.cjs +22 -0
- package/dist/intervalIndex/intervalIndexUtils.cjs.map +1 -0
- package/dist/intervalIndex/intervalIndexUtils.d.ts +17 -0
- package/dist/intervalIndex/intervalIndexUtils.d.ts.map +1 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.cjs +116 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.cjs.map +1 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +44 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs +41 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs.map +1 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +11 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
- package/dist/intervalIndex/sequenceIntervalIndexes.cjs +7 -0
- package/dist/intervalIndex/sequenceIntervalIndexes.cjs.map +1 -0
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +35 -0
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
- package/dist/intervalIndex/startpointInRangeIndex.cjs +66 -0
- package/dist/intervalIndex/startpointInRangeIndex.cjs.map +1 -0
- package/dist/intervalIndex/startpointInRangeIndex.d.ts +34 -0
- package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -0
- package/dist/intervalTree.cjs +80 -0
- package/dist/intervalTree.cjs.map +1 -0
- package/dist/intervalTree.d.ts +24 -0
- package/dist/intervalTree.d.ts.map +1 -0
- package/dist/intervals/index.cjs +23 -0
- package/dist/intervals/index.cjs.map +1 -0
- package/dist/intervals/index.d.ts +8 -0
- package/dist/intervals/index.d.ts.map +1 -0
- package/dist/intervals/interval.cjs +181 -0
- package/dist/intervals/interval.cjs.map +1 -0
- package/dist/intervals/interval.d.ts +84 -0
- package/dist/intervals/interval.d.ts.map +1 -0
- package/dist/intervals/intervalUtils.cjs +83 -0
- package/dist/intervals/intervalUtils.cjs.map +1 -0
- package/dist/intervals/intervalUtils.d.ts +230 -0
- package/dist/intervals/intervalUtils.d.ts.map +1 -0
- package/dist/intervals/sequenceInterval.cjs +378 -0
- package/dist/intervals/sequenceInterval.cjs.map +1 -0
- package/dist/intervals/sequenceInterval.d.ts +137 -0
- package/dist/intervals/sequenceInterval.d.ts.map +1 -0
- package/dist/{localValues.js → localValues.cjs} +1 -1
- package/dist/localValues.cjs.map +1 -0
- package/dist/localValues.d.ts +2 -1
- package/dist/localValues.d.ts.map +1 -1
- package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
- package/dist/packageVersion.cjs.map +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/revertibles.cjs +425 -0
- package/dist/revertibles.cjs.map +1 -0
- package/dist/revertibles.d.ts +86 -0
- package/dist/revertibles.d.ts.map +1 -0
- package/dist/sequence-alpha.d.ts +1315 -0
- package/dist/sequence-beta.d.ts +244 -0
- package/dist/sequence-public.d.ts +244 -0
- package/dist/sequence-untrimmed.d.ts +1803 -0
- package/dist/{sequence.js → sequence.cjs} +226 -156
- package/dist/sequence.cjs.map +1 -0
- package/dist/sequence.d.ts +125 -48
- package/dist/sequence.d.ts.map +1 -1
- package/dist/{sequenceDeltaEvent.js → sequenceDeltaEvent.cjs} +18 -8
- package/dist/sequenceDeltaEvent.cjs.map +1 -0
- package/dist/sequenceDeltaEvent.d.ts +24 -7
- package/dist/sequenceDeltaEvent.d.ts.map +1 -1
- package/dist/sequenceFactory.cjs +55 -0
- package/dist/sequenceFactory.cjs.map +1 -0
- package/dist/sequenceFactory.d.ts +3 -89
- package/dist/sequenceFactory.d.ts.map +1 -1
- package/dist/{sharedIntervalCollection.js → sharedIntervalCollection.cjs} +17 -22
- package/dist/sharedIntervalCollection.cjs.map +1 -0
- package/dist/sharedIntervalCollection.d.ts +12 -12
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/{sharedSequence.js → sharedSequence.cjs} +29 -22
- package/dist/sharedSequence.cjs.map +1 -0
- package/dist/sharedSequence.d.ts +14 -2
- package/dist/sharedSequence.d.ts.map +1 -1
- package/dist/sharedString.cjs +286 -0
- package/dist/sharedString.cjs.map +1 -0
- package/dist/sharedString.d.ts +58 -22
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/{defaultMap.d.ts → defaultMap.d.mts} +7 -6
- package/lib/defaultMap.d.mts.map +1 -0
- package/lib/{defaultMap.js → defaultMap.mjs} +28 -21
- package/lib/defaultMap.mjs.map +1 -0
- package/lib/{defaultMapInterfaces.d.ts → defaultMapInterfaces.d.mts} +44 -12
- package/lib/defaultMapInterfaces.d.mts.map +1 -0
- package/lib/defaultMapInterfaces.mjs +6 -0
- package/lib/defaultMapInterfaces.mjs.map +1 -0
- package/lib/index.d.mts +17 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +16 -0
- package/lib/index.mjs.map +1 -0
- package/lib/intervalCollection.d.mts +569 -0
- package/lib/intervalCollection.d.mts.map +1 -0
- package/lib/intervalCollection.mjs +1144 -0
- package/lib/intervalCollection.mjs.map +1 -0
- package/lib/intervalIndex/endpointInRangeIndex.d.mts +34 -0
- package/lib/intervalIndex/endpointInRangeIndex.d.mts.map +1 -0
- package/lib/intervalIndex/endpointInRangeIndex.mjs +61 -0
- package/lib/intervalIndex/endpointInRangeIndex.mjs.map +1 -0
- package/lib/intervalIndex/endpointIndex.d.mts +38 -0
- package/lib/intervalIndex/endpointIndex.d.mts.map +1 -0
- package/lib/intervalIndex/endpointIndex.mjs +42 -0
- package/lib/intervalIndex/endpointIndex.mjs.map +1 -0
- package/lib/intervalIndex/idIntervalIndex.d.mts +18 -0
- package/lib/intervalIndex/idIntervalIndex.d.mts.map +1 -0
- package/lib/intervalIndex/idIntervalIndex.mjs +40 -0
- package/lib/intervalIndex/idIntervalIndex.mjs.map +1 -0
- package/lib/intervalIndex/index.d.mts +13 -0
- package/lib/intervalIndex/index.d.mts.map +1 -0
- package/lib/intervalIndex/index.mjs +11 -0
- package/lib/intervalIndex/index.mjs.map +1 -0
- package/lib/intervalIndex/intervalIndex.d.mts +30 -0
- package/lib/intervalIndex/intervalIndex.d.mts.map +1 -0
- package/lib/{defaultMapInterfaces.js → intervalIndex/intervalIndex.mjs} +1 -1
- package/lib/intervalIndex/intervalIndex.mjs.map +1 -0
- package/lib/intervalIndex/intervalIndexUtils.d.mts +17 -0
- package/lib/intervalIndex/intervalIndexUtils.d.mts.map +1 -0
- package/lib/intervalIndex/intervalIndexUtils.mjs +18 -0
- package/lib/intervalIndex/intervalIndexUtils.mjs.map +1 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.d.mts +44 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.d.mts.map +1 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.mjs +111 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.mjs.map +1 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts +11 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts.map +1 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs +37 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs.map +1 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.d.mts +35 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.d.mts.map +1 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.mjs +6 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.mjs.map +1 -0
- package/lib/intervalIndex/startpointInRangeIndex.d.mts +34 -0
- package/lib/intervalIndex/startpointInRangeIndex.d.mts.map +1 -0
- package/lib/intervalIndex/startpointInRangeIndex.mjs +61 -0
- package/lib/intervalIndex/startpointInRangeIndex.mjs.map +1 -0
- package/lib/intervalTree.d.mts +24 -0
- package/lib/intervalTree.d.mts.map +1 -0
- package/lib/intervalTree.mjs +76 -0
- package/lib/intervalTree.mjs.map +1 -0
- package/lib/intervals/index.d.mts +8 -0
- package/lib/intervals/index.d.mts.map +1 -0
- package/lib/intervals/index.mjs +8 -0
- package/lib/intervals/index.mjs.map +1 -0
- package/lib/intervals/interval.d.mts +84 -0
- package/lib/intervals/interval.d.mts.map +1 -0
- package/lib/intervals/interval.mjs +176 -0
- package/lib/intervals/interval.mjs.map +1 -0
- package/lib/intervals/intervalUtils.d.mts +230 -0
- package/lib/intervals/intervalUtils.d.mts.map +1 -0
- package/lib/intervals/intervalUtils.mjs +77 -0
- package/lib/intervals/intervalUtils.mjs.map +1 -0
- package/lib/intervals/sequenceInterval.d.mts +137 -0
- package/lib/intervals/sequenceInterval.d.mts.map +1 -0
- package/lib/intervals/sequenceInterval.mjs +370 -0
- package/lib/intervals/sequenceInterval.mjs.map +1 -0
- package/lib/{localValues.d.ts → localValues.d.mts} +3 -2
- package/lib/localValues.d.mts.map +1 -0
- package/lib/{localValues.js → localValues.mjs} +2 -2
- package/lib/localValues.mjs.map +1 -0
- package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
- package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
- package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
- package/lib/packageVersion.mjs.map +1 -0
- package/lib/revertibles.d.mts +86 -0
- package/lib/revertibles.d.mts.map +1 -0
- package/lib/revertibles.mjs +416 -0
- package/lib/revertibles.mjs.map +1 -0
- package/lib/sequence-alpha.d.mts +1315 -0
- package/lib/sequence-beta.d.mts +244 -0
- package/lib/sequence-public.d.mts +244 -0
- package/lib/sequence-untrimmed.d.mts +1803 -0
- package/lib/{sequence.d.ts → sequence.d.mts} +127 -50
- package/lib/sequence.d.mts.map +1 -0
- package/lib/{sequence.js → sequence.mjs} +225 -152
- package/lib/sequence.mjs.map +1 -0
- package/lib/{sequenceDeltaEvent.d.ts → sequenceDeltaEvent.d.mts} +24 -7
- package/lib/sequenceDeltaEvent.d.mts.map +1 -0
- package/lib/{sequenceDeltaEvent.js → sequenceDeltaEvent.mjs} +20 -8
- package/lib/sequenceDeltaEvent.mjs.map +1 -0
- package/lib/sequenceFactory.d.mts +22 -0
- package/lib/sequenceFactory.d.mts.map +1 -0
- package/lib/sequenceFactory.mjs +51 -0
- package/lib/sequenceFactory.mjs.map +1 -0
- package/lib/{sharedIntervalCollection.d.ts → sharedIntervalCollection.d.mts} +12 -12
- package/lib/sharedIntervalCollection.d.mts.map +1 -0
- package/lib/{sharedIntervalCollection.js → sharedIntervalCollection.mjs} +16 -21
- package/lib/sharedIntervalCollection.mjs.map +1 -0
- package/lib/{sharedSequence.d.ts → sharedSequence.d.mts} +15 -3
- package/lib/sharedSequence.d.mts.map +1 -0
- package/lib/{sharedSequence.js → sharedSequence.mjs} +30 -23
- package/lib/sharedSequence.mjs.map +1 -0
- package/lib/{sharedString.d.ts → sharedString.d.mts} +60 -24
- package/lib/sharedString.d.mts.map +1 -0
- package/lib/sharedString.mjs +281 -0
- package/lib/sharedString.mjs.map +1 -0
- package/package.json +146 -75
- package/prettier.config.cjs +8 -0
- package/sequence.test-files.tar +0 -0
- package/src/defaultMap.ts +417 -403
- package/src/defaultMapInterfaces.ts +157 -117
- package/src/index.ts +86 -26
- package/src/intervalCollection.ts +2043 -1563
- package/src/intervalIndex/endpointInRangeIndex.ts +116 -0
- package/src/intervalIndex/endpointIndex.ts +91 -0
- package/src/intervalIndex/idIntervalIndex.ts +64 -0
- package/src/intervalIndex/index.ts +25 -0
- package/src/intervalIndex/intervalIndex.ts +32 -0
- package/src/intervalIndex/intervalIndexUtils.ts +27 -0
- package/src/intervalIndex/overlappingIntervalsIndex.ts +187 -0
- package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +80 -0
- package/src/intervalIndex/sequenceIntervalIndexes.ts +34 -0
- package/src/intervalIndex/startpointInRangeIndex.ts +114 -0
- package/src/intervalTree.ts +98 -0
- package/src/intervals/index.ts +25 -0
- package/src/intervals/interval.ts +238 -0
- package/src/intervals/intervalUtils.ts +288 -0
- package/src/intervals/sequenceInterval.ts +616 -0
- package/src/localValues.ts +68 -73
- package/src/packageVersion.ts +1 -1
- package/src/revertibles.ts +693 -0
- package/src/sequence.ts +845 -690
- package/src/sequenceDeltaEvent.ts +164 -131
- package/src/sequenceFactory.ts +58 -214
- package/src/sharedIntervalCollection.ts +161 -152
- package/src/sharedSequence.ts +181 -167
- package/src/sharedString.ts +390 -234
- package/tsc-multi.test.json +10 -0
- package/tsconfig.json +11 -13
- package/.editorconfig +0 -7
- package/.vscode/launch.json +0 -15
- package/dist/defaultMap.js.map +0 -1
- package/dist/defaultMapInterfaces.js.map +0 -1
- package/dist/index.js +0 -44
- package/dist/index.js.map +0 -1
- package/dist/intervalCollection.js +0 -1250
- package/dist/intervalCollection.js.map +0 -1
- package/dist/localValues.js.map +0 -1
- package/dist/packageVersion.js.map +0 -1
- package/dist/sequence.js.map +0 -1
- package/dist/sequenceDeltaEvent.js.map +0 -1
- package/dist/sequenceFactory.js +0 -192
- package/dist/sequenceFactory.js.map +0 -1
- package/dist/sharedIntervalCollection.js.map +0 -1
- package/dist/sharedNumberSequence.d.ts +0 -50
- package/dist/sharedNumberSequence.d.ts.map +0 -1
- package/dist/sharedNumberSequence.js +0 -61
- package/dist/sharedNumberSequence.js.map +0 -1
- package/dist/sharedObjectSequence.d.ts +0 -50
- package/dist/sharedObjectSequence.d.ts.map +0 -1
- package/dist/sharedObjectSequence.js +0 -61
- package/dist/sharedObjectSequence.js.map +0 -1
- package/dist/sharedSequence.js.map +0 -1
- package/dist/sharedString.js +0 -187
- package/dist/sharedString.js.map +0 -1
- package/dist/sparsematrix.d.ts +0 -139
- package/dist/sparsematrix.d.ts.map +0 -1
- package/dist/sparsematrix.js +0 -332
- package/dist/sparsematrix.js.map +0 -1
- package/lib/defaultMap.d.ts.map +0 -1
- package/lib/defaultMap.js.map +0 -1
- package/lib/defaultMapInterfaces.d.ts.map +0 -1
- package/lib/defaultMapInterfaces.js.map +0 -1
- package/lib/index.d.ts +0 -27
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -26
- package/lib/index.js.map +0 -1
- package/lib/intervalCollection.d.ts +0 -270
- package/lib/intervalCollection.d.ts.map +0 -1
- package/lib/intervalCollection.js +0 -1238
- package/lib/intervalCollection.js.map +0 -1
- package/lib/localValues.d.ts.map +0 -1
- package/lib/localValues.js.map +0 -1
- package/lib/packageVersion.js.map +0 -1
- package/lib/sequence.d.ts.map +0 -1
- package/lib/sequence.js.map +0 -1
- package/lib/sequenceDeltaEvent.d.ts.map +0 -1
- package/lib/sequenceDeltaEvent.js.map +0 -1
- package/lib/sequenceFactory.d.ts +0 -108
- package/lib/sequenceFactory.d.ts.map +0 -1
- package/lib/sequenceFactory.js +0 -186
- package/lib/sequenceFactory.js.map +0 -1
- package/lib/sharedIntervalCollection.d.ts.map +0 -1
- package/lib/sharedIntervalCollection.js.map +0 -1
- package/lib/sharedNumberSequence.d.ts +0 -50
- package/lib/sharedNumberSequence.d.ts.map +0 -1
- package/lib/sharedNumberSequence.js +0 -57
- package/lib/sharedNumberSequence.js.map +0 -1
- package/lib/sharedObjectSequence.d.ts +0 -50
- package/lib/sharedObjectSequence.d.ts.map +0 -1
- package/lib/sharedObjectSequence.js +0 -57
- package/lib/sharedObjectSequence.js.map +0 -1
- package/lib/sharedSequence.d.ts.map +0 -1
- package/lib/sharedSequence.js.map +0 -1
- package/lib/sharedString.d.ts.map +0 -1
- package/lib/sharedString.js +0 -183
- package/lib/sharedString.js.map +0 -1
- package/lib/sparsematrix.d.ts +0 -139
- package/lib/sparsematrix.d.ts.map +0 -1
- package/lib/sparsematrix.js +0 -323
- package/lib/sparsematrix.js.map +0 -1
- package/src/sharedNumberSequence.ts +0 -62
- package/src/sharedObjectSequence.ts +0 -62
- package/src/sparsematrix.ts +0 -421
- package/tsconfig.esnext.json +0 -7
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable import/no-deprecated */
|
|
6
|
+
|
|
7
|
+
import { Client, PropertyAction, RedBlackTree } from "@fluidframework/merge-tree";
|
|
8
|
+
import {
|
|
9
|
+
IIntervalHelpers,
|
|
10
|
+
ISerializableInterval,
|
|
11
|
+
IntervalType,
|
|
12
|
+
SequenceInterval,
|
|
13
|
+
sequenceIntervalHelpers,
|
|
14
|
+
} from "../intervals";
|
|
15
|
+
import { SharedString } from "../sharedString";
|
|
16
|
+
import { IntervalIndex } from "./intervalIndex";
|
|
17
|
+
import { HasComparisonOverride, compareOverrideables, forceCompare } from "./intervalIndexUtils";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Collection of intervals.
|
|
21
|
+
*
|
|
22
|
+
* Provide additional APIs to support efficiently querying a collection of intervals whose startpoints fall within a specified range.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export interface IStartpointInRangeIndex<TInterval extends ISerializableInterval>
|
|
26
|
+
extends IntervalIndex<TInterval> {
|
|
27
|
+
/**
|
|
28
|
+
* @returns an array of all intervals contained in this collection whose startpoints locate in the range [start, end] (includes both ends)
|
|
29
|
+
*/
|
|
30
|
+
findIntervalsWithStartpointInRange(start: number, end: number): TInterval[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class StartpointInRangeIndex<TInterval extends ISerializableInterval>
|
|
34
|
+
implements IStartpointInRangeIndex<TInterval>
|
|
35
|
+
{
|
|
36
|
+
private readonly intervalTree;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
private readonly client: Client,
|
|
40
|
+
private readonly helpers: IIntervalHelpers<TInterval>,
|
|
41
|
+
) {
|
|
42
|
+
this.intervalTree = new RedBlackTree<TInterval, TInterval>((a: TInterval, b: TInterval) => {
|
|
43
|
+
const compareStartsResult = a.compareStart(b);
|
|
44
|
+
if (compareStartsResult !== 0) {
|
|
45
|
+
return compareStartsResult;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const overrideablesComparison = compareOverrideables(
|
|
49
|
+
a as Partial<HasComparisonOverride>,
|
|
50
|
+
b as Partial<HasComparisonOverride>,
|
|
51
|
+
);
|
|
52
|
+
if (overrideablesComparison !== 0) {
|
|
53
|
+
return overrideablesComparison;
|
|
54
|
+
}
|
|
55
|
+
const aId = a.getIntervalId();
|
|
56
|
+
const bId = b.getIntervalId();
|
|
57
|
+
if (aId !== undefined && bId !== undefined) {
|
|
58
|
+
return aId.localeCompare(bId);
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public add(interval: TInterval): void {
|
|
65
|
+
this.intervalTree.put(interval, interval);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public remove(interval: TInterval): void {
|
|
69
|
+
this.intervalTree.remove(interval);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public findIntervalsWithStartpointInRange(start: number, end: number): TInterval[] {
|
|
73
|
+
if (start <= 0 || start > end || this.intervalTree.isEmpty()) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const results: TInterval[] = [];
|
|
77
|
+
const action: PropertyAction<TInterval, TInterval> = (node) => {
|
|
78
|
+
results.push(node.data);
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const transientStartInterval = this.helpers.create(
|
|
83
|
+
"transient",
|
|
84
|
+
start,
|
|
85
|
+
start,
|
|
86
|
+
this.client,
|
|
87
|
+
IntervalType.Transient,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const transientEndInterval = this.helpers.create(
|
|
91
|
+
"transient",
|
|
92
|
+
end,
|
|
93
|
+
end,
|
|
94
|
+
this.client,
|
|
95
|
+
IntervalType.Transient,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Add comparison overrides to the transient intervals
|
|
99
|
+
(transientStartInterval as Partial<HasComparisonOverride>)[forceCompare] = -1;
|
|
100
|
+
(transientEndInterval as Partial<HasComparisonOverride>)[forceCompare] = 1;
|
|
101
|
+
|
|
102
|
+
this.intervalTree.mapRange(action, results, transientStartInterval, transientEndInterval);
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export function createStartpointInRangeIndex(
|
|
110
|
+
sharedString: SharedString,
|
|
111
|
+
): IStartpointInRangeIndex<SequenceInterval> {
|
|
112
|
+
const client = (sharedString as unknown as { client: Client }).client;
|
|
113
|
+
return new StartpointInRangeIndex<SequenceInterval>(client, sequenceIntervalHelpers);
|
|
114
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
RBNode,
|
|
8
|
+
IRBAugmentation,
|
|
9
|
+
IRBMatcher,
|
|
10
|
+
RedBlackTree,
|
|
11
|
+
RBNodeActions,
|
|
12
|
+
} from "@fluidframework/merge-tree";
|
|
13
|
+
import { IInterval } from "./intervals";
|
|
14
|
+
|
|
15
|
+
export interface AugmentedIntervalNode {
|
|
16
|
+
minmax: IInterval;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const intervalComparer = (a: IInterval, b: IInterval) => a.compare(b);
|
|
20
|
+
|
|
21
|
+
export type IntervalNode<T extends IInterval> = RBNode<T, AugmentedIntervalNode>;
|
|
22
|
+
|
|
23
|
+
export class IntervalTree<T extends IInterval>
|
|
24
|
+
implements IRBAugmentation<T, AugmentedIntervalNode>, IRBMatcher<T, AugmentedIntervalNode>
|
|
25
|
+
{
|
|
26
|
+
public intervals = new RedBlackTree<T, AugmentedIntervalNode>(intervalComparer, this);
|
|
27
|
+
|
|
28
|
+
public remove(x: T) {
|
|
29
|
+
this.intervals.remove(x);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public removeExisting(x: T) {
|
|
33
|
+
this.intervals.removeExisting(x);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public put(x: T) {
|
|
37
|
+
this.intervals.put(x, { minmax: x.clone() });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public map(fn: (x: T) => void) {
|
|
41
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
42
|
+
infix: (node) => {
|
|
43
|
+
fn(node.key);
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
showStructure: true,
|
|
47
|
+
};
|
|
48
|
+
this.intervals.walk(actions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public mapUntil(fn: (X: T) => boolean) {
|
|
52
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
53
|
+
infix: (node) => {
|
|
54
|
+
return fn(node.key);
|
|
55
|
+
},
|
|
56
|
+
showStructure: true,
|
|
57
|
+
};
|
|
58
|
+
this.intervals.walk(actions);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public mapBackward(fn: (x: T) => void) {
|
|
62
|
+
const actions: RBNodeActions<T, AugmentedIntervalNode> = {
|
|
63
|
+
infix: (node) => {
|
|
64
|
+
fn(node.key);
|
|
65
|
+
return true;
|
|
66
|
+
},
|
|
67
|
+
showStructure: true,
|
|
68
|
+
};
|
|
69
|
+
this.intervals.walkBackward(actions);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// TODO: toString()
|
|
73
|
+
public match(x: T) {
|
|
74
|
+
return this.intervals.gather(x, this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public matchNode(node: IntervalNode<T> | undefined, key: T) {
|
|
78
|
+
return !!node && node.key.overlaps(key);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public continueSubtree(node: IntervalNode<T> | undefined, key: T) {
|
|
82
|
+
return !!node && node.data.minmax.overlaps(key);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public update(node: IntervalNode<T>) {
|
|
86
|
+
if (node.left && node.right) {
|
|
87
|
+
node.data.minmax = node.key.union(node.left.data.minmax.union(node.right.data.minmax));
|
|
88
|
+
} else {
|
|
89
|
+
if (node.left) {
|
|
90
|
+
node.data.minmax = node.key.union(node.left.data.minmax);
|
|
91
|
+
} else if (node.right) {
|
|
92
|
+
node.data.minmax = node.key.union(node.right.data.minmax);
|
|
93
|
+
} else {
|
|
94
|
+
node.data.minmax = node.key.clone();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
IInterval,
|
|
8
|
+
ISerializedInterval,
|
|
9
|
+
ISerializableInterval,
|
|
10
|
+
IntervalOpType,
|
|
11
|
+
IntervalType,
|
|
12
|
+
IIntervalHelpers,
|
|
13
|
+
IntervalStickiness,
|
|
14
|
+
SerializedIntervalDelta,
|
|
15
|
+
CompressedSerializedInterval,
|
|
16
|
+
endReferenceSlidingPreference,
|
|
17
|
+
startReferenceSlidingPreference,
|
|
18
|
+
} from "./intervalUtils";
|
|
19
|
+
export { Interval, createInterval, intervalHelpers } from "./interval";
|
|
20
|
+
export {
|
|
21
|
+
SequenceInterval,
|
|
22
|
+
createSequenceInterval,
|
|
23
|
+
createPositionReferenceFromSegoff,
|
|
24
|
+
sequenceIntervalHelpers,
|
|
25
|
+
} from "./sequenceInterval";
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable import/no-deprecated */
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
PropertiesManager,
|
|
9
|
+
PropertySet,
|
|
10
|
+
createMap,
|
|
11
|
+
reservedRangeLabelsKey,
|
|
12
|
+
} from "@fluidframework/merge-tree";
|
|
13
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
14
|
+
import { assert } from "@fluidframework/core-utils";
|
|
15
|
+
import { UsageError } from "@fluidframework/telemetry-utils";
|
|
16
|
+
import { SequencePlace } from "../intervalCollection";
|
|
17
|
+
import { IIntervalHelpers, ISerializableInterval, ISerializedInterval } from "./intervalUtils";
|
|
18
|
+
|
|
19
|
+
const reservedIntervalIdKey = "intervalId";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Serializable interval whose endpoints are plain-old numbers.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export class Interval implements ISerializableInterval {
|
|
26
|
+
/**
|
|
27
|
+
* {@inheritDoc ISerializableInterval.properties}
|
|
28
|
+
*/
|
|
29
|
+
public properties: PropertySet = createMap<any>();
|
|
30
|
+
|
|
31
|
+
/***/
|
|
32
|
+
public auxProps: PropertySet[] | undefined;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* {@inheritDoc ISerializableInterval.propertyManager}
|
|
36
|
+
*/
|
|
37
|
+
public readonly propertyManager: PropertiesManager = new PropertiesManager();
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
public start: number,
|
|
41
|
+
public end: number,
|
|
42
|
+
props?: PropertySet,
|
|
43
|
+
) {
|
|
44
|
+
if (props) {
|
|
45
|
+
this.addProperties(props);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* {@inheritDoc ISerializableInterval.getIntervalId}
|
|
51
|
+
*/
|
|
52
|
+
public getIntervalId(): string {
|
|
53
|
+
const id = this.properties?.[reservedIntervalIdKey];
|
|
54
|
+
assert(id !== undefined, 0x5e1 /* interval ID should not be undefined */);
|
|
55
|
+
return `${id}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @returns an array containing any auxiliary property sets added with `addPropertySet`.
|
|
60
|
+
*/
|
|
61
|
+
public getAdditionalPropertySets(): PropertySet[] {
|
|
62
|
+
return this.auxProps ?? [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Adds an auxiliary set of properties to this interval.
|
|
67
|
+
* These properties can be recovered using `getAdditionalPropertySets`
|
|
68
|
+
* @param props - set of properties to add
|
|
69
|
+
* @remarks This gets called as part of the default conflict resolver for `IIntervalCollection<Interval>`
|
|
70
|
+
* (i.e. non-sequence-based interval collections). However, the additional properties don't get serialized.
|
|
71
|
+
* This functionality seems half-baked.
|
|
72
|
+
*/
|
|
73
|
+
public addPropertySet(props: PropertySet) {
|
|
74
|
+
if (this.auxProps === undefined) {
|
|
75
|
+
this.auxProps = [];
|
|
76
|
+
}
|
|
77
|
+
this.auxProps.push(props);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* {@inheritDoc ISerializableInterval.serialize}
|
|
82
|
+
*/
|
|
83
|
+
public serialize(): ISerializedInterval {
|
|
84
|
+
const serializedInterval: ISerializedInterval = {
|
|
85
|
+
end: this.end,
|
|
86
|
+
intervalType: 0,
|
|
87
|
+
sequenceNumber: 0,
|
|
88
|
+
start: this.start,
|
|
89
|
+
};
|
|
90
|
+
if (this.properties) {
|
|
91
|
+
serializedInterval.properties = this.properties;
|
|
92
|
+
}
|
|
93
|
+
return serializedInterval;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* {@inheritDoc IInterval.clone}
|
|
98
|
+
*/
|
|
99
|
+
public clone() {
|
|
100
|
+
return new Interval(this.start, this.end, this.properties);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* {@inheritDoc IInterval.compare}
|
|
105
|
+
*/
|
|
106
|
+
public compare(b: Interval) {
|
|
107
|
+
const startResult = this.compareStart(b);
|
|
108
|
+
if (startResult === 0) {
|
|
109
|
+
const endResult = this.compareEnd(b);
|
|
110
|
+
if (endResult === 0) {
|
|
111
|
+
const thisId = this.getIntervalId();
|
|
112
|
+
if (thisId) {
|
|
113
|
+
const bId = b.getIntervalId();
|
|
114
|
+
if (bId) {
|
|
115
|
+
return thisId > bId ? 1 : thisId < bId ? -1 : 0;
|
|
116
|
+
}
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
return 0;
|
|
120
|
+
} else {
|
|
121
|
+
return endResult;
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
return startResult;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* {@inheritDoc IInterval.compareStart}
|
|
130
|
+
*/
|
|
131
|
+
public compareStart(b: Interval) {
|
|
132
|
+
return this.start - b.start;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* {@inheritDoc IInterval.compareEnd}
|
|
137
|
+
*/
|
|
138
|
+
public compareEnd(b: Interval) {
|
|
139
|
+
return this.end - b.end;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* {@inheritDoc IInterval.overlaps}
|
|
144
|
+
*/
|
|
145
|
+
public overlaps(b: Interval) {
|
|
146
|
+
const result = this.start <= b.end && this.end >= b.start;
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* {@inheritDoc IInterval.union}
|
|
152
|
+
*/
|
|
153
|
+
public union(b: Interval) {
|
|
154
|
+
return new Interval(
|
|
155
|
+
Math.min(this.start, b.start),
|
|
156
|
+
Math.max(this.end, b.end),
|
|
157
|
+
this.properties,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public getProperties() {
|
|
162
|
+
return this.properties;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* {@inheritDoc ISerializableInterval.addProperties}
|
|
167
|
+
*/
|
|
168
|
+
public addProperties(
|
|
169
|
+
newProps: PropertySet,
|
|
170
|
+
collaborating: boolean = false,
|
|
171
|
+
seq?: number,
|
|
172
|
+
): PropertySet | undefined {
|
|
173
|
+
if (newProps) {
|
|
174
|
+
return this.propertyManager.addProperties(
|
|
175
|
+
this.properties,
|
|
176
|
+
newProps,
|
|
177
|
+
seq,
|
|
178
|
+
collaborating,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* {@inheritDoc IInterval.modify}
|
|
185
|
+
*/
|
|
186
|
+
public modify(
|
|
187
|
+
label: string,
|
|
188
|
+
start?: SequencePlace,
|
|
189
|
+
end?: SequencePlace,
|
|
190
|
+
op?: ISequencedDocumentMessage,
|
|
191
|
+
) {
|
|
192
|
+
if (typeof start === "string" || typeof end === "string") {
|
|
193
|
+
throw new UsageError(
|
|
194
|
+
"The start and end positions of a plain interval may not be on the special endpoint segments.",
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const startPos = typeof start === "number" ? start : start?.pos ?? this.start;
|
|
199
|
+
const endPos = typeof end === "number" ? end : end?.pos ?? this.end;
|
|
200
|
+
|
|
201
|
+
if (this.start === startPos && this.end === endPos) {
|
|
202
|
+
// Return undefined to indicate that no change is necessary.
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const newInterval = new Interval(startPos, endPos);
|
|
206
|
+
if (this.properties) {
|
|
207
|
+
this.propertyManager.copyTo(
|
|
208
|
+
this.properties,
|
|
209
|
+
newInterval.properties,
|
|
210
|
+
newInterval.propertyManager,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return newInterval;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function createInterval(label: string, start: SequencePlace, end: SequencePlace): Interval {
|
|
218
|
+
if (typeof start === "string" || typeof end === "string") {
|
|
219
|
+
throw new UsageError(
|
|
220
|
+
"The start and end positions of a plain interval may not be on the special endpoint segments.",
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const rangeProp: PropertySet = {};
|
|
225
|
+
|
|
226
|
+
if (label && label.length > 0) {
|
|
227
|
+
rangeProp[reservedRangeLabelsKey] = [label];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const startPos = typeof start === "number" ? start : start.pos;
|
|
231
|
+
const endPos = typeof end === "number" ? end : end.pos;
|
|
232
|
+
|
|
233
|
+
return new Interval(startPos, endPos, rangeProp);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const intervalHelpers: IIntervalHelpers<Interval> = {
|
|
237
|
+
create: createInterval,
|
|
238
|
+
};
|