logoalt Hacker News

aidenn0yesterday at 2:36 PM2 repliesview on HN

If you are storing 16-bit integers, wouldn't an 8kB bitmap be even faster?


Replies

loegyesterday at 3:55 PM

The library the author is talking about selects between bitmap and array dynamically depending on density.

https://roaringbitmap.org/

Findecanoryesterday at 3:03 PM

The range is 1..4096, so 4096 bits = 512 byte bitmap would suffice.

That is, if you're only ever going to test for membership in the set. If you need metadata then ... You could store that in a packed array and use a population count of the bit-vector before the lookup bit as index into it. For each word of bits, store the accumulated population count of the words before it to speed up lookup. Modern CPU's are memory-bound so I don't think SIMD would help much over using 64-bit words. For 4096 bits / 64, that would be 64 additional bytes.