Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
[merge-sort] add limit option to take_arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jul 30, 2021
1 parent 84d98f2 commit 9ccaf93
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/compute/merge_sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,28 @@ pub fn take_arrays<I: IntoIterator<Item = MergeSlice>>(
) -> Box<dyn Array> {
let slices = slices.into_iter();
let len = arrays.iter().map(|array| array.len()).sum();

let limit = limit.unwrap_or(len);
let limit = limit.min(len);
let mut growable = make_growable(arrays, false, limit);

let mut current_len = 0;
for (index, start, len) in slices {
if len + current_len >= limit {
growable.extend(index, start, limit - current_len);
break;
} else {
if limit == len {
let mut current_len = 0;
for (index, start, len) in slices {
if len + current_len >= limit {
growable.extend(index, start, limit - current_len);
break;
} else {
growable.extend(index, start, len);
current_len += len;
}
}
} else {
for (index, start, len) in slices {
growable.extend(index, start, len);
current_len += len;
}
}

growable.as_box()
}

Expand Down

0 comments on commit 9ccaf93

Please sign in to comment.