1use clvmr::{Allocator, NodePtr, SExp};
2use std::collections::HashSet;
3
4pub fn node_eq(allocator: &Allocator, lhs: NodePtr, rhs: NodePtr) -> bool {
6 let mut stack = vec![(lhs, rhs)];
7 let mut visited = HashSet::<NodePtr>::new();
8
9 while let Some((l, r)) = stack.pop() {
10 match (allocator.sexp(l), allocator.sexp(r)) {
11 (SExp::Pair(ll, lr), SExp::Pair(rl, rr)) => {
12 if !visited.insert(l) {
13 continue;
14 }
15 stack.push((lr, rr));
16 stack.push((ll, rl));
17 }
18 (SExp::Atom, SExp::Atom) => {
19 if !allocator.atom_eq(l, r) {
20 return false;
21 }
22 }
23 _ => {
24 return false;
25 }
26 }
27 }
28 true
29}