-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add higher/lower search functions in gb_trees and gb_sets #7745
Conversation
CT Test Results 2 files 92 suites 35m 17s ⏱️ Results for commit 1595acf. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
I will add java tailmap/submap/tailset/subset equivalent later in a separate PR |
Do we want to be able to do |
Hi @mikpe, is there any update on this? I cannot proceed with out deciding the behavior of gb_sets:prev(element(2, gb_sets:next(Iterator))). Thanks! |
@zzydxm This is stalled until we've discussed things internally, we'll get back to you as soon as we can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing this internally, we'd like the following:
To match the maps
module, we'd like reverse iteration to be handled by an order argument to iterator/1
and iterator_from/2
instead of having explicit forward and backward functions. next/1
would be used for both directions with the order depending on the iterator.
We would also prefer the names smaller
and larger
for <
and >
, to match smallest/1
and largest/1
.
>=
and =<
may have some uses but they can be trivially implemented by composing is_element/2
and smaller/2
or larger/2
in user code. They can always be added later if there is a need.
Sure I will rename these functions and fix the issues. |
I just realized that if we only have next but not prev, then reversed iterator need to return some datatype different with iterator/1, like {reverse, iter(Element)}. Otherwise it is either more expensive to create the iterator, or we cannot distinguish whether it is forward or backward iter. |
Updated the commit, I kept type spec unchanged because doing suggest way will see this error:
|
703bbf6
to
365bb62
Compare
Yes.
Yep.
How about something like...? -spec smaller(SmallerThan, Set) -> none | {found, SmallerElement} when
SmallerThan :: term(),
SmallerElement :: term(),
Set :: set(). |
Sure I can do that, but it is quite different with other typings in the module. Shall we modify them together in a later commit? |
Sure, later commit is fine. |
Hi! This line needs to be updated (and for trees too?), the property tests fail to compile right now. |
Sorry property test had some issue on my laptop so were skipped. It should be fixed now. |
Merged, thanks for the PR! |
Provide some common operations that is available for BSTs.
API follows java TreeSet / TreeMap