• 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: a mild sorting annoyance?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a mild sorting annoyance?


  • Subject: Re: a mild sorting annoyance?
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 18 Nov 2002 18:53:59 -0800

On Monday, November 18, 2002, at 03:22 PM, Steve Mykytyn wrote:

The sorting methods available for NSMutableArray (e.g sortUsingFunction) do not appear to be "stable" - that is, they don't preserve the previous order of elements with identical values after a sort. The documentation does not say, and the list archive does not appear to have touched on this issue.

This would be of value, for example, if you had a list of all cities and towns in the USA and wanted to sort it by city name, but if there were two cities with the same name, you would want them in order by state. If the sort were stable, you could simply sort first by state, then by city name and you would be OK. This does not appear to be the case with NSMutableArray - you would have to decide by evaluating both city name and state yourself.

Having a stable sort makes life easier in some situations...

Is this worth a bug report? Or did i miss something here???

I wouldn't call it a bug. If you return NSOrderedSame, I'd say it's fair to insert the two elements in question in either order. It sounds like in your situation, they're not *really* the same. For the example you give, your compare method should check both criteria.

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: a mild sorting annoyance?
      • From: Ondra Cada <email@hidden>
References: 
 >a mild sorting annoyance? (From: Steve Mykytyn <email@hidden>)

  • Prev by Date: Re: Weirdness with NSTableView's scroll bars
  • Next by Date: Re: Is Objective-C loaded?
  • Previous by thread: a mild sorting annoyance?
  • Next by thread: Re: a mild sorting annoyance?
  • Index(es):
    • Date
    • Thread