From: Roland Orre <roland.orre@neurologic.se>
Subject: Re: Sort on vectors slow
Date: Thu, 14 Oct 2004 16:22:35 +0200 [thread overview]
Message-ID: <1097763755.5279.3655.camel@localhost> (raw)
On Thu, 2004-10-14 at 14:28, Roland Orre wrote:
> PS. Code to the restricted-vector-msort! below. I suggest that this
> should go into the distribution, alternatively we should replace the
> current default quicksort for vectors with merge sort.
Typical, the code I sent contained a little bug, which I hadn't
noticed as I'm usually using a temporary vector (optional arg)
supplied. So, here is a new version of restricted-vector-msort!
if anyone is interested or maybe consider it should be put into
the distribution.
/Roland
SCM_DEFINE (scm_restricted_vector_msort_x,
"restricted-vector-msort!", 4, 1, 0,
(SCM vec, SCM less, SCM startpos, SCM endpos, SCM tmpv),
"Sort the sequence @var{items}, which may be a list or a\n"
"vector. @var{less} is used for comparing the sequence elements.\n"
"The sorting is destructive, that means that the input sequence\n"
"is modified to produce the sorted result.\n"
"This is a stable sort.")
#define FUNC_NAME s_scm_restricted_vector_msort_x
{
const scm_t_trampoline_2 cmp = compare_function (less, 2, FUNC_NAME);
size_t vlen, spos, high;
if (SCM_VECTORP (vec))
{
SCM *temp;
vlen = SCM_VECTOR_LENGTH (vec);
SCM_VALIDATE_INUM_MIN_COPY (3, startpos, 0, spos);
SCM_ASSERT_RANGE (3, startpos, spos <= vlen);
SCM_VALIDATE_INUM_RANGE (4, endpos,0, vlen);
high = SCM_INUM (endpos) - spos;
/*
the following array does not contain any new references to
SCM objects, so we can get away with allocing it on the heap.
*/
if (SCM_UNBNDP(tmpv)) {
temp = scm_malloc (vlen * sizeof(SCM));
}
else
if (SCM_VECTORP(tmpv) && (SCM_VECTOR_LENGTH(tmpv) >= vlen))
{
temp = SCM_WRITABLE_VELTS(tmpv);
}
else SCM_WRONG_TYPE_ARG (5, tmpv);
scm_merge_vector_step (vec, temp, cmp, less, spos, high);
if (SCM_UNBNDP(tmpv))
free(temp);
return SCM_UNSPECIFIED;
}
else
SCM_WRONG_TYPE_ARG (1, vec);
}
#undef FUNC_NAME
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next reply other threads:[~2004-10-14 14:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-14 14:22 Roland Orre [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-10-14 12:28 Sort on vectors slow Roland Orre
2004-10-19 17:52 ` Marius Vollmer
2004-10-19 21:47 ` Marius Vollmer
2004-10-19 22:28 ` Marius Vollmer
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1097763755.5279.3655.camel@localhost \
--to=roland.orre@neurologic.se \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).