You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently bytes_to_field_elements takes AsRef<[u8]> as input and returns Vec<F> as output. This can lead to unnecessary mem copy or heap alloc if the caller doesn't already have a AsRef<[u8]> or wants the output in some form other than Vec<F>.
Example: here the caller actually wants a Vec<Vec<F>>, and needs to copy/allocate a whole 2D vec for this purpose.
Problem
Originally posted by @ggutoski in #299 (comment)
Currently
bytes_to_field_elements
takesAsRef<[u8]>
as input and returnsVec<F>
as output. This can lead to unnecessary mem copy or heap alloc if the caller doesn't already have aAsRef<[u8]>
or wants the output in some form other thanVec<F>
.Example: here the caller actually wants a
Vec<Vec<F>>
, and needs to copy/allocate a whole 2D vec for this purpose.https://github.com/EspressoSystems/hotshot-primitives/blob/52b2f713eea897778eb8a73f401c9b1b4a2dde19/src/vid/advz.rs#L158-L159
Solution
bytes_to_field_elements
should acceptIntoIterator
instead ofAsRef<[u8]>
and should return an iterator overF
instead ofVec<F>
.We should do the same for
bytes_from_field_elements
, though that will be more complicated to implement.This solution is an example of the iterator adaptor pattern:
The text was updated successfully, but these errors were encountered: