According to this post Performance of doing bitwise operations on bitsets performance is O(n)
how do I make it O(log n)
.
The answer is you don't.
Assume you have a bitset of n
size.
Let's look at the xor operator ^
.
It obviously has to look at each bit in both operands, so it makes 2n
lookups.
This results in a complexity of O(n)
.
You can use assembler instructions that e.g. do it for 32 bits at a time, so the number of operations is (n+31)/32
, but this doesn't change that the complexity is O(n)
. After all complexity is calculated for n
towards infinity and constant factors are disregarded.