Returns digits of `value` when expressed in sumset notation give sumset boundaries, i.e. `G`
(value: u128, G: &[u128], base: u16)
| 94 | |
| 95 | /// Returns digits of `value` when expressed in sumset notation give sumset boundaries, i.e. `G` |
| 96 | pub fn decompose_for_sumset(value: u128, G: &[u128], base: u16) -> Vec<u16> { |
| 97 | let mut deomposition = vec![0; G.len()]; |
| 98 | let mut target = value; |
| 99 | for (i, g_i) in G.iter().enumerate() { |
| 100 | // For each g_i, check if target >= (base-1) * g_i. If it is then digit corresponding to g_i is (base-1) and new |
| 101 | // target is target - (base-1) * g_i. Else check if target >= (base-2) * g_i and so on. |
| 102 | for u_i in (1..base).rev() { |
| 103 | let g_u = *g_i * u_i as u128; |
| 104 | if target >= g_u { |
| 105 | deomposition[i] = u_i; |
| 106 | target -= g_u; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | debug_assert_eq!(target, 0); |
| 112 | deomposition |
| 113 | } |
| 114 | |
| 115 | /// Pre-requisites of applying sumset protocol |
| 116 | /// Returns number of digits, sumset boundaries (G), randomness multiple and digits of the adapted value. |