-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
I see that TreeSet is
type Set struct {
tree *rbt.Tree
}and rbt.Tree has Left() and Right() to get the min and max:
gods/trees/redblacktree/redblacktree.go
Lines 196 to 216 in 14f7142
| // 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.
ksw2000
Metadata
Metadata
Assignees
Labels
No labels