Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
prefered -> preferred
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Nov 19, 2021
1 parent adaa92a commit eca1c49
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions runtime/parachains/src/paras_inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,36 +682,36 @@ where
fn random_sel<X, F: Fn(&X) -> Weight>(
rng: &mut rand_chacha::ChaChaRng,
selectables: Vec<X>,
mut prefered_indices: Vec<usize>,
mut preferred_indices: Vec<usize>,
weight_fn: F,
weight_limit: Weight,
) -> (Weight, Vec<usize>) {
if selectables.is_empty() {
return (0 as Weight, Vec::new())
}
// all indices that are not part of the prefered set
// all indices that are not part of the preferred set
let mut indices = (0..selectables.len())
.into_iter()
.filter(|idx| !prefered_indices.contains(idx))
.filter(|idx| !preferred_indices.contains(idx))
.collect::<Vec<_>>();
let mut picked_indices = Vec::with_capacity(selectables.len().saturating_sub(1));

let mut weight_acc = 0 as Weight;

// also shuffle the prefered ones
rng.shuffle(&mut prefered_indices);
for prefered_idx in prefered_indices {
// also shuffle the preferred ones
rng.shuffle(&mut preferred_indices);
for preferred_idx in preferred_indices {

// prefered indices originate from outside
if let Some(item) = selectables.get(prefered_idx) {
// preferred indices originate from outside
if let Some(item) = selectables.get(preferred_idx) {
weight_acc += weight_fn(item);

let updated = weight_acc + weight_fn(item);
if updated > weight_limit {
continue
}
weight_acc = updated;
picked_indices.push(prefered_idx);
picked_indices.push(preferred_idx);
}
}

Expand Down

0 comments on commit eca1c49

Please sign in to comment.