Comparing two bit arrays - FAST

  • Thread starter Thread starter Iain
  • Start date Start date
I

Iain

Hi

Hopefully I am missing something really simple with this question, but
here goes.

I have two Bitarrays that I would like to compare. At the moment, I am
XORing one with the other and checking to see if the result has any 1s
in it (if so, the arrays are different). This seems to be faster than
comparing each bit of the two original arrays one at a time. But I
still have to iterate over each element of the array, and I'd like to
do this faster. I've tried using the Equals method but this checks
whether the object references for the arrays are the same, not whether
each element is the same. My code compares millions of bit arrays,
which is why any faster method would be a great help.

Thanks very much in advance for any help.

Iain
 
Mmmh, do you store them in a BOOL? Because a bool is 32 bits wide; if
you choose a different way of storing them (this is 32 bools in an
unsigned int or 64 in a long), you could speed up the procedure a lot
(factor of 32 or 64 :-), though storing the bools in first place will be
more complex (since you have to apply some logic as shifting and
or'ing). So, depending on what you are going to do with the bit arrays
(just comparing or like manipulate single bits) you might want to
rethink the way of storage. Xor'ing them will of course still have to be
used for comparison. Fastest method i can think of.

I just figured something else :) What about using the Hash() method that
each object has.. at first you could compare hashes, if equal, do full
comparison, if not, dang, different.

Cheers
 
Back
Top