introduce the Comparable trait for btree internals #144506
Open
+75
−27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Apologies if this is not the way to do things. I have a usecase for the
Comparable
trait thatK: Borrow, Q: Ord
does not satisfy. See my comment.It was previously mentioned regarding the
Equivalent
trait to start an ACP if someone has a compelling use-case, although I don't have the energy to do that right now. However I thought I would at least introduce the trait as an implementation detail, just to get the ball rolling if anyone else does have more time/motivation than myself.This does not introduce any changes to public API, nor should it have any impact to performance or behaviour. The one thing of note is that I've used a flipped version of the trait.
The one annoying thing is that we still need
Q: Ord
in order to provide the panic messages for bad usage. One could likely address this but it would move the branch inside the search loop which might impact performance. Another approach is to move the condition out, but that won't help if we want the same helpful panic condition in any potential exposed API. Note that this check is not needed for memory safety (as we already have to deal with invalid Ord impls) so maybe such a check is not really that necessary. The alternative is we accept thisQ: Ord
bound as not a significant limitation. I don't really know/care - this is not an ACP so there's not really any API to discuss :)