unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* bug in sort.c
@ 2004-10-14 12:07 Roland Orre
  2004-10-19 14:33 ` Marius Vollmer
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Orre @ 2004-10-14 12:07 UTC (permalink / raw)


The following two lines in scm_restricted_vector_sort_x
are wrong:

  SCM_VALIDATE_INUM_RANGE (4, endpos,0, vlen+1);
  len = SCM_INUM (endpos) - spos;

they should be:

  SCM_VALIDATE_INUM_RANGE (4, endpos,0, vlen);
  len = SCM_INUM (endpos) - spos + 1;

at least to be consistent with the documentation. Apart from that
I've found that quicksort is extremely slow for vectors and am now
using a merge sort also for vectors. (It's me having put that code
ther earlier and I'll look into why it is slow, but quicksort worst
case complexity is O(N^2), in average O(N log N) but merge sort
is always O(N log N) as I understand so it may be correct, but I'll
post the suggested restricted_vector_msort_x on the guile-user.

	Best regards
	Roland Orre





_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: bug in sort.c
  2004-10-14 12:07 bug in sort.c Roland Orre
@ 2004-10-19 14:33 ` Marius Vollmer
  0 siblings, 0 replies; 2+ messages in thread
From: Marius Vollmer @ 2004-10-19 14:33 UTC (permalink / raw)
  Cc: guile-devel

Roland Orre <roland.orre@neurologic.se> writes:

> The following two lines in scm_restricted_vector_sort_x
> are wrong:
>
>   SCM_VALIDATE_INUM_RANGE (4, endpos,0, vlen+1);
>   len = SCM_INUM (endpos) - spos;
>
> they should be:
>
>   SCM_VALIDATE_INUM_RANGE (4, endpos,0, vlen);
>   len = SCM_INUM (endpos) - spos + 1;

I think the code is correct: we need to have

    0 <= startpos <= endpos <= vlen

The element with index endpos is not included in the sort, thus we
will sort

    len = endpos - spos

elements.

The docstring needs to be clearer about this, tho.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-19 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-14 12:07 bug in sort.c Roland Orre
2004-10-19 14:33 ` Marius Vollmer

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).