Search-optimized bitmap
Posted: Thu Aug 13, 2009 3:52 pm
I've come up with idea about optimized bitmap, which should be able to look up ones (or with slight modifications - zeros) pretty fast.
Begin with bitmap as usual. But then I add another bitmap on top of it and fill it by OR-ing groups of bits of lower level together. If that layer is still too large, I add another level on top of it. Repeat until top-level bitmap is small enough for sequential scan.
Here's an illustration for 64 bits, using 4-bit groups: If I set or clear bit, I update bits in upper levels, of course.
Then, if I need to look up a bit, I start from the top, find first bit, move down a level to corresponding group, search there and continue until hit the bottom level.
By my calculations lookup and bit toggling should be O(log_{bits_per_group}(N)).
Ideally I'd use 2-bit groups, thus O(log2(n)), however 8-bit groups (bytes ) seems to be more practical for coding. And O(log8(n)) doesn't seem bad either.
Now, haven't I overlooked something? It almost seems too good to be true
Begin with bitmap as usual. But then I add another bitmap on top of it and fill it by OR-ing groups of bits of lower level together. If that layer is still too large, I add another level on top of it. Repeat until top-level bitmap is small enough for sequential scan.
Here's an illustration for 64 bits, using 4-bit groups: If I set or clear bit, I update bits in upper levels, of course.
Then, if I need to look up a bit, I start from the top, find first bit, move down a level to corresponding group, search there and continue until hit the bottom level.
By my calculations lookup and bit toggling should be O(log_{bits_per_group}(N)).
Ideally I'd use 2-bit groups, thus O(log2(n)), however 8-bit groups (bytes ) seems to be more practical for coding. And O(log8(n)) doesn't seem bad either.
Now, haven't I overlooked something? It almost seems too good to be true