Uh oh!
There was an error while loading. Please reload this page.
Add count_ones, count_zeros methods - #22
Conversation
emilio
left a comment
There was a problem hiding this comment.
I think this can be much simpler, unless I'm missing something.
| if self.is_inline() { | ||
| let mask = inline_ones(len); | ||
| (self.data & mask).count_ones() as usize |
There was a problem hiding this comment.
I'd prefer to return here and deindent the rest.
There was a problem hiding this comment.
Do you really need the & mask for this case? The other bits should always be zero.
There was a problem hiding this comment.
Ah, I lie, I recall that we use the last non-zero bit as a sentinel, so you do need this.
| (self.data & mask).count_ones() as usize | ||
| } else { | ||
| let mut count = 0; | ||
| for &storage in self.buffer() { |
There was a problem hiding this comment.
Same, can't this loop just do count += storage.count_ones()?
There was a problem hiding this comment.
And you cannot, because we don't clear storage when we pop(), so never mind :)
| } | ||
| /// Counts the number of bits in the vector that are set to zero/false | ||
| pub fn count_zeros(&self) -> usize { |
There was a problem hiding this comment.
Why can't this be self.len() - self.count_ones()?
Pretty self-explanatory. Add methods for counting the number of ones/zeros in a
SmallBitVec.