diff options
| author | Richard M. Stallman | 1992-08-02 02:34:06 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-08-02 02:34:06 +0000 |
| commit | 73183f2b6596b0f811450bafb4cc22b21e1a110d (patch) | |
| tree | 6b71ec2721714a40a8e10e45f7d1e74ef54c40e5 | |
| parent | 594722a8073be84e528f261b300aeae517655e99 (diff) | |
| download | emacs-73183f2b6596b0f811450bafb4cc22b21e1a110d.tar.gz emacs-73183f2b6596b0f811450bafb4cc22b21e1a110d.zip | |
entered into RCS
| -rw-r--r-- | lisp/emacs-lisp/ring.el | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/ring.el b/lisp/emacs-lisp/ring.el index 9951221c1d8..1e42c063d7f 100644 --- a/lisp/emacs-lisp/ring.el +++ b/lisp/emacs-lisp/ring.el | |||
| @@ -36,16 +36,18 @@ | |||
| 36 | 36 | ||
| 37 | ;;; Code: | 37 | ;;; Code: |
| 38 | 38 | ||
| 39 | (provide 'history) | 39 | (provide 'ring) |
| 40 | 40 | ||
| 41 | ;;;###autoload | ||
| 41 | (defun ring-p (x) | 42 | (defun ring-p (x) |
| 42 | "T if X is a ring; NIL otherwise." | 43 | "T if X is a ring; NIL otherwise." |
| 43 | (and (consp x) (integerp (car x)) | 44 | (and (consp x) (integerp (car x)) |
| 44 | (consp (cdr x)) (integerp (car (cdr x))) | 45 | (consp (cdr x)) (integerp (car (cdr x))) |
| 45 | (vectorp (cdr (cdr x))))) | 46 | (vectorp (cdr (cdr x))))) |
| 46 | 47 | ||
| 48 | ;;;###autoload | ||
| 47 | (defun make-ring (size) | 49 | (defun make-ring (size) |
| 48 | "Make a ring that can contain SIZE elts" | 50 | "Make a ring that can contain SIZE elts." |
| 49 | (cons 1 (cons 0 (make-vector (+ size 1) nil)))) | 51 | (cons 1 (cons 0 (make-vector (+ size 1) nil)))) |
| 50 | 52 | ||
| 51 | (defun ring-plus1 (index veclen) | 53 | (defun ring-plus1 (index veclen) |
| @@ -80,7 +82,7 @@ item to make room." | |||
| 80 | "Remove the oldest item retained on the ring." | 82 | "Remove the oldest item retained on the ring." |
| 81 | (if (ring-empty-p ring) (error "Ring empty") | 83 | (if (ring-empty-p ring) (error "Ring empty") |
| 82 | (let ((tl (car (cdr ring))) (vec (cdr (cdr ring)))) | 84 | (let ((tl (car (cdr ring))) (vec (cdr (cdr ring)))) |
| 83 | (set-car (cdr ring) (ring-minus1 tl (length vec))) | 85 | (setcar (cdr ring) (ring-minus1 tl (length vec))) |
| 84 | (aref vec tl)))) | 86 | (aref vec tl)))) |
| 85 | 87 | ||
| 86 | ;;; This isn't actually used in this package. I just threw it in in case | 88 | ;;; This isn't actually used in this package. I just threw it in in case |
| @@ -105,10 +107,10 @@ item to make room." | |||
| 105 | (aset vec hd (aref vec tl)) | 107 | (aset vec hd (aref vec tl)) |
| 106 | (setq tl (ring-minus1 tl len)) | 108 | (setq tl (ring-minus1 tl len)) |
| 107 | (setq n (- n 1)))) | 109 | (setq n (- n 1)))) |
| 108 | (set-car ring hd) | 110 | (setcar ring hd) |
| 109 | (set-car (cdr ring) tl))))) | 111 | (setcar (cdr ring) tl))))) |
| 110 | 112 | ||
| 111 | (defun comint-mod (n m) | 113 | (defun ring-mod (n m) |
| 112 | "Returns N mod M. M is positive. | 114 | "Returns N mod M. M is positive. |
| 113 | Answer is guaranteed to be non-negative, and less than m." | 115 | Answer is guaranteed to be non-negative, and less than m." |
| 114 | (let ((n (% n m))) | 116 | (let ((n (% n m))) |
| @@ -120,9 +122,8 @@ Answer is guaranteed to be non-negative, and less than m." | |||
| 120 | (let ((numelts (ring-length ring))) | 122 | (let ((numelts (ring-length ring))) |
| 121 | (if (= numelts 0) (error "indexed empty ring") | 123 | (if (= numelts 0) (error "indexed empty ring") |
| 122 | (let* ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring))) | 124 | (let* ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring))) |
| 123 | (index (comint-mod index numelts)) | 125 | (index (ring-mod index numelts)) |
| 124 | (vec-index (comint-mod (+ index hd) | 126 | (vec-index (ring-mod (+ index hd) (length vec)))) |
| 125 | (length vec)))) | ||
| 126 | (aref vec vec-index))))) | 127 | (aref vec vec-index))))) |
| 127 | 128 | ||
| 128 | ;;; ring.el ends here | 129 | ;;; ring.el ends here |