mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-08 03:51:22 +00:00
Improve split function
This commit is contained in:
parent
229351b38e
commit
c8d5f00d7c
@ -37,7 +37,10 @@ fn honey_badger_split<T: Clone>(list: &Vec<T>, n: usize) -> Vec<Vec<T>> {
|
|||||||
let mut split_list: Vec<Vec<T>> = vec![];
|
let mut split_list: Vec<Vec<T>> = vec![];
|
||||||
let list_length = list.len();
|
let list_length = list.len();
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
let partition = list.get(list_length*i/n..list_length*(i+1)/n).unwrap(); // cannot go out of bounds
|
let partition = match list.get(list_length*i/n..list_length*(i+1)/n) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => unreachable!(),
|
||||||
|
};
|
||||||
split_list.push(partition.to_vec());
|
split_list.push(partition.to_vec());
|
||||||
}
|
}
|
||||||
split_list
|
split_list
|
||||||
|
Loading…
Reference in New Issue
Block a user