Skip to content

Request: add methods Min() and Max() to TreeSet #259

Open
@miparnisari

Description

@miparnisari

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions