···291291 return nil
292292}
293293294294+func (n *Node) walk(f func(key []byte, val cid.Cid) error) error {
295295+ if n == nil {
296296+ return fmt.Errorf("nil tree pointer")
297297+ }
298298+ for _, e := range n.Entries {
299299+ if e.IsValue() {
300300+ if err := f(e.Key, *e.Value); err != nil {
301301+ return err
302302+ }
303303+ }
304304+ if e.Child != nil {
305305+ if err := e.Child.walk(f); err != nil {
306306+ return err
307307+ }
308308+ }
309309+ }
310310+ return nil
311311+}
312312+294313// Reads the value (CID) corresponding to the key. If key is not in the tree, returns (nil, nil).
295314//
296315// n: Node at top of sub-tree to operate on. Must not be nil.
+5
atproto/repo/mst/tree.go
···7979 return t.Root.getCID(key, -1)
8080}
81818282+// Walks the Tree, invoking the callback function on each key/value pair.
8383+func (t *Tree) Walk(f func(key []byte, val cid.Cid) error) error {
8484+ return t.Root.walk(f)
8585+}
8686+8287// Creates a new Tree by loading key/value pairs from a map.
8388func LoadTreeFromMap(m map[string]cid.Cid) (*Tree, error) {
8489 if m == nil {