PC Review


Reply
Thread Tools Rate Thread

Comparing two bit arrays - FAST

 
 
Iain
Guest
Posts: n/a
 
      21st Feb 2005
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

 
Reply With Quote
 
 
 
 
D. Arndt
Guest
Posts: n/a
 
      21st Feb 2005
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
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing 2 arrays Nikita1984@gmail.com Microsoft Excel Worksheet Functions 3 2nd Jan 2006 02:31 AM
Comparing Arrays KL Microsoft Excel Worksheet Functions 9 3rd Dec 2004 08:58 PM
Re: Comparing to Arrays marston.gould@alaskaair.com Microsoft Excel Programming 0 31st Aug 2004 10:21 PM
Re: Comparing to Arrays marston.gould@alaskaair.com Microsoft Excel Programming 1 31st Aug 2004 08:47 PM
Re: Comparing to Arrays marston.gould@alaskaair.com Microsoft Excel Programming 0 31st Aug 2004 07:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 AM.