[−][src]Macro sp_npos_elections_compact::generate_compact_solution_type
generate_compact_solution_type!() { /* proc-macro */ }
Generates a struct to store the election assignments in a compact way. The struct can only store distributions up to the given input count. The given count must be greater than 2.
ⓘThis example is not tested
// generate a struct with nominator and edge weight u128, with maximum supported // edge per voter of 16. generate_compact_solution_type(pub TestCompact, 16)
This generates:
ⓘThis example is not tested
pub struct TestCompact<V, T, W> { votes1: Vec<(V, T)>, votes2: Vec<(V, (T, W), T)>, votes3: Vec<(V, [(T, W); 2usize], T)>, votes4: Vec<(V, [(T, W); 3usize], T)>, votes5: Vec<(V, [(T, W); 4usize], T)>, votes6: Vec<(V, [(T, W); 5usize], T)>, votes7: Vec<(V, [(T, W); 6usize], T)>, votes8: Vec<(V, [(T, W); 7usize], T)>, votes9: Vec<(V, [(T, W); 8usize], T)>, votes10: Vec<(V, [(T, W); 9usize], T)>, votes11: Vec<(V, [(T, W); 10usize], T)>, votes12: Vec<(V, [(T, W); 11usize], T)>, votes13: Vec<(V, [(T, W); 12usize], T)>, votes14: Vec<(V, [(T, W); 13usize], T)>, votes15: Vec<(V, [(T, W); 14usize], T)>, votes16: Vec<(V, [(T, W); 15usize], T)>, }
The generic arguments are:
V
: identifier/index for voter (nominator) types.T
identifier/index for candidate (validator) types.W
weight type.
Some conversion implementations are provided by default if
W
is u128, orW
is anything that implementsPerThing
(such asPerbill
)
The ideas behind the structure are as follows:
- For single distribution, no weight is stored. The weight is known to be 100%.
- For all the rest, the weight if the last distribution is omitted. This value can be computed from the rest.