I have never worked with bit operations in C, but now I need to, because I need my program to be CPU efficient.
I have a big array int *v
which contains k
, numbers (k
is known) and my program will set each v[i]
to zero, in an undefined order, and will store the index i
in an array int *q
. Before storing the index I have to check if the index is already in q
, so I won't store it twice. This check takes up a lot of time. I was thinking of implementing a bitset k
bits, each set to zero and when I add index i
to q
, I would also set the bit i
from my bitset to one. Before that I need to check if the i
bit is not already one. How can I do that?
I did check if other questions already have my answer, but I didn't understand very well since I'm new to programming.