Skip to content
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

compute_hash_on_elements could accept any iterator on FieldElement #575

Closed
tdelabro opened this issue Mar 25, 2024 · 4 comments · Fixed by #594
Closed

compute_hash_on_elements could accept any iterator on FieldElement #575

tdelabro opened this issue Mar 25, 2024 · 4 comments · Fixed by #594

Comments

@tdelabro
Copy link
Contributor

pub fn compute_hash_on_elements(data: &[FieldElement]) -> FieldElement {

Right now the signature requires the input to be &[FieldElement] but it's implementation would still be valid if the input were to be a more generic T: Iter<FieldElement>. It would allow more flexibility for the lib users

@xJonathanLEI
Copy link
Owner

The issue with Iterator<FieldElement> is then you can't use say slices they yield &FieldElement instead of FieldELement.

@xJonathanLEI
Copy link
Owner

What we could do is maybe T: AsRef<[FieldElement]>? This way you can send in anything that can be referenced as a slice, but then... if you can reference it as a slice you could have just passed in the slice like you do right now.

The only benefit of this change, as far as I know, is that you can now also pass in owned values, which could be useful in a threading scenario. Not that it's not useful in certain cases, but it's probably not what you're looking for.

@xJonathanLEI
Copy link
Owner

xJonathanLEI commented Mar 27, 2024

Oh the other hand, we can indeed provide a hasher type which would actually work better with iterators? Such a hasher would probably be rather generic and won't hash the arrary length at the end though.

@tdelabro
Copy link
Contributor Author

https://rust-lang.github.io/api-guidelines/flexibility.html#functions-minimize-assumptions-about-parameters-by-using-generics-c-generic

T: IntoIterator<Item = FieldElement> requires you to have ownership of the value, if you want to pass a slice, you can do so:

compute_hash_on_elements(my_slice.into_iter().cloned())

This ensures you own the value you are passing in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants