Doing this type of comparison is always a little awkward. Effectively,
you're trying to see if, given 2 sets, whether the intersection of the two
sets is identical to both sets individually (I'm thinking in terms of Venn
Diagrams here). I don't know if the elements of each set have to be in the
same order or not. Generally, when dealing with sets as an abstract concept,
its not an issue.
Given that: I've read 3 or 4 different ways that this cam be acomplished.
None of then are really as efficient as I think we'd all like for them to be
because you have to do a member by member comparison of each element in the
sets..here's the one I use in .NET..
Lets say I have 2 Sets A and B (Collections, Arrays, or some other class
that implements an aggregation)
1) if the sets have different numbers of items, the sets are not equal.
2) create an Int32 array (arrA) the same size as Set A
3) Populate the Array with the Hash Codes of all of the members of Set A
4) For each member of Set B
a) get the member's HashCode
b) Do a BinarySearch of arrA to see if there's a matching Hash Code
c) if there is not, then the sets are not equal
5) if you got through step 4 without any problems, then the sets must be
equal (you already checked to see if the sets were of the same size)
Granted, I always override GetHashCode on the classes I create, so I know
that the hases will correctly Reflect state equivelance in my classes.
"Jim Andersen" wrote:
David Jessee wrote:
What are these arrays of (what type)?
I actually start out by having the data in 2 datatables. One column is
system.string the other is system.byte
/jim