Re: Comparing arrays
Re: Comparing arrays
- Subject: Re: Comparing arrays
- From: Q <email@hidden>
- Date: Mon, 11 Jun 2007 23:34:31 +1000
On 11/06/2007, at 3:34 PM, Michelle Parker wrote:
Hi all
I have a slight problem which I am looking for the most efficient
solution:
I am comparing 2 NSArrays containing numbers, with the aim of
removing the numbers in one array from the other array.
The first array is obtained by rawRowsForSQL which returns the
numbers as Longs.
The second array is obtained by valueForKeyPath which returns the
numbers as Integers.
NSArray.removeObjectWithArray or NSSet.subtractSet don't work
because the objects are not equal.
The arrays can be very large, ie. 100,000 objects.
The most efficient approach would be to do something like this:
Assuming array1 is an array of <Integer>, and array2 is an array of
<Long>
NSMutableSet set1 = new NSMutableSet(array1);
for (int i = 0; i < array2.count(); i++) {
set1.removeObject(new Integer( ((Long)(array2.objectAtIndex
(i))).intValue() ) );
}
array1 = set1.allObjects();
Assuming you don't need to preserve the order or cardinality of array1.
What is the best way to handle this?
thanks
mich
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
--
Seeya...Q
Quinton Dolan - email@hidden
Gold Coast, QLD, Australia
Ph: +61 419 729 806
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden