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

Add count_ones_to_offset function #4

Closed
fuine opened this issue Oct 12, 2016 · 6 comments
Closed

Add count_ones_to_offset function #4

fuine opened this issue Oct 12, 2016 · 6 comments

Comments

@fuine
Copy link
Contributor

fuine commented Oct 12, 2016

I have implemented function: fn count_ones_to_offset(&self, offset: usize) -> usize. I would like to add it to this crate, but when I asked @bluss about it, he suggested that maybe this function should take Range as argument. Example usage below:

    let mut fb = FixedBitSet::with_capacity(15);
    fb.set(11, true);
    fb.set(7, true);
    assert_eq!(fb.count_ones_to_offset(6), 0);
    assert_eq!(fb.count_ones_to_offset(7), 1);
    assert_eq!(fb.count_ones_to_offset(11), 2);
@bluss
Copy link
Member

bluss commented Oct 12, 2016

fb.count_ones(..), fb.count_ones(..6), fb.count_ones(3..11) seems like the most powerful and simple to use API. However, that would require some kind of range trait. You can copy the code from crate odds.

@bluss
Copy link
Member

bluss commented Oct 12, 2016

Or just implement it for Range<usize> for now.

@fuine
Copy link
Contributor Author

fuine commented Oct 12, 2016

I thought about using this crate like so:
fn count_ones<T: Num>(&self, r: Range<T>) -> usize. What do you think?

@bluss
Copy link
Member

bluss commented Oct 12, 2016

Absolutely not. Nothing personal, but indices are only usize in Rust, we don't need numerical traits.

@fuine
Copy link
Contributor Author

fuine commented Oct 12, 2016

Sure. I think i will use the trait from odds, do you want me to copy the implementation over or include odds as dependency? Also i think that in the long term we could migrate to rust-lang/rust#30877 if it ever stabilizes

@bluss
Copy link
Member

bluss commented Oct 12, 2016

copy

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

No branches or pull requests

2 participants