-
Notifications
You must be signed in to change notification settings - Fork 137
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 to SetOfVec at lexicographically correct position #1060
Conversation
Perhaps we need to better document/advertise this, but there's a That seems a lot more efficient than your proposed change. |
Yeah, damn, I overlooked that. But this doesn't really help, if you get a |
@tarcieri A test in the x509 crate tests the order of adding to |
CI should be patched to use the in-repo I agree the existing method's ergonomics aren't great, but I'm a bit worried changing it like this creates an API which though convenient to use has some pathological corner cases performance-wise. If the primary use case is adding an item to an existing set, does that really make sense via in-place mutation, or would you normally pub fn append(&self, new_elem: T) -> Result<Self> ...which can be constructed by moving the inner |
Also Edit: this approach could also make for a general |
Went ahead and impl'd |
I have an alternative proposal in #1067. It also avoids making breaking changes. |
|
Re: |
Motivation
When adding an element to a
SetOfVec
, lexicographical ordering must be respected. This is required, when the content is DER encoded. Current solution is to forbid adding elements, that are not greater than all exisiting elements.This PR adds new elements in the correct position, which makes it possible to add elements to existing
SetOfVec
s at any time in any order.Overhead?
The overhead introduced by this implementation is not really an overhead, because otherwise, the user of this crate would have to sort. And due to the current order check, there is no way around sorting anyway.
SetOf
The alloc-free
SetOf
was not changed. ButSetOf::add()
could also be improved, I think.