Skip to content

Commit

Permalink
[interval] Fix panic in empty tree Size() method (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Dubský authored May 16, 2022
1 parent ecd8f7d commit 7fb5054
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions interval/itree.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ func (n *node[I, V]) findSmallest() *node[I, V] {
}

func (n *node[I, V]) size() int {
s := 1
if n.left != nil {
s += n.left.size()
}
if n.right != nil {
s += n.right.size()
if n == nil {
return 0
}

s := 1
s += n.left.size()
s += n.right.size()

return s
}

0 comments on commit 7fb5054

Please sign in to comment.