Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
miparnisari opened this issue Jul 12, 2024 · 1 comment · May be fixed by #260
Open

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

miparnisari opened this issue Jul 12, 2024 · 1 comment · May be fixed by #260

Comments

@miparnisari
Copy link

miparnisari commented Jul 12, 2024

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.

@yossev yossev linked a pull request Jul 20, 2024 that will close this issue
@yossev
Copy link

yossev commented Jul 20, 2024

Should be there now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants