@fluidframework/core-utils 2.0.0-internal.6.1.1 → 2.0.0-internal.6.3.0
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 +1 -1
- package/CHANGELOG.md +8 -0
- package/README.md +32 -6
- package/dist/assert.d.ts +16 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +24 -0
- package/dist/assert.js.map +1 -0
- package/dist/delay.d.ts +10 -0
- package/dist/delay.d.ts.map +1 -0
- package/dist/delay.js +14 -0
- package/dist/delay.js.map +1 -0
- package/dist/heap.d.ts +82 -0
- package/dist/heap.d.ts.map +1 -0
- package/dist/heap.js +139 -0
- package/dist/heap.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/promises.d.ts +37 -0
- package/dist/promises.d.ts.map +1 -0
- package/dist/promises.js +57 -0
- package/dist/promises.js.map +1 -0
- package/dist/timer.d.ts +105 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js +186 -0
- package/dist/timer.js.map +1 -0
- package/dist/unreachable.d.ts +21 -0
- package/dist/unreachable.d.ts.map +1 -0
- package/dist/unreachable.js +27 -0
- package/dist/unreachable.js.map +1 -0
- package/lib/assert.d.ts +16 -0
- package/lib/assert.d.ts.map +1 -0
- package/lib/assert.js +20 -0
- package/lib/assert.js.map +1 -0
- package/lib/delay.d.ts +10 -0
- package/lib/delay.d.ts.map +1 -0
- package/lib/delay.js +10 -0
- package/lib/delay.js.map +1 -0
- package/lib/heap.d.ts +82 -0
- package/lib/heap.d.ts.map +1 -0
- package/lib/heap.js +135 -0
- package/lib/heap.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/promises.d.ts +37 -0
- package/lib/promises.d.ts.map +1 -0
- package/lib/promises.js +53 -0
- package/lib/promises.js.map +1 -0
- package/lib/timer.d.ts +105 -0
- package/lib/timer.d.ts.map +1 -0
- package/lib/timer.js +180 -0
- package/lib/timer.js.map +1 -0
- package/lib/unreachable.d.ts +21 -0
- package/lib/unreachable.d.ts.map +1 -0
- package/lib/unreachable.js +23 -0
- package/lib/unreachable.js.map +1 -0
- package/package.json +7 -9
- package/src/assert.ts +22 -0
- package/src/delay.ts +11 -0
- package/src/heap.ts +174 -0
- package/src/index.ts +13 -0
- package/src/promises.ts +60 -0
- package/src/timer.ts +279 -0
- package/src/unreachable.ts +23 -0
package/dist/timer.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export interface ITimer {
|
|
6
|
+
/**
|
|
7
|
+
* True if timer is currently running
|
|
8
|
+
*/
|
|
9
|
+
readonly hasTimer: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Starts the timer
|
|
12
|
+
*/
|
|
13
|
+
start(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Cancels the timer if already running
|
|
16
|
+
*/
|
|
17
|
+
clear(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.
|
|
21
|
+
* Timeouts may not be exactly accurate due to browser implementations and the OS.
|
|
22
|
+
* https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate
|
|
23
|
+
* @param timeoutFn - Executed when the timeout expires
|
|
24
|
+
* @param timeoutMs - Duration of the timeout in milliseconds
|
|
25
|
+
* @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when
|
|
26
|
+
* timeoutMs greater than maxTimeout
|
|
27
|
+
* @returns The initial timeout
|
|
28
|
+
*/
|
|
29
|
+
export declare function setLongTimeout(timeoutFn: () => void, timeoutMs: number, setTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void): ReturnType<typeof setTimeout>;
|
|
30
|
+
/**
|
|
31
|
+
* This class is a thin wrapper over setTimeout and clearTimeout which
|
|
32
|
+
* makes it simpler to keep track of recurring timeouts with the same
|
|
33
|
+
* or similar handlers and timeouts. This class supports long timeouts
|
|
34
|
+
* or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Timer implements ITimer {
|
|
37
|
+
private readonly defaultTimeout;
|
|
38
|
+
private readonly defaultHandler;
|
|
39
|
+
private readonly getCurrentTick;
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the timer is running.
|
|
42
|
+
*/
|
|
43
|
+
get hasTimer(): boolean;
|
|
44
|
+
private runningState;
|
|
45
|
+
constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);
|
|
46
|
+
/**
|
|
47
|
+
* Calls setTimeout and tracks the resulting timeout.
|
|
48
|
+
* @param ms - overrides default timeout in ms
|
|
49
|
+
* @param handler - overrides default handler
|
|
50
|
+
*/
|
|
51
|
+
start(ms?: number, handler?: () => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* Calls clearTimeout on the underlying timeout if running.
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Restarts the timer with the new handler and duration.
|
|
58
|
+
* If a new handler is passed, the original handler may
|
|
59
|
+
* never execute.
|
|
60
|
+
* This is a potentially more efficient way to clear and start
|
|
61
|
+
* a new timer.
|
|
62
|
+
* @param ms - overrides previous or default timeout in ms
|
|
63
|
+
* @param handler - overrides previous or default handler
|
|
64
|
+
*/
|
|
65
|
+
restart(ms?: number, handler?: () => void): void;
|
|
66
|
+
private startCore;
|
|
67
|
+
private handler;
|
|
68
|
+
private calculateRemainingTime;
|
|
69
|
+
}
|
|
70
|
+
export interface IPromiseTimerResult {
|
|
71
|
+
timerResult: "timeout" | "cancel";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Timer which offers a promise that fulfills when the timer
|
|
75
|
+
* completes.
|
|
76
|
+
*/
|
|
77
|
+
export interface IPromiseTimer extends ITimer {
|
|
78
|
+
/**
|
|
79
|
+
* Starts the timer and returns a promise that
|
|
80
|
+
* resolves when the timer times out or is canceled.
|
|
81
|
+
*/
|
|
82
|
+
start(): Promise<IPromiseTimerResult>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* This class is a wrapper over setTimeout and clearTimeout which
|
|
86
|
+
* makes it simpler to keep track of recurring timeouts with the
|
|
87
|
+
* same handlers and timeouts, while also providing a promise that
|
|
88
|
+
* resolves when it times out.
|
|
89
|
+
*/
|
|
90
|
+
export declare class PromiseTimer implements IPromiseTimer {
|
|
91
|
+
private deferred?;
|
|
92
|
+
private readonly timer;
|
|
93
|
+
/**
|
|
94
|
+
* {@inheritDoc Timer.hasTimer}
|
|
95
|
+
*/
|
|
96
|
+
get hasTimer(): boolean;
|
|
97
|
+
constructor(defaultTimeout: number, defaultHandler: () => void);
|
|
98
|
+
/**
|
|
99
|
+
* {@inheritDoc IPromiseTimer.start}
|
|
100
|
+
*/
|
|
101
|
+
start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult>;
|
|
102
|
+
clear(): void;
|
|
103
|
+
protected wrapHandler(handler: () => void): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,MAAM;IACtB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACd;AAsCD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC7B,SAAS,E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E,cAAc,EAAE,MAAM,IAAI;IAI9D;;OAEG;IACU,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO5E,KAAK,IAAI,IAAI;IAQpB,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;CAMhD"}
|
package/dist/timer.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PromiseTimer = exports.Timer = exports.setLongTimeout = void 0;
|
|
8
|
+
const assert_1 = require("./assert");
|
|
9
|
+
const promises_1 = require("./promises");
|
|
10
|
+
const maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).
|
|
11
|
+
/**
|
|
12
|
+
* Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.
|
|
13
|
+
* Timeouts may not be exactly accurate due to browser implementations and the OS.
|
|
14
|
+
* https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate
|
|
15
|
+
* @param timeoutFn - Executed when the timeout expires
|
|
16
|
+
* @param timeoutMs - Duration of the timeout in milliseconds
|
|
17
|
+
* @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when
|
|
18
|
+
* timeoutMs greater than maxTimeout
|
|
19
|
+
* @returns The initial timeout
|
|
20
|
+
*/
|
|
21
|
+
function setLongTimeout(timeoutFn, timeoutMs, setTimeoutIdFn) {
|
|
22
|
+
// The setTimeout max is 24.8 days before looping occurs.
|
|
23
|
+
let timeoutId;
|
|
24
|
+
if (timeoutMs > maxSetTimeoutMs) {
|
|
25
|
+
const newTimeoutMs = timeoutMs - maxSetTimeoutMs;
|
|
26
|
+
timeoutId = setTimeout(() => setLongTimeout(timeoutFn, newTimeoutMs, setTimeoutIdFn), maxSetTimeoutMs);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
timeoutId = setTimeout(() => timeoutFn(), Math.max(timeoutMs, 0));
|
|
30
|
+
}
|
|
31
|
+
setTimeoutIdFn?.(timeoutId);
|
|
32
|
+
return timeoutId;
|
|
33
|
+
}
|
|
34
|
+
exports.setLongTimeout = setLongTimeout;
|
|
35
|
+
/**
|
|
36
|
+
* This class is a thin wrapper over setTimeout and clearTimeout which
|
|
37
|
+
* makes it simpler to keep track of recurring timeouts with the same
|
|
38
|
+
* or similar handlers and timeouts. This class supports long timeouts
|
|
39
|
+
* or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.
|
|
40
|
+
*/
|
|
41
|
+
class Timer {
|
|
42
|
+
constructor(defaultTimeout, defaultHandler, getCurrentTick = () => Date.now()) {
|
|
43
|
+
this.defaultTimeout = defaultTimeout;
|
|
44
|
+
this.defaultHandler = defaultHandler;
|
|
45
|
+
this.getCurrentTick = getCurrentTick;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns true if the timer is running.
|
|
49
|
+
*/
|
|
50
|
+
get hasTimer() {
|
|
51
|
+
return !!this.runningState;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Calls setTimeout and tracks the resulting timeout.
|
|
55
|
+
* @param ms - overrides default timeout in ms
|
|
56
|
+
* @param handler - overrides default handler
|
|
57
|
+
*/
|
|
58
|
+
start(ms = this.defaultTimeout, handler = this.defaultHandler) {
|
|
59
|
+
this.startCore(ms, handler, ms);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calls clearTimeout on the underlying timeout if running.
|
|
63
|
+
*/
|
|
64
|
+
clear() {
|
|
65
|
+
if (!this.runningState) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
clearTimeout(this.runningState.timeout);
|
|
69
|
+
this.runningState = undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Restarts the timer with the new handler and duration.
|
|
73
|
+
* If a new handler is passed, the original handler may
|
|
74
|
+
* never execute.
|
|
75
|
+
* This is a potentially more efficient way to clear and start
|
|
76
|
+
* a new timer.
|
|
77
|
+
* @param ms - overrides previous or default timeout in ms
|
|
78
|
+
* @param handler - overrides previous or default handler
|
|
79
|
+
*/
|
|
80
|
+
restart(ms, handler) {
|
|
81
|
+
if (!this.runningState) {
|
|
82
|
+
// If restart is called first, it behaves as a call to start
|
|
83
|
+
this.start(ms, handler);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const duration = ms ?? this.runningState.intendedDuration;
|
|
87
|
+
const handlerToUse = handler ?? this.runningState.restart?.handler ?? this.runningState.handler;
|
|
88
|
+
const remainingTime = this.calculateRemainingTime(this.runningState);
|
|
89
|
+
if (duration < remainingTime) {
|
|
90
|
+
// If remaining time exceeds restart duration, do a hard restart.
|
|
91
|
+
// The existing timeout time is too long.
|
|
92
|
+
this.start(duration, handlerToUse);
|
|
93
|
+
}
|
|
94
|
+
else if (duration === remainingTime) {
|
|
95
|
+
// The existing timeout time is perfect, just update handler and data.
|
|
96
|
+
this.runningState.handler = handlerToUse;
|
|
97
|
+
this.runningState.restart = undefined;
|
|
98
|
+
this.runningState.intendedDuration = duration;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// If restart duration exceeds remaining time, set restart info.
|
|
102
|
+
// Existing timeout will start a new timeout for remaining time.
|
|
103
|
+
this.runningState.restart = {
|
|
104
|
+
startTick: this.getCurrentTick(),
|
|
105
|
+
duration,
|
|
106
|
+
handler: handlerToUse,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
startCore(duration, handler, intendedDuration) {
|
|
112
|
+
this.clear();
|
|
113
|
+
this.runningState = {
|
|
114
|
+
startTick: this.getCurrentTick(),
|
|
115
|
+
duration,
|
|
116
|
+
intendedDuration,
|
|
117
|
+
handler,
|
|
118
|
+
timeout: setLongTimeout(() => this.handler(), duration, (timer) => {
|
|
119
|
+
if (this.runningState !== undefined) {
|
|
120
|
+
this.runningState.timeout = timer;
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
handler() {
|
|
126
|
+
(0, assert_1.assert)(!!this.runningState, 0x764 /* Running timer missing handler */);
|
|
127
|
+
const restart = this.runningState.restart;
|
|
128
|
+
if (restart !== undefined) {
|
|
129
|
+
// Restart with remaining time
|
|
130
|
+
const remainingTime = this.calculateRemainingTime(restart);
|
|
131
|
+
this.startCore(remainingTime, () => restart.handler(), restart.duration);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Run clear first, in case the handler decides to start again
|
|
135
|
+
const handler = this.runningState.handler;
|
|
136
|
+
this.clear();
|
|
137
|
+
handler();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
calculateRemainingTime(runningTimeout) {
|
|
141
|
+
const elapsedTime = this.getCurrentTick() - runningTimeout.startTick;
|
|
142
|
+
return runningTimeout.duration - elapsedTime;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Timer = Timer;
|
|
146
|
+
/**
|
|
147
|
+
* This class is a wrapper over setTimeout and clearTimeout which
|
|
148
|
+
* makes it simpler to keep track of recurring timeouts with the
|
|
149
|
+
* same handlers and timeouts, while also providing a promise that
|
|
150
|
+
* resolves when it times out.
|
|
151
|
+
*/
|
|
152
|
+
class PromiseTimer {
|
|
153
|
+
constructor(defaultTimeout, defaultHandler) {
|
|
154
|
+
this.timer = new Timer(defaultTimeout, () => this.wrapHandler(defaultHandler));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* {@inheritDoc Timer.hasTimer}
|
|
158
|
+
*/
|
|
159
|
+
get hasTimer() {
|
|
160
|
+
return this.timer.hasTimer;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* {@inheritDoc IPromiseTimer.start}
|
|
164
|
+
*/
|
|
165
|
+
async start(ms, handler) {
|
|
166
|
+
this.clear();
|
|
167
|
+
this.deferred = new promises_1.Deferred();
|
|
168
|
+
this.timer.start(ms, handler ? () => this.wrapHandler(handler) : undefined);
|
|
169
|
+
return this.deferred.promise;
|
|
170
|
+
}
|
|
171
|
+
clear() {
|
|
172
|
+
this.timer.clear();
|
|
173
|
+
if (this.deferred) {
|
|
174
|
+
this.deferred.resolve({ timerResult: "cancel" });
|
|
175
|
+
this.deferred = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
wrapHandler(handler) {
|
|
179
|
+
handler();
|
|
180
|
+
(0, assert_1.assert)(!!this.deferred, 0x765 /* Handler executed without deferred */);
|
|
181
|
+
this.deferred.resolve({ timerResult: "timeout" });
|
|
182
|
+
this.deferred = undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.PromiseTimer = PromiseTimer;
|
|
186
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qCAAkC;AAClC,yCAAsC;AAqDtC,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,0CAA0C;AAE9E;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAC7B,SAAqB,EACrB,SAAiB,EACjB,cAAmE;IAEnE,yDAAyD;IACzD,IAAI,SAAwC,CAAC;IAC7C,IAAI,SAAS,GAAG,eAAe,EAAE;QAChC,MAAM,YAAY,GAAG,SAAS,GAAG,eAAe,CAAC;QACjD,SAAS,GAAG,UAAU,CACrB,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,cAAc,CAAC,EAC7D,eAAe,CACf,CAAC;KACF;SAAM;QACN,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,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AAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;SAC1B;IACF,CAAC;IAES,WAAW,CAAC,OAAmB;QACxC,OAAO,EAAE,CAAC;QACV,IAAA,eAAM,EAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC3B,CAAC;CACD;AAvCD,oCAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"./assert\";\nimport { Deferred } from \"./promises\";\n\nexport interface ITimer {\n\t/**\n\t * True if timer is currently running\n\t */\n\treadonly hasTimer: boolean;\n\n\t/**\n\t * Starts the timer\n\t */\n\tstart(): void;\n\n\t/**\n\t * Cancels the timer if already running\n\t */\n\tclear(): void;\n}\n\ninterface ITimeout {\n\t/**\n\t * Tick that timeout was started.\n\t */\n\tstartTick: number;\n\n\t/**\n\t * Timeout duration in ms.\n\t */\n\tduration: number;\n\n\t/**\n\t * Handler to execute when timeout ends.\n\t */\n\thandler: () => void;\n}\n\ninterface IRunningTimerState extends ITimeout {\n\t/**\n\t * JavaScript Timeout object.\n\t */\n\ttimeout: ReturnType<typeof setTimeout>;\n\n\t/**\n\t * Intended duration in ms.\n\t */\n\tintendedDuration: number;\n\n\t/**\n\t * Intended restart timeout.\n\t */\n\trestart?: ITimeout;\n}\n\nconst maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).\n\n/**\n * Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.\n * Timeouts may not be exactly accurate due to browser implementations and the OS.\n * https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate\n * @param timeoutFn - Executed when the timeout expires\n * @param timeoutMs - Duration of the timeout in milliseconds\n * @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when\n * timeoutMs greater than maxTimeout\n * @returns The initial timeout\n */\nexport function setLongTimeout(\n\ttimeoutFn: () => void,\n\ttimeoutMs: number,\n\tsetTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void,\n): ReturnType<typeof setTimeout> {\n\t// The setTimeout max is 24.8 days before looping occurs.\n\tlet timeoutId: ReturnType<typeof setTimeout>;\n\tif (timeoutMs > maxSetTimeoutMs) {\n\t\tconst newTimeoutMs = timeoutMs - maxSetTimeoutMs;\n\t\ttimeoutId = setTimeout(\n\t\t\t() => setLongTimeout(timeoutFn, newTimeoutMs, setTimeoutIdFn),\n\t\t\tmaxSetTimeoutMs,\n\t\t);\n\t} else {\n\t\ttimeoutId = setTimeout(() => timeoutFn(), Math.max(timeoutMs, 0));\n\t}\n\n\tsetTimeoutIdFn?.(timeoutId);\n\treturn timeoutId;\n}\n\n/**\n * This class is a thin wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the same\n * or similar handlers and timeouts. This class supports long timeouts\n * or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.\n */\nexport class Timer implements ITimer {\n\t/**\n\t * Returns true if the timer is running.\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn !!this.runningState;\n\t}\n\n\tprivate runningState: IRunningTimerState | undefined;\n\n\tconstructor(\n\t\tprivate readonly defaultTimeout: number,\n\t\tprivate readonly defaultHandler: () => void,\n\t\tprivate readonly getCurrentTick: () => number = (): number => Date.now(),\n\t) {}\n\n\t/**\n\t * Calls setTimeout and tracks the resulting timeout.\n\t * @param ms - overrides default timeout in ms\n\t * @param handler - overrides default handler\n\t */\n\tpublic start(\n\t\tms: number = this.defaultTimeout,\n\t\thandler: () => void = this.defaultHandler,\n\t): void {\n\t\tthis.startCore(ms, handler, ms);\n\t}\n\n\t/**\n\t * Calls clearTimeout on the underlying timeout if running.\n\t */\n\tpublic clear(): void {\n\t\tif (!this.runningState) {\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(this.runningState.timeout);\n\t\tthis.runningState = undefined;\n\t}\n\n\t/**\n\t * Restarts the timer with the new handler and duration.\n\t * If a new handler is passed, the original handler may\n\t * never execute.\n\t * This is a potentially more efficient way to clear and start\n\t * a new timer.\n\t * @param ms - overrides previous or default timeout in ms\n\t * @param handler - overrides previous or default handler\n\t */\n\tpublic restart(ms?: number, handler?: () => void): void {\n\t\tif (!this.runningState) {\n\t\t\t// If restart is called first, it behaves as a call to start\n\t\t\tthis.start(ms, handler);\n\t\t} else {\n\t\t\tconst duration = ms ?? this.runningState.intendedDuration;\n\t\t\tconst handlerToUse =\n\t\t\t\thandler ?? this.runningState.restart?.handler ?? this.runningState.handler;\n\t\t\tconst remainingTime = this.calculateRemainingTime(this.runningState);\n\n\t\t\tif (duration < remainingTime) {\n\t\t\t\t// If remaining time exceeds restart duration, do a hard restart.\n\t\t\t\t// The existing timeout time is too long.\n\t\t\t\tthis.start(duration, handlerToUse);\n\t\t\t} else if (duration === remainingTime) {\n\t\t\t\t// The existing timeout time is perfect, just update handler and data.\n\t\t\t\tthis.runningState.handler = handlerToUse;\n\t\t\t\tthis.runningState.restart = undefined;\n\t\t\t\tthis.runningState.intendedDuration = duration;\n\t\t\t} else {\n\t\t\t\t// If restart duration exceeds remaining time, set restart info.\n\t\t\t\t// Existing timeout will start a new timeout for remaining time.\n\t\t\t\tthis.runningState.restart = {\n\t\t\t\t\tstartTick: this.getCurrentTick(),\n\t\t\t\t\tduration,\n\t\t\t\t\thandler: handlerToUse,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate startCore(duration: number, handler: () => void, intendedDuration: number): void {\n\t\tthis.clear();\n\t\tthis.runningState = {\n\t\t\tstartTick: this.getCurrentTick(),\n\t\t\tduration,\n\t\t\tintendedDuration,\n\t\t\thandler,\n\t\t\ttimeout: setLongTimeout(\n\t\t\t\t() => this.handler(),\n\t\t\t\tduration,\n\t\t\t\t(timer: number) => {\n\t\t\t\t\tif (this.runningState !== undefined) {\n\t\t\t\t\t\tthis.runningState.timeout = timer;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t};\n\t}\n\n\tprivate handler(): void {\n\t\tassert(!!this.runningState, 0x764 /* Running timer missing handler */);\n\t\tconst restart = this.runningState.restart;\n\t\tif (restart !== undefined) {\n\t\t\t// Restart with remaining time\n\t\t\tconst remainingTime = this.calculateRemainingTime(restart);\n\t\t\tthis.startCore(remainingTime, () => restart.handler(), restart.duration);\n\t\t} else {\n\t\t\t// Run clear first, in case the handler decides to start again\n\t\t\tconst handler = this.runningState.handler;\n\t\t\tthis.clear();\n\t\t\thandler();\n\t\t}\n\t}\n\n\tprivate calculateRemainingTime(runningTimeout: ITimeout): number {\n\t\tconst elapsedTime = this.getCurrentTick() - runningTimeout.startTick;\n\t\treturn runningTimeout.duration - elapsedTime;\n\t}\n}\n\nexport interface IPromiseTimerResult {\n\ttimerResult: \"timeout\" | \"cancel\";\n}\n\n/**\n * Timer which offers a promise that fulfills when the timer\n * completes.\n */\nexport interface IPromiseTimer extends ITimer {\n\t/**\n\t * Starts the timer and returns a promise that\n\t * resolves when the timer times out or is canceled.\n\t */\n\tstart(): Promise<IPromiseTimerResult>;\n}\n\n/**\n * This class is a wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the\n * same handlers and timeouts, while also providing a promise that\n * resolves when it times out.\n */\nexport class PromiseTimer implements IPromiseTimer {\n\tprivate deferred?: Deferred<IPromiseTimerResult>;\n\tprivate readonly timer: Timer;\n\n\t/**\n\t * {@inheritDoc Timer.hasTimer}\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn this.timer.hasTimer;\n\t}\n\n\tconstructor(defaultTimeout: number, defaultHandler: () => void) {\n\t\tthis.timer = new Timer(defaultTimeout, () => this.wrapHandler(defaultHandler));\n\t}\n\n\t/**\n\t * {@inheritDoc IPromiseTimer.start}\n\t */\n\tpublic async start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult> {\n\t\tthis.clear();\n\t\tthis.deferred = new Deferred<IPromiseTimerResult>();\n\t\tthis.timer.start(ms, handler ? (): void => this.wrapHandler(handler) : undefined);\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.timer.clear();\n\t\tif (this.deferred) {\n\t\t\tthis.deferred.resolve({ timerResult: \"cancel\" });\n\t\t\tthis.deferred = undefined;\n\t\t}\n\t}\n\n\tprotected wrapHandler(handler: () => void): void {\n\t\thandler();\n\t\tassert(!!this.deferred, 0x765 /* Handler executed without deferred */);\n\t\tthis.deferred.resolve({ timerResult: \"timeout\" });\n\t\tthis.deferred = undefined;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* This function can be used to assert at compile time that a given value has type never.
|
|
7
|
+
* One common usage is in the default case of a switch block,
|
|
8
|
+
* to ensure that all cases are explicitly handled.
|
|
9
|
+
*
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const bool: true | false = ...;
|
|
13
|
+
* switch(bool) {
|
|
14
|
+
* case true: {...}
|
|
15
|
+
* case false: {...}
|
|
16
|
+
* default: unreachableCase(bool);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function unreachableCase(_: never, message?: string): never;
|
|
21
|
+
//# sourceMappingURL=unreachable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unreachable.d.ts","sourceRoot":"","sources":["../src/unreachable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,SAAqB,GAAG,KAAK,CAE7E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.unreachableCase = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* This function can be used to assert at compile time that a given value has type never.
|
|
10
|
+
* One common usage is in the default case of a switch block,
|
|
11
|
+
* to ensure that all cases are explicitly handled.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const bool: true | false = ...;
|
|
16
|
+
* switch(bool) {
|
|
17
|
+
* case true: {...}
|
|
18
|
+
* case false: {...}
|
|
19
|
+
* default: unreachableCase(bool);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function unreachableCase(_, message = "Unreachable Case") {
|
|
24
|
+
throw new Error(message);
|
|
25
|
+
}
|
|
26
|
+
exports.unreachableCase = unreachableCase;
|
|
27
|
+
//# sourceMappingURL=unreachable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unreachable.js","sourceRoot":"","sources":["../src/unreachable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe,CAAC,CAAQ,EAAE,OAAO,GAAG,kBAAkB;IACrE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,0CAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This function can be used to assert at compile time that a given value has type never.\n * One common usage is in the default case of a switch block,\n * to ensure that all cases are explicitly handled.\n *\n * Example:\n * ```typescript\n * const bool: true | false = ...;\n * switch(bool) {\n * case true: {...}\n * case false: {...}\n * default: unreachableCase(bool);\n * }\n * ```\n */\nexport function unreachableCase(_: never, message = \"Unreachable Case\"): never {\n\tthrow new Error(message);\n}\n"]}
|
package/lib/assert.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A browser friendly assert library.
|
|
7
|
+
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
|
|
8
|
+
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
|
|
9
|
+
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
|
|
10
|
+
* @param message - The message to include in the error when the condition does not hold.
|
|
11
|
+
* A number should not be specified manually: use a string.
|
|
12
|
+
* Before a release, policy-check should be run, which will convert any asserts still using strings to
|
|
13
|
+
* use numbered error codes instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assert(condition: boolean, message: string | number): asserts condition;
|
|
16
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,CAMtF"}
|
package/lib/assert.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A browser friendly assert library.
|
|
7
|
+
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
|
|
8
|
+
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
|
|
9
|
+
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
|
|
10
|
+
* @param message - The message to include in the error when the condition does not hold.
|
|
11
|
+
* A number should not be specified manually: use a string.
|
|
12
|
+
* Before a release, policy-check should be run, which will convert any asserts still using strings to
|
|
13
|
+
* use numbered error codes instead.
|
|
14
|
+
*/
|
|
15
|
+
export function assert(condition, message) {
|
|
16
|
+
if (!condition) {
|
|
17
|
+
throw new Error(typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CAAC,SAAkB,EAAE,OAAwB;IAClE,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,KAAK,CACd,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CACpF,CAAC;KACF;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A browser friendly assert library.\n * Use this instead of the 'assert' package, which has a big impact on bundle sizes.\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n */\nexport function assert(condition: boolean, message: string | number): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(\n\t\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message,\n\t\t);\n\t}\n}\n"]}
|
package/lib/delay.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns a promise that resolves after `timeMs`.
|
|
7
|
+
* @param timeMs - Time in milliseconds to wait.
|
|
8
|
+
*/
|
|
9
|
+
export declare const delay: (timeMs: number) => Promise<void>;
|
|
10
|
+
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,KAAK,WAAkB,MAAM,KAAG,QAAQ,IAAI,CACK,CAAC"}
|
package/lib/delay.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns a promise that resolves after `timeMs`.
|
|
7
|
+
* @param timeMs - Time in milliseconds to wait.
|
|
8
|
+
*/
|
|
9
|
+
export const delay = async (timeMs) => new Promise((resolve) => setTimeout(() => resolve(), timeMs));
|
|
10
|
+
//# sourceMappingURL=delay.js.map
|
package/lib/delay.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE,CAC5D,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Returns a promise that resolves after `timeMs`.\n * @param timeMs - Time in milliseconds to wait.\n */\nexport const delay = async (timeMs: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(() => resolve(), timeMs));\n"]}
|
package/lib/heap.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Interface for a comparer.
|
|
7
|
+
*/
|
|
8
|
+
export interface IComparer<T> {
|
|
9
|
+
/**
|
|
10
|
+
* The minimum value of type T.
|
|
11
|
+
*/
|
|
12
|
+
min: T;
|
|
13
|
+
/**
|
|
14
|
+
* Compare the two value
|
|
15
|
+
*
|
|
16
|
+
* @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise
|
|
17
|
+
*/
|
|
18
|
+
compare(a: T, b: T): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A comparer for numbers.
|
|
22
|
+
*/
|
|
23
|
+
export declare const NumberComparer: IComparer<number>;
|
|
24
|
+
/**
|
|
25
|
+
* Interface to a node in {@link Heap}.
|
|
26
|
+
*/
|
|
27
|
+
export interface IHeapNode<T> {
|
|
28
|
+
value: T;
|
|
29
|
+
position: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
|
|
33
|
+
*/
|
|
34
|
+
export declare class Heap<T> {
|
|
35
|
+
comp: IComparer<T>;
|
|
36
|
+
private L;
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of `Heap` with comparer.
|
|
39
|
+
* @param comp - A comparer that specify how elements are ordered.
|
|
40
|
+
*/
|
|
41
|
+
constructor(comp: IComparer<T>);
|
|
42
|
+
/**
|
|
43
|
+
* Return the smallest element in the heap as determined by the order of the comparer
|
|
44
|
+
*
|
|
45
|
+
* @returns Heap node containing the smallest element
|
|
46
|
+
*/
|
|
47
|
+
peek(): IHeapNode<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Get and remove the smallest element in the heap as determined by the order of the comparer
|
|
50
|
+
*
|
|
51
|
+
* @returns The smallest value in the heap
|
|
52
|
+
*/
|
|
53
|
+
get(): T;
|
|
54
|
+
/**
|
|
55
|
+
* Add a value to the heap
|
|
56
|
+
*
|
|
57
|
+
* @param x - value to add
|
|
58
|
+
* @returns The heap node that contains the value
|
|
59
|
+
*/
|
|
60
|
+
add(x: T): IHeapNode<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Allows for the Heap to be updated after a node's value changes.
|
|
63
|
+
*/
|
|
64
|
+
update(node: IHeapNode<T>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Removes the given node from the heap.
|
|
67
|
+
*
|
|
68
|
+
* @param node - The node to remove from the heap.
|
|
69
|
+
*/
|
|
70
|
+
remove(node: IHeapNode<T>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get the number of elements in the Heap.
|
|
73
|
+
*
|
|
74
|
+
* @returns The number of elements in the Heap.
|
|
75
|
+
*/
|
|
76
|
+
count(): number;
|
|
77
|
+
private fixup;
|
|
78
|
+
private isGreaterThanParent;
|
|
79
|
+
private fixdown;
|
|
80
|
+
private swap;
|
|
81
|
+
}
|
|
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