• 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: Better sorting using threads?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Better sorting using threads?


  • Subject: Re: Better sorting using threads?
  • From: Ken Ferry <email@hidden>
  • Date: Thu, 11 Mar 2010 23:25:40 -0800

> Does Cocoa have sorted containers so that an object can be inserted in
sorted order?  If so it seems like this would be far less expensive.

Probably the best thing to do if you want this is to maintain the sort
yourself by inserting new objects in the correct position.  You can find the
position using
-[NSArray indexOfObject:inSortedRange:options:usingComparator:].  That's two
lines instead of one to add an object to an array, which is not bad.

That method is new in 10.6, but something similar has been in CoreFoundation
for a while.  CFArrayBSearchValues is usable on NSArray since CFArray is
bridged.

You can also look at -[NSArray sortedArrayHint].  The deal there is that you
extract an opaque "hint" from a sorted array, change the array, and resort
passing in the hint.  This is optimized for the case when the array is still
mostly sorted, but with some things out of place.

-Ken

On Thu, Mar 11, 2010 at 10:38 PM, Bill Bumgarner <email@hidden> wrote:

>
> On Mar 11, 2010, at 11:15 AM, Andrew James wrote:
>
> > Does Cocoa have sorted containers so that an object can be inserted in
> sorted order?  If so it seems like this would be far less expensive.
>
> Depends entirely on need.   Keeping a container sorted on insert can be
> quite expensive;  potentially considerably more expensive than doing a
> single batch sort at the end.
>
> On-the-fly sorted containers are generally only applicable when updates to
> the container will be frequently interleaved with read operations.
>
> 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
>
_______________________________________________

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

  • Follow-Ups:
    • Re: Better sorting using threads?
      • From: Gwynne Raskind <email@hidden>
References: 
 >Better sorting using threads? (From: Graham Cox <email@hidden>)
 >Re: Better sorting using threads? (From: Ken Thomases <email@hidden>)
 >Re: Better sorting using threads? (From: Ken Ferry <email@hidden>)
 >Re: Better sorting using threads? (From: Andrew James <email@hidden>)
 >Re: Better sorting using threads? (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: [MEET] CocoaHeads-NYC tonight - NSOperation
  • Next by Date: Re: NSTextView backed by core data, undo problems
  • Previous by thread: Re: Better sorting using threads?
  • Next by thread: Re: Better sorting using threads?
  • Index(es):
    • Date
    • Thread