merkletree: add CollapsedTree.Equal

This commit is contained in:
Andrew Ayer 2023-08-30 11:53:31 -04:00
parent eb16a10c2e
commit 84de749c8c
1 changed files with 5 additions and 0 deletions

View File

@ -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++