From: Andreas Ericsson <ae@op5.se>
To: GIT Mailing List <git@vger.kernel.org>
Subject: Re: type_size_sort
Date: Tue, 06 Dec 2005 22:38:39 +0100 [thread overview]
Message-ID: <439604DF.5010603@op5.se> (raw)
In-Reply-To: <118833cc0512061319l3726fdfbs8286e7b3f5ab0713@mail.gmail.com>
Morten Welinder wrote:
> static int type_size_sort(const struct object_entry *a, const struct
> object_entry *b)
> {
> ...
> return a < b ? -1 : (a > b);
> }
>
> This does not look valid. the standard says you must not depend on the
> location:
>
>
> [#4] When the same objects (consisting of size bytes,
> irrespective of their current positions in the array) are
> passed more than once to the comparison function, the
> results shall be consistent with one another. That is, for
> qsort they shall define a total ordering on the array, and
> for bsearch the same object shall always compare the same
> way with the key.
>
It's perfectly correct. If the same list was to be passed to
create_sorted_list() twice it will come out exactly the same the second
time as it did the first. The only thing to remark on is that the return
above could be written as below instead:
return a - b;
--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
next prev parent reply other threads:[~2005-12-06 21:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-06 21:19 type_size_sort Morten Welinder
2005-12-06 21:38 ` Andreas Ericsson [this message]
2005-12-06 21:46 ` type_size_sort Junio C Hamano
2005-12-07 0:51 ` type_size_sort Morten Welinder
2005-12-07 2:28 ` type_size_sort Junio C Hamano
2005-12-07 3:01 ` type_size_sort Morten Welinder
2005-12-06 21:45 ` type_size_sort Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=439604DF.5010603@op5.se \
--to=ae@op5.se \
--cc=git@vger.kernel.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.
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 NNTP newsgroup(s).