Skip to content

feat(examples): add bitset package#5430

Open
jeronimoalbi wants to merge 5 commits intognolang:masterfrom
jeronimoalbi:feat/jeronimoalbi-bitset-package
Open

feat(examples): add bitset package#5430
jeronimoalbi wants to merge 5 commits intognolang:masterfrom
jeronimoalbi:feat/jeronimoalbi-bitset-package

Conversation

@jeronimoalbi
Copy link
Copy Markdown
Member

No description provided.

@jeronimoalbi
Copy link
Copy Markdown
Member Author

The main purpose of this package right now is to be used to implement a bloom filter package

@Gno2D2
Copy link
Copy Markdown
Collaborator

Gno2D2 commented Apr 4, 2026

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
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:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: jeronimoalbi/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission


// And performs an in-place AND with other bitset.
// Current bitset grows if the other bitset is bigger.
func (b *BitSet) And(other BitSet) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if b is longer than other, the bits outside the range of other seems would not be handled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, nice catch!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 78e3c51

Copy link
Copy Markdown
Member

@davd-gzl davd-gzl left a comment

Choose a reason for hiding this comment

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

Looks good otherwise!


// Set turns on the bit at a given position.
func (b *BitSet) Set(i int) {
idx := wordIndex(i)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return false // Bit has not been setted yet
return false // Bit has not been set yet

return s
}

func (b *BitSet) grow(idx int) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should zero-pad values to have a correct binary representation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧾 package/realm Tag used for new Realms or Packages.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants