OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [slib/] [sort.scm] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
;;; "sort.scm" Defines: sorted?, merge, merge!, sort, sort!
2
;;; Author : Richard A. O'Keefe (based on Prolog code by D.H.D.Warren)
3
 
4
;;; Modified for scheme library: Aubrey Jaffer 19 Sept. 1991
5
;;; (sorted? sequence less?)
6
 
7
;;; such that for all 1 <= i <= m,
8
;;;     (not (less? (list-ref list i) (list-ref list (- i 1)))).
9
;;; (merge a b less?)
10
;;; takes two lists a and b such that (sorted? a less?) and (sorted? b less?)
11
 
12
;;; interleaved so that (sorted? (merge a b less?) less?).
13
;;; Note:  this does _not_ accept vectors.  See below.
14
;; The loop handles the merging of non-empty lists.  It has
15
;; been written this way to save testing and car/cdring.
16
;; x <= y
17
;;; (merge! a b less?)
18
;;; takes two sorted lists a and b and smashes their cdr fields to form a
19
;;; single sorted list including the elements of both.
20
;;; Note:  this does _not_ accept vectors.
21
;; (car a) <= (car b)
22
; (car a) <= (car b)
23
;;; (sort! sequence less?)
24
;;; sorts the list or vector sequence destructively.  It uses a version
25
;;; of merge-sort invented, to the best of my knowledge, by David H. D.
26
;;; Warren, and first used in the DEC-10 Prolog system.  R. A. O'Keefe
27
;;; adapted it to work destructively in Scheme.
28
;; otherwise, assume it is a list
29
;;; (sort sequence less?)
30
 
31
 
32
;;; that the result of append is always "newly allocated" except for
33
;;; sharing structure with "the last argument", so (append x '()) ought
34
;;; to be a standard way of copying a list x.
35
;;; eof
36
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.