-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
There was a problem hiding this 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
/** 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(); | ||
|
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
I went ahead and addressed my review comments. Thanks @TJKoury! |
Awesome! Thanks for accepting; those other methods help with time complexity but at the cost of memory (as always is the trade-off). |
Added isEmpty utility method. Needed a more efficient way to check if a BitField instance has no set bits, using early return for positives.