feat(examples): add bitset package#5430
Conversation
|
The main purpose of this package right now is to be used to implement a bloom filter package |
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
|
|
||
| // And performs an in-place AND with other bitset. | ||
| // Current bitset grows if the other bitset is bigger. | ||
| func (b *BitSet) And(other BitSet) { |
There was a problem hiding this comment.
if b is longer than other, the bits outside the range of other seems would not be handled.
There was a problem hiding this comment.
Good point, nice catch!
|
|
||
| // Set turns on the bit at a given position. | ||
| func (b *BitSet) Set(i int) { | ||
| idx := wordIndex(i) |
There was a problem hiding this comment.
This panic if i < -64
-65 / 64 = -1
idx == -1, b.grow(-1) == noop
b.words[-1] => out of bounds, panic
| func (b BitSet) Test(i int) bool { | ||
| idx := wordIndex(i) | ||
| if idx >= len(b.words) { | ||
| return false // Bit has not been setted yet |
There was a problem hiding this comment.
| return false // Bit has not been setted yet | |
| return false // Bit has not been set yet |
| return s | ||
| } | ||
|
|
||
| func (b *BitSet) grow(idx int) { |
There was a problem hiding this comment.
Should grow take a length instead of an idx? Almost every call subtract one to its value, and this function add 1 back.
And personally I think it makes more sense to grow to a length instead of an index.
| func (b BitSet) String() string { | ||
| var s string | ||
| for _, w := range b.words { | ||
| s += strconv.FormatUint(w, 2) |
There was a problem hiding this comment.
You should zero-pad values to have a correct binary representation
No description provided.