470,836 Members | 1,913 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,836 developers. It's quick & easy.

Comparing two bit arrays - FAST

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

Nov 22 '05 #1
1 5386
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

Iain schrieb:
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

Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Peter | last post: by
1 post views Thread by Iain | last post: by
12 posts views Thread by Elijah Bailey | last post: by
4 posts views Thread by agent349 | last post: by
41 posts views Thread by Odd-R. | last post: by
2 posts views Thread by Robert Linder | last post: by
6 posts views Thread by Dennis | last post: by
1 post views Thread by Donald Grove | last post: by
19 posts views Thread by Ole Nielsby | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.