-
Notifications
You must be signed in to change notification settings - Fork 36
/
gather-visitor.ts
48 lines (41 loc) · 1.28 KB
/
gather-visitor.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
import * as db from '../db/mod';
import {Hash, isTempHash} from '../hash';
import type * as dag from '../dag/mod';
import type * as btree from '../btree/mod';
import type {HashRefType} from '../db/hash-ref-type';
import type {Meta} from '../db/commit';
export class GatherVisitor extends db.Visitor {
private readonly _gatheredChunks: Map<Hash, dag.Chunk> = new Map();
get gatheredChunks(): ReadonlyMap<Hash, dag.Chunk> {
return this._gatheredChunks;
}
override async visitCommit(
h: Hash,
hashRefType?: HashRefType,
): Promise<void> {
if (!isTempHash(h)) {
// Not a temp hash, no need to visit anything else.
return;
}
return super.visitCommit(h, hashRefType);
}
override async visitCommitChunk(
chunk: dag.Chunk<db.CommitData<Meta>>,
): Promise<void> {
this._gatheredChunks.set(chunk.hash, chunk);
return super.visitCommitChunk(chunk);
}
override async visitBTreeNode(h: Hash): Promise<void> {
if (!isTempHash(h)) {
// Not a temp hash, no need to visit anything else.
return;
}
return super.visitBTreeNode(h);
}
override async visitBTreeNodeChunk(
chunk: dag.Chunk<btree.Node>,
): Promise<void> {
this._gatheredChunks.set(chunk.hash, chunk);
return super.visitBTreeNodeChunk(chunk);
}
}