Closed whaatt closed 5 years ago
good idea to use the merge sort technique, and to make it general. 3 changes to make
Never
thing if we have to re-derive anyway? Experienced rust devs should recognize the empty enum pattern.Yeah, not super attached to this; made the change since the future preferred way to write an uninhabited struct is Type(!)
once the !
(Never) type lands in stable. Will defer to you on whether we should just keep the empty enum pattern until that happens.
tru
Agreed that recursion is cleaner (and internally requires the same N
allocations). Motivation behind the iterative version (should've added this in a comment) is that in general we might get away with just consuming elem_witnesses
in delete
rather than borrowing. In which case the iterative solution would require no extra allocations.
Still looking into (3) though.
re 1. let's keep the empty enums for the time being re 3, yeah, see if it's true whether or not we can consume the elem_witnesses. if all of our use-cases turn out to require clones, we may as well use the cleaner recursive implementation
changed (1) and (2)
also changed to recursive impl; I benchmarked the no-allocation version without the cloning and it wasn't appreciably faster (runtime is dominated by Shamir it seems)
Looks good now. Why don't we also make shamir_trick return a Result<> instead of an Option? Should save a few lines
Edit: nevermind, since the error has to be converted to an AccError anyway
Definitely more stuff to look into here, but
delete
on 50 elements is made about 4x faster if theShamirTrick
is applied in a MergeSort-fashion (as opposed to iteratively), since the average size of the inputs toShamirTrick
should go down.