logoalt Hacker News

Findecanoryesterday at 3:03 PM1 replyview on HN

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.


Replies

aidenn0yesterday at 10:19 PM

The size is 1..4096, the range is implied to be the full 16-bit integer range.