Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev bp clippy #18

Draft
wants to merge 7 commits into
base: dev_bp
Choose a base branch
from
Draft

Dev bp clippy #18

wants to merge 7 commits into from

Conversation

faassen
Copy link

@faassen faassen commented Jan 8, 2025

Here's a draft PR applying suggested clippy changes to the dev_bp branch to make cargo clippy produce no output and besides that I tried to follow clippy suggestions in tests and benches.

Many of the clippy changes are in tests. A lot of them have to do with changing manual indexing to using iterators, or not using vec! for sample data.

In main code:

I noticed that unfortunately there are some spurious diffs due to whitespace changes - I only use the standard Rust formatter though. I think that's mostly restricted to the new trees module. Most of the clippy changes in the trees section involve changing and_then into map and a few redundant closures.

div_ceil is an interesting one; there were various cases where it was implemented manually. There are a few changes of manual indexing to iter() in the wavelet matrix code.

I am curious whether there is any performance impact; I haven't done a benchmark compare yet.

Finally one change that seems silly: the additional brackets are what clippy suggests though they seem entirely redundant here.

(data[data_index] & ((1 << bit_index) - 1)).count_ones() as usize

@faassen faassen changed the title Dev bp Dev bp clippy Jan 8, 2025
@faassen faassen mentioned this pull request Jan 8, 2025
Copy link
Owner

@Cydhra Cydhra left a comment

Choose a reason for hiding this comment

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

A few changes are too eager, as they destroy test coverage

@@ -213,14 +213,14 @@ fn test_custom_iter_behavior() {
assert!(iter.advance_by(6).is_err());
assert!(iter.advance_back_by(5).is_ok());

assert_eq!(bv.iter().skip(2).next(), Some(0));
Copy link
Owner

Choose a reason for hiding this comment

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

Please revert this and suppress the clippy correction. This intentionally calls skip() and next() to verify skip behaves correctly. This test should exist regardless of whether nth() internally uses skip (which I think it doesn't). Same for the change a few lines down.

}
}

#[test]
fn test_custom_iter_behavior() {
let ef = EliasFanoVec::from_slice(&vec![0, 1, 2, 3, 4, 5, 6, 7, 8]);
assert_eq!(ef.iter().skip(2).next(), Some(2));
Copy link
Owner

Choose a reason for hiding this comment

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

Same here: skip().next() is called intentionally to test the skip function over nth(). Same a few lines below.

@@ -94,8 +94,8 @@ impl WaveletMatrix {

for (level, data) in data.iter_mut().enumerate() {
let mut total_zeros = 0;
for i in 0..num_elements {
if bit_lookup(permutation[i], element_len - level - 1) == 0 {
for (i, p) in permutation.iter().enumerate().take(num_elements) {
Copy link
Owner

Choose a reason for hiding this comment

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

is take() required here? is i required here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants