I wrote a bitvector class (well, I modified the one in Ron Penton's DSFGP book). I just have a couple of questions.
First, in his class he has a SetAll function to set each bit to 1. Basically, something like this:
void SetAll()
{
int index;
for( index = 0; index < m_size; index++)
m_array[index] = 0xFFffFFff // he's using 32 bits per cell
}
I rewrote this to support cells of any size by changing m_array[index] = 0xFFffFFff to m_array[index] = ~0. I'm wondering if there's some sort of reason he didn't do it that way. The books all about keeping things as reusable as possible, but in this case he's saying each cell /must/ be 32 bits for it to work! Is there something wrong undesireable with the way I'm doing it?
My second question is, is this line too much to pack into one line of code?
m_array[cell] = p_value ? (m_array[cell] | (1<< bit)):(m_array[cell] & (~(1<<bit)));
He has it split up into an if/else statement, but I'm getting accustomed to using the ternary operator for cases like this. If you saw that code would you be irritated that I didn't split it up, or is that clear enough?
Like I said, just a couple of boring questions, but they're two things I'd like to know before I start developing bad habits.