Variable size bitmap

I am dealing with the issue of an array in which I have to find unique elements. Now for this, my logic is to find the max element in the array and define a set of bits for this. But the problem in batet requires constant value, therefore, how to overcome this, below are some of my questions:

a) Can I accidentally set a variable-sized bitset?
b) If not, what is the best approach to use vector<bool> or vector<char> ?
c) I know that boost has a dynamic set of bits, but since I am doing this for training, I want to know alternative approaches.

+8
c ++ data-structures bitset
source share
1 answer

The std::bitset<N> pattern requires a fixed size in advance. std::vector<bool> is the standard C ++ way to provide a variable length bitvector, and it offers functionality similar to a bitrate that can grow and shrink.

Whether it's better or worse to use vector<char> or vector<bool> : vector<bool> is a much more direct way to achieve this. I would start using it and then switch to vector<char> if performance is unacceptable. In general, it's good to try to write the cleanest, simplest implementation first, and then optimize later.

Hope this helps!

+8
source share

All Articles