pub fn build_support_map<AccountId>(
	winners: &[AccountId],
	assignments: &[StakedAssignment<AccountId>],
) -> Result<SupportMap<AccountId>, AccountId> where
	AccountId: IdentifierT,
{
	// Initialize the support of each candidate.
	let mut supports = <SupportMap<AccountId>>::new();
	winners
		.iter()
		.for_each(|e| { supports.insert(e.clone(), Default::default()); });

	// build support struct.
	for StakedAssignment { who, distribution } in assignments.iter() {
		for (c, weight_extended) in distribution.iter() {
			if let Some(support) = supports.get_mut(c) {
				support.total = support.total.saturating_add(*weight_extended);
				support.voters.push((who.clone(), *weight_extended));
			} else {
				return Err(c.clone())
			}
		}
	}
	Ok(supports)
}
/// Build the support map from the given election result. It maps a flat structure like
///
/// ```nocompile
/// assignments: vec![
///     voter1, vec![(candidate1, w11), (candidate2, w12)],
///     voter2, vec![(candidate1, w21), (candidate2, w22)]
/// ]
/// ```
///
/// into a mapping of candidates and their respective support:
///
/// ```nocompile
///  SupportMap {
///     candidate1: Support {
///         own:0,
///         total: w11 + w21,
///         others: vec![(candidate1, w11), (candidate2, w21)]
///     },
///     candidate2: Support {
///         own:0,
///         total: w12 + w22,
///         others: vec![(candidate1, w12), (candidate2, w22)]
///     },
/// }
/// ```
///
/// The second returned flag indicates the number of edges who didn't corresponded to an actual
/// winner from the given winner set. A value in this place larger than 0 indicates a potentially
/// faulty assignment.
///
/// `O(E)` where `E` is the total number of edges.
Build the support map from the given election result.

into a mapping of candidates and their respective support.



The second returned flag indicates the number of edges who didn't corresponded to an actual
winner from the given winner set. A value in this place larger than 0 indicates a potentially
faulty assignment.

`O(E)` where `E` is the total number of edges.
Build the support map from the given election result . into a mapping of candidates and their respective support . The second returned flag indicates the number of edges who didn ' t corresponded to an actual winner from the given winner set . A value in this place larger than 0 indicates a potentially faulty assignment . ` O ( E ) ` where ` E ` is the total number of edges .
pub fn build_support_map<AccountId>(
	winners: &[AccountId],
	assignments: &[StakedAssignment<AccountId>],
) -> Result<SupportMap<AccountId>, AccountId> where
	AccountId: IdentifierT,
{
	// Initialize the support of each candidate.
	let mut supports = <SupportMap<AccountId>>::new();
	winners
		.iter()
		.for_each(|e| { supports.insert(e.clone(), Default::default()); });
	// build support struct.
	for StakedAssignment { who, distribution } in assignments.iter() {
		for (c, weight_extended) in distribution.iter() {
			if let Some(support) = supports.get_mut(c) {
				support.total = support.total.saturating_add(*weight_extended);
				support.voters.push((who.clone(), *weight_extended));
			} else {
				return Err(c.clone())
			}
		}
	}
	Ok(supports)
}
pub fn build_support_map < AccountId > ( winners : & [ AccountId ] , assignments : & [ StakedAssignment < AccountId > ] , ) -> Result < SupportMap < AccountId > , AccountId > where AccountId : IdentifierT , { // Initialize the support of each candidate. let mut supports = < SupportMap < AccountId > > :: new ( ) ; winners . iter ( ) . for_each ( | e | { supports . insert ( e . clone ( ) , Default :: default ( ) ) ; } ) ; // build support struct. for StakedAssignment { who , distribution } in assignments . iter ( ) { for ( c , weight_extended ) in distribution . iter ( ) { if let Some ( support ) = supports . get_mut ( c ) { support . total = support . total . saturating_add ( * weight_extended ) ; support . voters . push ( ( who . clone ( ) , * weight_extended ) ) ; } else { return Err ( c . clone ( ) ) } } } Ok ( supports ) }
Build the support map from the given election result.
Build the support map from the given election result .
winners
&[AccountId]
assignments
&[StakedAssignment<AccountId>]
winners
&[AccountId]
assignments
&[StakedAssignment<AccountId>]