[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting implemented in Guile standard library

From: Bill Markmann
Subject: Re: Sorting implemented in Guile standard library
Date: Sun, 16 Aug 2020 17:11:19 -0400

I'm not a guile hacker, but looking at the source for "libguile/sort.c", it
looks like quicksort:

#include "sort.h"

/* We have two quicksort variants: one for SCM (#t) arrays and one for
   typed arrays.

#define NAME        quicksort
#define INC_PARAM   ssize_t inc,
#define VEC_PARAM   SCM * ra,
#define GET(i)      ra[(i)*inc]
#define SET(i, val) ra[(i)*inc] = val
#include "quicksort.i.c"

The sort functions look like they call "s_scm_restricted_vector_sort_x",
and then in there:

  if (handle.element_type == SCM_ARRAY_ELEMENT_TYPE_SCM)
    quicksort (scm_array_handle_writable_elements (&handle) - dims[0].lbnd
* dims[0].inc,
               spos, epos, dims[0].inc, less);
    quicksorta (&handle, spos, epos, less);

I'd assume that's what is underneath (sort items less) and friends.  Just a
guess, though... :-)

On Sun, Aug 16, 2020 at 4:56 PM Zelphir Kaltstahl <> wrote:

> Hello Guile Users!
> I was checking out
> and
> noticed, that the definition of `sort` does not mention, which algorithm
> is used for sorting:
> > Sort the sequence items, which may be a list or a vector. less is used
> for comparing the sequence elements. This is not a stable sort.
> So my question is: Which algorithm is used for Guile's `sort` function?
> Regards,
> Zelphir
> --
> repositories:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]