Comments (9)
Thanks for the ticket, that makes sense. What I don't get is how you get a 64 bit bitset with 4x8bit. Even if the 8bit array is mapped 1:1 to the internal 31 bit Array structure, it's 4x31=124bit.
from bitset.js.
from bitset.js.
Okay, I see your point now. Even if Bitset.js allocates 64 bits, it doesn't mean it's the actual size. Consider the following:
console.log(new BitSet(new Uint8Array([1,2,3,4])))
which produces: { data: [ 67305985, 0 ] }
That means the whole 4 bytes are packed into the 32bit integer - which makes sense. The additional zero is just a slight extension for performance reasons, since it could happen that one of the proceeding bits is touched soon.
So, I see your point here. Also on the whole topic, that 64 should be returned. But it isn't correct and doesn't make too much sense, since the internal allocated data doesn't represent the external state. And things are getting even more complicated with #22. Since Bitset.js provides arbitrarily large bit vectors, Infinity is the only reasonable answer to ntz()
. You bring additional knowledge into play here, since you know JavaScript works on 32bit integers and as such Bitset.js does. But the purpose of this library is to abstract over this limitation.
Could you elaborate on how you want to use ntz with a bit vector of all zeros? What would 64 mean to you in your application?
from bitset.js.
It doesn't matter atm, I wrote an adapter around the bitset functions making it more closer to the API I expected. But checking for Infinity is not any different as checking for ntz = bitmap size in my case.
from bitset.js.
The thing is, that I don't have the actual bitmap size. I could return arr.length*32
, but as I said this doesn't reflect the actual bitmap size, since bitset.js pre-allocates the array with zeros to reduce execution time on stressful environments. I decided to do so, when I fought with Daniel Lemire's fastbitset to win the battle. In a later step I decided to make Bitset.js working with negations - that's where the '_'-attribute was born. This change made Bitset.js an arbitrarily large bit vector implementation, for which ntz=Infty is the most logical answer. That's why I'd like to keep it the way it is.
from bitset.js.
I'm using it for this: https://github.com/MatrixAI/js-resource-counter btw. BitSet is fine currently.
from bitset.js.
This is a pretty cool use case for Bitset.js! Matrix.ai is a nice project, are u working alone on it?
from bitset.js.
from bitset.js.
So, can we close this ticket as well? I mean, Infinity is the only reasonable result and it doesn't make any difference in your code. I added a small note on the ntz
doc entry about this behavior.
from bitset.js.
Related Issues (20)
- Why is isEmpty false even when all bits are set to 0? HOT 3
- New Functions HOT 5
- Webpack compatible version HOT 8
- Q: TypeScript Definition file? HOT 4
- Misleading comments on [im]mutable functions HOT 2
- [Question] Optimized for large ranges of the same value? HOT 3
- Array parser HOT 2
- Memory usage HOT 10
- A `size()` method HOT 3
- The typescript type declaration does not match the structure of the actual module
- Symbol.iterator is missing from the TypeScript types
- Shifts
- iterator: syntax error in IE HOT 9
- As we can construct a bitset object by a Buffer, Can we convert the bitset to Buffer HOT 4
- How to use this most efficiently? HOT 3
- Unexpected Results HOT 2
- Documentation problem with "set" function HOT 1
- Base 36 constructor HOT 3
- Benchmarks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitset.js.