hashicorp / go-set

The go-set package provides generic Set implementations for Go, including HashSet for types with a Hash() function and TreeSet for orderable data
Mozilla Public License 2.0
118 stars 8 forks source link

LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual #37

Closed vanodevium closed 1 year ago

vanodevium commented 1 year ago

Do you have any plans to make such methods for TreeSet? Because very often such methods are necessary.

If not, please provide a code example of the fastest way to implement such functionality.

For example: I have treeset (10, 20, 30, 40, 50) and when I call orderedSet.LessThan(30) I will retrieve 20 , but for orderedSet.GreaterThan(30) I will retrieve 40

Thanx!

shoenig commented 1 year ago

Hi @vanodevium! Indeed such methods would be very useful to add, it just wasn't something we needed right away. I can probably find time to work on this in the next few weeks, if you or someone else doesn't want to work on it first.

The implementation(s) would be quite similar to the TopK/BottomK methods, but with slightly adjusted logic.

vanodevium commented 1 year ago

@shoenig

Thank you very much for your response!

I already tried to do it, but my knowledge was not enough.

I will wait when you have free time.