Sorting algorithm(s) used by PHP's sort function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shaunak Kashyap

    Sorting algorithm(s) used by PHP's sort function

    Does anyone know what sorting algorithm(s) -- quicksort, mergesort,
    radix sort, etc. -- does PHP use internally in its sort function?
  • Zac Hester

    #2
    Re: Sorting algorithm(s) used by PHP's sort function

    "Shaunak Kashyap" <skashyap@inter techmedia.com> wrote in message
    news:67746bb.03 07241733.63a564 9f@posting.goog le.com...[color=blue]
    > Does anyone know what sorting algorithm(s) -- quicksort, mergesort,
    > radix sort, etc. -- does PHP use internally in its sort function?[/color]

    There's a lot of sorting algorithms used by PHP. It looks like the primary
    array sorting method is quicksort. I also found some use of mergesort.
    Looking at the source, I found this:

    <builddirectory >/ext/standard/array.c

    This sets up the "hooks" for most of the array functions for use in Zend.

    It looks like all of the sort methods rely on a sort_type == zend_qsort.
    Doing a quick search for this in the rest of the source, returns this:

    <builddirectory >/Zend/zend_qsort.c

    If you look at this file, you can see the good ol' quick sort algorithm in
    action. If you prefer a different algorithm, I'm sure you could replace the
    quicksort algorithm, recompile PHP, and whammo!

    If you're interested in developing extensions to PHP, the API is pretty well
    documented in the manual and in "Programmin g PHP" by Rasmus Lerdorf. I wish
    I had the time to tinker with PHP at this level.

    Take care,
    Zac


    Comment

    Working...