1#![allow(dead_code)]
2
3use build_const::build_const;
4
5build_const!("constants");
6
7#[macro_export]
8macro_rules! const_for {
9 ($i:ident in $a:literal.. $b:ident $contents:block) => {
10 let mut $i = $a;
11 while $i < $b {
12 $contents;
13 $i += 1;
14 }
15 };
16}
17
18pub(crate) static INVERSE_TABLE: [[u32; MAX_PRIME]; NUM_PRIMES] = const {
19 let mut result = [[0; MAX_PRIME]; NUM_PRIMES];
20 const_for! { i in 0 .. NUM_PRIMES {
21 let p = PRIMES[i];
22 const_for! { k in 1 .. p {
23 result[i][k as usize] = crate::prime::power_mod(p, k, p - 2);
24 }}
25 }};
26 result
27};
28
29macro_rules! populate_binomial_table {
30 ($res:expr, $size:ident, $mod:expr) => {
31 const_for! { n in 0 .. $size {
32 $res[n][0] = 1;
33 const_for! { k in 0 .. n {
34 $res[n][k + 1] = ($res[n - 1][k] + $res[n - 1][k + 1]) % $mod;
35 }}
36 }}
37 };
38}
39
40pub(crate) const BINOMIAL4_TABLE_SIZE: usize = 50;
41
42pub(crate) const BINOMIAL4_TABLE: [[u32; BINOMIAL4_TABLE_SIZE]; BINOMIAL4_TABLE_SIZE] = {
43 let mut res = [[0; BINOMIAL4_TABLE_SIZE]; BINOMIAL4_TABLE_SIZE];
44 populate_binomial_table!(res, BINOMIAL4_TABLE_SIZE, 4);
45 res
46};
47
48pub(crate) static BINOMIAL_TABLE: [[[u32; MAX_PRIME]; MAX_PRIME]; NUM_PRIMES] = {
49 let mut result = [[[0; MAX_PRIME]; MAX_PRIME]; NUM_PRIMES];
50 const_for! { i in 0 .. NUM_PRIMES {
51 let p = PRIMES[i];
52 let pu = p as usize;
53 populate_binomial_table!(result[i], pu, p);
54 }}
55 result
56};