• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Comparing arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing arrays


  • Subject: Re: Comparing arrays
  • From: "Daniele Corti" <email@hidden>
  • Date: Mon, 11 Jun 2007 09:39:46 +0200



2007/6/11, Michelle Parker <email@hidden>:
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.

For this you should try to convert each of them in String, then reconvert into NSArray using NSPropertyListSerialization.arrayFromString(String), this shuold create arrays with the same objects.
 

NSArray.removeObjectWithArray or NSSet.subtractSet don't work because
the objects are not equal.

The arrays can be very large, ie. 100,000 objects.

What is the best way to handle this?

Look if you don't reach using that, I think the only way is to check each element controlling the value of every object. I can give you a solution to execute this in linear time m+n (where m is the length of the first array, and m the length of the second).

A = {your first Array: length = m}
B = {your second Array: length = n}
i=0, j=0
while i <m AND j <n do
   if A[i] = B[j] then
      remove(A, i)
      i++
   Elseif A[i] > B[j]
      j++
   Else
      i++
   End if
End

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: email@hidden

hope this help!

--
Daniele Corti
AIM: S0CR4TE5
Messenger: email@hidden
 _______________________________________________
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

  • Follow-Ups:
    • Re: Comparing arrays
      • From: "Jerry W. Walker" <email@hidden>
References: 
 >Comparing arrays (From: Michelle Parker <email@hidden>)

  • Prev by Date: Re: Problem with deleting a related object (to-many relationship)
  • Next by Date: Re: WO 4.5 on NT & Env Vars
  • Previous by thread: Comparing arrays
  • Next by thread: Re: Comparing arrays
  • Index(es):
    • Date
    • Thread