UNPKG

2.61 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BaseTrie } from '..';
3import { FoundNodeFunction } from '../baseTrie';
4import { PrioritizedTaskExecutor } from '../prioritizedTaskExecutor';
5import { BranchNode, Nibbles, TrieNode } from '../trieNode';
6/**
7 * WalkController is an interface to control how the trie is being traversed.
8 */
9export declare class WalkController {
10 readonly onNode: FoundNodeFunction;
11 readonly taskExecutor: PrioritizedTaskExecutor;
12 readonly trie: BaseTrie;
13 private resolve;
14 private reject;
15 /**
16 * Creates a new WalkController
17 * @param onNode - The `FoundNodeFunction` to call if a node is found.
18 * @param trie - The `Trie` to walk on.
19 * @param poolSize - The size of the task queue.
20 */
21 private constructor();
22 /**
23 * Async function to create and start a new walk over a trie.
24 * @param onNode - The `FoundNodeFunction to call if a node is found.
25 * @param trie - The trie to walk on.
26 * @param root - The root key to walk on.
27 * @param poolSize - Task execution pool size to prevent OOM errors. Defaults to 500.
28 */
29 static newWalk(onNode: FoundNodeFunction, trie: BaseTrie, root: Buffer, poolSize?: number): Promise<void>;
30 private startWalk;
31 /**
32 * Run all children of a node. Priority of these nodes are the key length of the children.
33 * @param node - Node to get all children of and call onNode on.
34 * @param key - The current `key` which would yield the `node` when trying to get this node with a `get` operation.
35 */
36 allChildren(node: TrieNode, key?: Nibbles): void;
37 /**
38 * Push a node to the queue. If the queue has places left for tasks, the node is executed immediately, otherwise it is queued.
39 * @param nodeRef - Push a node reference to the event queue. This reference is a 32-byte keccak hash of the value corresponding to the `key`.
40 * @param key - The current key.
41 * @param priority - Optional priority, defaults to key length
42 */
43 pushNodeToQueue(nodeRef: Buffer, key?: Nibbles, priority?: number): void;
44 /**
45 * Push a branch of a certain BranchNode to the event queue.
46 * @param node - The node to select a branch on. Should be a BranchNode.
47 * @param key - The current key which leads to the corresponding node.
48 * @param childIndex - The child index to add to the event queue.
49 * @param priority - Optional priority of the event, defaults to the total key length.
50 */
51 onlyBranchIndex(node: BranchNode, key: Nibbles | undefined, childIndex: number, priority?: number): void;
52 private processNode;
53}