Skip to content

trees: implement more TreeSet helper methods#42

Merged
shoenig merged 3 commits intohashicorp:mainfrom
shoenig:treeset-funcs
Apr 27, 2023
Merged

trees: implement more TreeSet helper methods#42
shoenig merged 3 commits intohashicorp:mainfrom
shoenig:treeset-funcs

Conversation

@shoenig
Copy link
Copy Markdown
Contributor

@shoenig shoenig commented Apr 26, 2023

This PR implements the following helper methods on TreeSet

  • Below - set of elements strictly below a value
  • BelowEqual - set of elements below or equal to a value
  • FirstBelow - first element strictly below a value (if exists)
  • FirstBelowEqual - first element below or equal to a value (if exists)
  • Above - set of elements strictly above a value
  • AboveEqual - set of elements above or equal to a value
  • FirstAbove - first element strictly above a value
  • FirstAboveEqual - first element strictly

Closes #37
Closes #38

shoenig added 3 commits April 25, 2023 13:16
This PR introduces Above, AboveEqual, Below, and BelowEqual functions
on TreeSet for creating subsets of elements that match the descriptive
function name.
This PR adds support for TreeSet methods

FirstAbove - the first element strictly above a value
FirstAboveEqual - the first element above or equal to a value
FirstBelow - the first element strictly below a value
FirstBelowEqual - the first element below or equal to a value
@shoenig shoenig requested review from jrasell and lgfa29 April 26, 2023 19:50
Copy link
Copy Markdown

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Minor doc comment, but not a big deal.

Comment thread README.md
- TopK (`TreeSet` only)
- BottomK (`TreeSet` only)

TreeSet helper methods
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these are the methods only available for TreeSet? Being nested under the # TreeSet title makes it seem like everything only applies to TreeSet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that's correct - this set of helpers depend on the data being ordered for there to be an efficient implementation. Since Set/HashSet don't have ordered data, we don't implement these for those.

@shoenig shoenig merged commit 0e21b54 into hashicorp:main Apr 27, 2023
@vanodevium
Copy link
Copy Markdown
Contributor

@shoenig
Please make release. I wanna update my mod file in classic way, by @latest

@shoenig
Copy link
Copy Markdown
Contributor Author

shoenig commented Apr 27, 2023

Hi @vanodevium, I just created a release for v0.1.12

BTW in case you are still interested in contributing, I also filed #45, #46, #47 for creating examples compatible with Go doc, which might be a nice place to get started

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 this pull request may close these issues.

LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual

3 participants