145
return new OffsetPair(this.offset1 + offset, this.offset2 + offset);
146
}
148
>
public equals(other: OffsetPair): boolean {
149
return this.offset1 === other.offset1 && this.offset2 === other.offset2;
150
}
152
>
153
>
export interface ISequence {
154
>
getElement(offset: number): number;
155
>
get length(): number;
156
>
157
>
/**
158
>
* The higher the score, the better that offset can be used to split the sequence.
159
>
* Is used to optimize insertions.
160
>
* Must not be negative.
161
>
*/
162
>
getBoundaryScore?(length: number): number;
163
>
164
>
/**
165
>
* For line sequences, getElement returns a number representing trimmed lines.
166
>
* This however checks equality for the original lines.
167
>
* It prevents shifting to less matching lines.
168
>
*/
169
>
isStronglyEqual(offset1: number, offset2: number): boolean;
170
>
}
171
>
172
>
export interface ITimeout {
173
>
isValid(): boolean;
174
>
}
175
>
176
>
export class InfiniteTimeout implements ITimeout {
177
>
public static instance = new InfiniteTimeout();
178
>
179
>
isValid(): boolean {
180
return true;
181
}
183
>
184
>
export class DateTimeout implements ITimeout {
185
>
private readonly startTime = Date.now();
186
>
private valid = true;
187
>
188
>
constructor(private timeout: number) {
189
if (timeout <= 0) {
190
throw new BugIndicatingError('timeout must be positive');
191
}
192
}
194
>
// Recommendation: Set a log-point `{this.disable()}` in the body
195
>
public isValid(): boolean {
196
const valid = Date.now() - this.startTime < this.timeout;
197
if (!valid && this.valid) {