Skip to content

Commit

Permalink
Merge pull request #4 from lestrrat-go/fix-ancestors
Browse files Browse the repository at this point in the history
reverse the return value of Ancestors()
  • Loading branch information
lestrrat authored Oct 16, 2024
2 parents 5e6058b + 3e0866c commit ed6f12c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type Node[K cmp.Ordered, V any] interface {
Parent() Node[K, V]

// Ancestors returns a sequence of ancestors of this node.
// The first element is the root element, progressing all the way
// up to the parent of this node.
// The first element is the current element, progressing all the way
// back to the root element ("")
Ancestors() iter.Seq[Node[K, V]]
}

Expand Down Expand Up @@ -271,13 +271,13 @@ func (n *node[K, V]) Ancestors() iter.Seq[Node[K, V]] {

return func(yield func(Node[K, V]) bool) {
for len(ancestors) > 0 {
cur := ancestors[len(ancestors)-1]
cur := ancestors[0]
if cur != nil && !cur.isRoot {
if !yield(cur) {
break
}
}
ancestors = ancestors[:len(ancestors)-1]
ancestors = ancestors[1:]
}
}
}
Expand Down

0 comments on commit ed6f12c

Please sign in to comment.