Debian Codegraph @

%3a132/sortfaster.scm

raw symbols SCIP
1 ;;; SRFI 132 specifies these eight procedures.
2 ;;;
3 ;;; Benchmarking has shown that the (rnrs sorting) procedures
4 ;;; are faster than the sorting procedures defined by SRFI 132's
5 ;;; reference implementation, so the R6RS procedures are used here.
6 ;;;
7 ;;; This file is a plug-and-play alternative to sort.scm in the
8 ;;; same directory.
9
10 (define list-sort r6rs-list-sort)
11 (define list-sort! r6rs-list-sort)
12 (define list-stable-sort r6rs-list-sort)
13 (define list-stable-sort! r6rs-list-sort)
14
15 (define (vector-sort < v . rest)
16 (cond ((null? rest)
17 (r6rs-vector-sort < v))
18 ((null? (cdr rest))
19 (r6rs-vector-sort < (r7rs-vector-copy v (car rest))))
20 ((null? (cddr rest))
21 (r6rs-vector-sort < (r7rs-vector-copy v (car rest) (cadr rest))))
22 (else
23 (error 'vector-sort
24 "too many arguments"
25 (cons < (cons v rest))))))
26
27 (define vector-stable-sort vector-sort)
28
29 (define (vector-sort! < v . rest)
30 (cond ((null? rest)
31 (r6rs-vector-sort! < v))
32 ((null? (cdr rest))
33 (let* ((start (car rest))
34 (v2 (r7rs-vector-copy v start)))
35 (r6rs-vector-sort! < v2)
36 (r7rs-vector-copy! v start v2 0)))
37 ((null? (cddr rest))
38 (let* ((start (car rest))
39 (end (cadr rest))
40 (v2 (r7rs-vector-copy v start end)))
41 (r6rs-vector-sort! < v2)
42 (r7rs-vector-copy! v start v2 0)))
43 (else
44 (error 'vector-sort!
45 "too many arguments"
46 (cons < (cons v rest))))))
47
48 (define vector-stable-sort! vector-sort!)
49