Skip to content

rewrite of shootout-reverse-complement.rs #10799

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

Merged

Conversation

TeXitoi
Copy link
Contributor

@TeXitoi TeXitoi commented Dec 4, 2013

This version is inspired by the best version in C by Mr Ledrug,
but without the parallelisation.

// reverse complement
let mut seq = seq;
loop {
if seq.len() <= 1 {break;}
Copy link
Member

Choose a reason for hiding this comment

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

Why not while seq.len() > 1 { ... }?

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 4, 2013

@huonw what do you think?

if ch == 0 {
break;
// reverse complement
let mut it = seq.mut_iter();
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, but couldn't this whole loop be replaced with seq.reverse()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's reversing and transforming using complements

Equivalent but slower:

        let mut it = seq.mut_iter();
        loop {
            match (it.next(), it.next_back()) {
                (Some(front), Some(back)) => {
                    std::util::swap(front, back);
                    *front = complements[*front];
                    *back = complements[*back];
                }
                _ => break // vector exhausted.
            }
        }

Equivalent but much slower:

        seq.reverse();
        for c in seq.mut_iter() {
            *c = complements[*c]
        }

Copy link
Member

Choose a reason for hiding this comment

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

Aha! I can totally read code.

@alexcrichton
Copy link
Member

Could you rebase these two commits into one? Other than that looks good to me!

This version is inspired by the best version in C by Mr Ledrug,
but without the parallelisation.
@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 4, 2013

@alexcrichton squashed.

bors added a commit that referenced this pull request Dec 5, 2013
…ected, r=alexcrichton

This version is inspired by the best version in C by Mr Ledrug,
but without the parallelisation.
@bors bors closed this Dec 5, 2013
@bors bors merged commit e76e83c into rust-lang:master Dec 5, 2013
@TeXitoi TeXitoi deleted the shootout-reverse-complement-resurected branch April 21, 2014 22:11
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.

4 participants