I see that TreeSet is
type Set struct {
tree *rbt.Tree
}
and rbt.Tree has Left() and Right() to get the min and max:
|
// Left returns the left-most (min) node or nil if tree is empty. |
|
func (tree *Tree[K, V]) Left() *Node[K, V] { |
|
var parent *Node[K, V] |
|
current := tree.Root |
|
for current != nil { |
|
parent = current |
|
current = current.Left |
|
} |
|
return parent |
|
} |
|
|
|
// Right returns the right-most (max) node or nil if tree is empty. |
|
func (tree *Tree[K, V]) Right() *Node[K, V] { |
|
var parent *Node[K, V] |
|
current := tree.Root |
|
for current != nil { |
|
parent = current |
|
current = current.Right |
|
} |
|
return parent |
|
} |
Can we expose those methods in the TreeSet too? The workaround of calling arr := treeset.Values() and then grabbing arr[0] and arr[len(arr)-1] seems very wasteful.
I see that TreeSet is
and
rbt.TreehasLeft()andRight()to get the min and max:gods/trees/redblacktree/redblacktree.go
Lines 196 to 216 in 14f7142
Can we expose those methods in the TreeSet too? The workaround of calling
arr := treeset.Values()and then grabbingarr[0]andarr[len(arr)-1]seems very wasteful.