Re: NSMutableArray comparator; sorting on insert
Re: NSMutableArray comparator; sorting on insert
- Subject: Re: NSMutableArray comparator; sorting on insert
- From: Bill Bumgarner <email@hidden>
- Date: Fri, 16 Jan 2009 08:44:42 -0800
On Jan 16, 2009, at 8:27 AM, David Harper wrote:
I have written a comparator that returns an NSComparisonResult based
on the comparison of two objects as required for
[(NSMutableArray *)someArray
sortUsingSelector:@selector(theSelector:)]
Now, I want this array to remain sorted after each insert. For now
I am inserting, then sorting, but this is not ideal. Is there a way
to perform an insert using the same selector to find the correct
index before inserting?
In short, No.
You could use the selector to loop and insert. Just call the selector
and check the comparison result return value.
HOWEVER, why do you want to keep the array in order? Have you
quantified a real performance issue that you need to address?
Are you accessing the contents of the array after every insertion?
How many items are in the array?
Have you measured to see whether adding-at-end-and-sorting is faster/
slower than insertion-in-middle-or-beginning? Often, an insertion may
be slow as the array has to move stuff around. But sorting can often
be done in place.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden