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

Add support to merge sort with a limit #222

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

sundy-li
Copy link
Collaborator

@sundy-li sundy-li commented Jul 25, 2021

Closes #221

Backward incompatible changes

The functions compute::merge_sort::take_arrays and compute::merge_sort::merge_sort now expects a third argument, Option<usize>, denoting an optional limit. To migrate, add None to their calls.

@sundy-li sundy-li changed the title add limit option to merge sort lazy take_arrays add limit option to merge sort Jul 25, 2021
@codecov
Copy link

codecov bot commented Jul 25, 2021

Codecov Report

Merging #222 (3268564) into main (eaa9be9) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #222      +/-   ##
==========================================
- Coverage   76.94%   76.84%   -0.10%     
==========================================
  Files         229      229              
  Lines       19536    19610      +74     
==========================================
+ Hits        15031    15070      +39     
- Misses       4505     4540      +35     
Impacted Files Coverage Δ
src/compute/merge_sort/mod.rs 94.09% <100.00%> (+0.53%) ⬆️
src/ffi/ffi.rs 70.53% <0.00%> (-5.94%) ⬇️
src/array/fixed_size_list/mod.rs 58.33% <0.00%> (-2.54%) ⬇️
src/array/utf8/ffi.rs 76.47% <0.00%> (-2.48%) ⬇️
src/compute/filter.rs 63.19% <0.00%> (-1.59%) ⬇️
src/array/binary/ffi.rs 81.81% <0.00%> (-1.52%) ⬇️
src/array/primitive/ffi.rs 75.00% <0.00%> (-1.48%) ⬇️
src/array/list/ffi.rs 80.00% <0.00%> (-0.96%) ⬇️
src/bitmap/immutable.rs 86.30% <0.00%> (-0.55%) ⬇️
src/buffer/mutable.rs 91.76% <0.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eaa9be9...3268564. Read the comment docs.

for (index, start, len) in slices {
growable.extend(index, start, len)
if len + current_len >= limit {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably makes the code without a limit (limit=None) slower.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be avoided by having two different implementations/bodies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not expose a new function just for this; wouldn't it make sense to move this if to outside of the loop and keep the function with the limit argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid the if can't move outside of the loop because the slice is an iterator.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do slices.into_iter() in two code blocks instead of reusing it, it shouldn't be a compile error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is thatslices is lazy iterated, we don't know the item of len unless we call next(), so the if check must be inside the loop when limit is some value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking in something like this:

...
if let Some(limit) = limit {
    iterate with the limit condition
} else {
   iterate without the limit condition
}
...
growable.to_box()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great.

@sundy-li sundy-li changed the title add limit option to merge sort Add take_arrays_with_limit function in merge_sort Jul 29, 2021
@sundy-li sundy-li changed the title Add take_arrays_with_limit function in merge_sort Add limit option to take_arrays in merge_sort Jul 30, 2021
@jorgecarleitao jorgecarleitao added backwards-incompatible enhancement An improvement to an existing feature labels Jul 30, 2021
@jorgecarleitao jorgecarleitao changed the title Add limit option to take_arrays in merge_sort Add support to merge_sort with a limit Jul 30, 2021
@jorgecarleitao jorgecarleitao changed the title Add support to merge_sort with a limit Add support to merge sort with a limit Jul 30, 2021
@jorgecarleitao jorgecarleitao merged commit 8a0c76e into jorgecarleitao:main Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backwards-incompatible enhancement An improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge sort support limit option
3 participants