From: David Kastrup <dak@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Change Emacs 'sort' API to use three-way comparison
Date: Fri, 29 Aug 2014 23:51:56 +0200 [thread overview]
Message-ID: <87wq9rm0ar.fsf@fencepost.gnu.org> (raw)
In-Reply-To: 5400EE70.8050207@cs.ucla.edu
Paul Eggert <eggert@cs.ucla.edu> writes:
> One infelicity I noticed in the recent change to 'sort' in the trunk
> is that the new implementation calls its predicate twice for each
> comparison. This is because the Lisp API says the comparison function
> returns a boolean (nil or non-nil), whereas qsort_r wants the
> comparison function to return a ternary value (-1, 0, or 1). If the
> predicate is expensive, the new Fsort can be twice as slow as the old.
> We could tune it but I don't see how to get it any faster than 1.5x
> slower than before, assuming random input and an expensive comparison
> function.
Can someone give an executive summary why we would be using a "qsort_r"
here?
"sort" sorts a list. There is really not much of a point in not using a
mergesort here, resulting in a stable sort and requiring only a binary
comparison function.
Quicksorts make sense when sorting arrays.
--
David Kastrup
next prev parent reply other threads:[~2014-08-29 21:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-29 10:46 [Emacs-diffs] trunk r117765: Add vectors support to Fsort Eli Zaretskii
2014-08-29 14:21 ` Jordon Biondo
2014-08-29 15:41 ` Dmitry Antipov
2014-08-29 15:50 ` Jordon Biondo
2014-08-29 16:34 ` Dmitry Antipov
2014-08-29 16:43 ` Jordon Biondo
2014-08-29 18:31 ` Stefan Monnier
2014-08-29 22:53 ` Dmitry Antipov
2014-08-31 0:18 ` Richard Stallman
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
2014-08-29 21:51 ` David Kastrup [this message]
2014-08-30 14:23 ` Lars Ingebrigtsen
2014-08-30 16:45 ` Paul Eggert
2014-08-30 18:07 ` Lars Ingebrigtsen
2014-08-30 18:14 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wq9rm0ar.fsf@fencepost.gnu.org \
--to=dak@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).