Skip to main content

clvm_fuzzing/
pick_node.rs

1use clvmr::{Allocator, NodePtr, SExp};
2use std::collections::HashSet;
3
4pub fn pick_node(a: &Allocator, root: NodePtr, mut node_idx: i32) -> NodePtr {
5    let mut stack = vec![root];
6    let mut seen_node = HashSet::<NodePtr>::new();
7
8    while let Some(node) = stack.pop() {
9        if node_idx == 0 {
10            return node;
11        }
12        if !seen_node.insert(node) {
13            continue;
14        }
15        node_idx -= 1;
16        if let SExp::Pair(left, right) = a.sexp(node) {
17            stack.push(left);
18            stack.push(right);
19        }
20    }
21    NodePtr::NIL
22}