From 84de749c8c8a54c11096e57eb8f9bc1d51cfd741 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Wed, 30 Aug 2023 11:53:31 -0400 Subject: [PATCH] merkletree: add CollapsedTree.Equal --- merkletree/collapsed_tree.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/merkletree/collapsed_tree.go b/merkletree/collapsed_tree.go index f0966b8..a42b9e1 100644 --- a/merkletree/collapsed_tree.go +++ b/merkletree/collapsed_tree.go @@ -13,6 +13,7 @@ import ( "encoding/json" "fmt" "math/bits" + "golang.org/x/exp/slices" ) type CollapsedTree struct { @@ -41,6 +42,10 @@ func CloneCollapsedTree(source *CollapsedTree) *CollapsedTree { return &CollapsedTree{nodes: nodes, size: source.size} } +func (tree CollapsedTree) Equal(other CollapsedTree) bool { + return tree.size == other.size && slices.Equal(tree.nodes, other.nodes) +} + func (tree *CollapsedTree) Add(hash Hash) { tree.nodes = append(tree.nodes, hash) tree.size++