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

Initialize with const fn #6

Merged
merged 3 commits into from
Mar 8, 2019
Merged

Initialize with const fn #6

merged 3 commits into from
Mar 8, 2019

Conversation

luizirber
Copy link
Owner

With Rust 1.33 we can use const fn and avoid lazy_static (as pointed in #2 (comment) )

lookup
};
const fn h_lookup_table() -> [u64; 256] {
let mut lookup = [1; 256];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity, any reason to initialize it with 256 items instead of just 5?

Copy link
Owner Author

@luizirber luizirber Mar 3, 2019

Choose a reason for hiding this comment

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

We are not converting the bases ACGT to a 2-bit representation, instead we keep it as char, which is u8 (and 2**8 = 256).

That said, we could return [u8; 256] instead, because the two places using the lookup table are doing a c as usize conversion:
https://github.com/luizirber/nthash/pull/6/files#diff-b4aea3e418ccdb71239b96952d9cddb6R47
https://github.com/luizirber/nthash/pull/6/files#diff-b4aea3e418ccdb71239b96952d9cddb6R56

update: Err, no, we can't return [u8; 256] because the values in the array are indeed u64, and the c as usize is necessary because indexing uses usize.

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