Giter Site home page Giter Site logo

Comments (9)

infusion avatar infusion commented on May 28, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on May 28, 2024

from bitset.js.

infusion avatar infusion commented on May 28, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on May 28, 2024

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.

infusion avatar infusion commented on May 28, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on May 28, 2024

I'm using it for this: https://github.com/MatrixAI/js-resource-counter btw. BitSet is fine currently.

from bitset.js.

infusion avatar infusion commented on May 28, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on May 28, 2024

from bitset.js.

infusion avatar infusion commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.