Skip to content

Commit ad85f92

Browse files
committed
expression: implement PartialEq/Eq for trees
This is really useful for testing.
1 parent b0508d8 commit ad85f92

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/expression/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ pub struct Tree<'a> {
4343
/// The comma-separated contents of the `(...)`, if any
4444
pub args: Vec<Tree<'a>>,
4545
}
46+
47+
impl PartialEq for Tree<'_> {
48+
fn eq(&self, other: &Self) -> bool {
49+
let mut stack = vec![(self, other)];
50+
while let Some((me, you)) = stack.pop() {
51+
if me.name != you.name || me.args.len() != you.args.len() {
52+
return false;
53+
}
54+
stack.extend(me.args.iter().zip(you.args.iter()));
55+
}
56+
true
57+
}
58+
}
59+
impl Eq for Tree<'_> {}
4660
// or_b(pk(A),pk(B))
4761
//
4862
// A = musig(musig(B,C),D,E)

0 commit comments

Comments
 (0)