-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathQueue.ts
More file actions
36 lines (30 loc) · 847 Bytes
/
Queue.ts
File metadata and controls
36 lines (30 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Implication } from './Types.js'
import ImplicationIndex from './ImplicationIndex.js'
export default class Queue<
TheoremId,
PropertyId,
Theorem extends Implication<TheoremId, PropertyId>,
> {
private index: ImplicationIndex<TheoremId, PropertyId, Theorem>
private queue: Set<Theorem>
constructor(index: ImplicationIndex<TheoremId, PropertyId, Theorem>) {
this.index = index
this.queue = new Set(index.all)
}
mark(property: PropertyId): void {
this.index.withProperty(property).forEach(i => this.queue.add(i))
}
addAll(theorems: Theorem[]): void {
for (const t of theorems) {
this.queue.add(t)
}
}
shift(): Theorem | undefined {
const result = this.queue.values().next()
if (result.done) {
return
}
this.queue.delete(result.value)
return result.value
}
}