473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 5668
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
1
by: Iain | last post by:
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...
12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
2
by: Robert Linder | last post by:
I am trying to compare arraylists in csharp. I setup a simple test with empty arraylists. string x1 = {}; string x2 = {}; Console.WriteLine( x1 == x2 ); // false...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
1
by: Donald Grove | last post by:
If I have two arrays, what is a good paradigm for comparing what is in them, to determine what elements they share, or don't share? Specifically, each array could potentially contain the integers...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
1
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.