lambdaworks_math/
helpers.rs

1#[cfg(feature = "alloc")]
2use crate::field::{element::FieldElement, traits::IsFFTField};
3
4pub fn next_power_of_two(n: u64) -> u64 {
5    if n <= 1 {
6        1
7    } else {
8        (u64::MAX >> (n - 1).leading_zeros()) + 1
9    }
10}
11
12#[cfg(feature = "alloc")]
13pub fn resize_to_next_power_of_two<F: IsFFTField>(
14    trace_colums: &mut [alloc::vec::Vec<FieldElement<F>>],
15) {
16    trace_colums.iter_mut().for_each(|col| {
17        // TODO: Remove this unwrap. This may panic if the usize cant be
18        // casted into a u64.
19        let col_len = col.len().try_into().unwrap();
20        let next_power_of_two_len = next_power_of_two(col_len);
21        col.resize(next_power_of_two_len as usize, FieldElement::<F>::zero())
22    })
23}