Skip to content

Commit 4fb26ee

Browse files
committed
Fixes ReferenceError: Cannot access 'SimplePriorityQueue' before initialization.
1 parent 55c2d4d commit 4fb26ee

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

src/vs/editor/contrib/inlineCompletions/test/timeTravelScheduler.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,60 @@
66
import { Emitter, Event } from 'vs/base/common/event';
77
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
88

9+
interface PriorityQueue<T> {
10+
length: number;
11+
add(value: T): void;
12+
remove(value: T): void;
13+
14+
removeMin(): T | undefined;
15+
toSortedArray(): T[];
16+
}
17+
18+
class SimplePriorityQueue<T> implements PriorityQueue<T> {
19+
private isSorted = false;
20+
private items: T[];
21+
22+
constructor(items: T[], private readonly compare: (a: T, b: T) => number) {
23+
this.items = items;
24+
}
25+
26+
get length(): number {
27+
return this.items.length;
28+
}
29+
30+
add(value: T): void {
31+
this.items.push(value);
32+
this.isSorted = false;
33+
}
34+
35+
remove(value: T): void {
36+
this.items.splice(this.items.indexOf(value), 1);
37+
this.isSorted = false;
38+
}
39+
40+
removeMin(): T | undefined {
41+
this.ensureSorted();
42+
return this.items.shift();
43+
}
44+
45+
getMin(): T | undefined {
46+
this.ensureSorted();
47+
return this.items[0];
48+
}
49+
50+
toSortedArray(): T[] {
51+
this.ensureSorted();
52+
return [...this.items];
53+
}
54+
55+
private ensureSorted() {
56+
if (!this.isSorted) {
57+
this.items.sort(this.compare);
58+
this.isSorted = true;
59+
}
60+
}
61+
}
62+
963
export type TimeOffset = number;
1064

1165
export interface Scheduler {
@@ -326,57 +380,3 @@ function createDateClass(scheduler: Scheduler): DateConstructor {
326380

327381
return SchedulerDate as any;
328382
}
329-
330-
interface PriorityQueue<T> {
331-
length: number;
332-
add(value: T): void;
333-
remove(value: T): void;
334-
335-
removeMin(): T | undefined;
336-
toSortedArray(): T[];
337-
}
338-
339-
class SimplePriorityQueue<T> implements PriorityQueue<T> {
340-
private isSorted = false;
341-
private items: T[];
342-
343-
constructor(items: T[], private readonly compare: (a: T, b: T) => number) {
344-
this.items = items;
345-
}
346-
347-
get length(): number {
348-
return this.items.length;
349-
}
350-
351-
add(value: T): void {
352-
this.items.push(value);
353-
this.isSorted = false;
354-
}
355-
356-
remove(value: T): void {
357-
this.items.splice(this.items.indexOf(value), 1);
358-
this.isSorted = false;
359-
}
360-
361-
removeMin(): T | undefined {
362-
this.ensureSorted();
363-
return this.items.shift();
364-
}
365-
366-
getMin(): T | undefined {
367-
this.ensureSorted();
368-
return this.items[0];
369-
}
370-
371-
toSortedArray(): T[] {
372-
this.ensureSorted();
373-
return [...this.items];
374-
}
375-
376-
private ensureSorted() {
377-
if (!this.isSorted) {
378-
this.items.sort(this.compare);
379-
this.isSorted = true;
380-
}
381-
}
382-
}

0 commit comments

Comments
 (0)