Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which sorting algorithm is behind an NSSortDescriptor?

Is that thing using bubble sort? Or what exactly? How does it work in context with an NSFetchRequest of Core Data?

like image 616
dontWatchMyProfile Avatar asked Jun 08 '10 18:06

dontWatchMyProfile


1 Answers

  1. The NSSortDescriptor API does not specify the algorithm (or even, like virtually all of the Cocoa APIs, a Big-O complexity guarantee). You should assume that the sort algorithm used is an implementation detail. You should probably also assume, however, that the algorithm used is selected at run time for best performance. Unless you have hard requirements for time or memory complexity, you should use the public API and let the framework authors at Apple worry abou the details.

    If you have complexity requirements, you may find CHDataStructures framework helpful in writing your own collection/sorting implementation.

  2. For NSFetchRequest, you should again assume that it is choosing an appropriate sort algorithm. In particular, sorting will be done by the SQLite engine, if possible, when using a SQL persistent store with Core Data.

like image 116
Barry Wark Avatar answered Sep 22 '22 16:09

Barry Wark