winter_fri/
utils.rs

1// Copyright (c) Facebook, Inc. and its affiliates.
2//
3// This source code is licensed under the MIT license found in the
4// LICENSE file in the root directory of this source tree.
5
6use alloc::vec::Vec;
7
8/// Maps positions in the evaluation domain to indexes of of the vector commitment.
9pub fn map_positions_to_indexes(
10    positions: &[usize],
11    source_domain_size: usize,
12    folding_factor: usize,
13    num_partitions: usize,
14) -> Vec<usize> {
15    // if there was only 1 partition, order of elements in the vector commitment
16    // is the same as the order of elements in the evaluation domain
17    if num_partitions == 1 {
18        return positions.to_vec();
19    }
20
21    let target_domain_size = source_domain_size / folding_factor;
22    let partition_size = target_domain_size / num_partitions;
23
24    let mut result = Vec::new();
25    for position in positions {
26        let partition_idx = position % num_partitions;
27        let local_idx = (position - partition_idx) / num_partitions;
28        let position = partition_idx * partition_size + local_idx;
29        result.push(position);
30    }
31
32    result
33}