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 isEmpty utility method #789

Merged
merged 6 commits into from
Jan 5, 2024
Merged

Add isEmpty utility method #789

merged 6 commits into from
Jan 5, 2024

Conversation

TJKoury
Copy link
Contributor

@TJKoury TJKoury commented Dec 6, 2023

Added isEmpty utility method. Needed a more efficient way to check if a BitField instance has no set bits, using early return for positives.

Copy link
Owner

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

I'd love to add isEmpty. The PR also adds a bunch of other methods that will make memory usage increase a lot and that I don't want to add to this module.

src/index.ts Outdated
Comment on lines 39 to 44
/** Variable to store the count of bits set to 1 */
private setBitCount: number = 0;

/** Set to keep track of indices of set bits */
private readonly setBits: Set<number> = new Set();

Copy link
Owner

Choose a reason for hiding this comment

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

I would like to keep the memory usage of bitfield the same as it is, and especially the set will require quite a bit more memory. They are also not needed for isEmpty. Let's remove them?

package.json Outdated
@@ -1,7 +1,7 @@
{
"name": "bitfield",
"description": "a simple bitfield, compliant with the BitTorrent spec",
"version": "4.1.0",
"version": "4.2.0",
Copy link
Owner

Choose a reason for hiding this comment

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

npm version bumps this, please don't change it manually.

@fb55 fb55 merged commit 9900dcf into fb55:master Jan 5, 2024
9 checks passed
@fb55
Copy link
Owner

fb55 commented Jan 5, 2024

I went ahead and addressed my review comments. Thanks @TJKoury!

@TJKoury
Copy link
Contributor Author

TJKoury commented Jan 5, 2024

Awesome! Thanks for accepting; those other methods help with time complexity but at the cost of memory (as always is the trade-off).

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.

None yet

2 participants