aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-06-23 23:11:02 +0000
committerRichard M. Stallman1994-06-23 23:11:02 +0000
commit9c545670f3bd969b1876faa95d93f2a149e6cb83 (patch)
tree8aefe676eceb6c2e3dc918305b46b16e2f055a4c
parent0c287afb97d280d8fccf0fd5d78d2ae30c71b958 (diff)
downloademacs-9c545670f3bd969b1876faa95d93f2a149e6cb83.tar.gz
emacs-9c545670f3bd969b1876faa95d93f2a149e6cb83.zip
(ring-insert-at-beginning): New function.
Don't visit the file, just read it.
-rw-r--r--lisp/emacs-lisp/ring.el16
1 files changed, 14 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/ring.el b/lisp/emacs-lisp/ring.el
index 390aba93da1..ec9e88e47b6 100644
--- a/lisp/emacs-lisp/ring.el
+++ b/lisp/emacs-lisp/ring.el
@@ -51,6 +51,18 @@
51 "Make a ring that can contain SIZE elements." 51 "Make a ring that can contain SIZE elements."
52 (cons 0 (cons 0 (make-vector size nil)))) 52 (cons 0 (cons 0 (make-vector size nil))))
53 53
54(defun ring-insert-at-beginning (ring item)
55 "Add to RING the item ITEM. Add it at the front (the early end)."
56 (let* ((vec (cdr (cdr ring)))
57 (veclen (length vec))
58 (hd (car ring))
59 (ln (car (cdr ring))))
60 (setq ln (min veclen (1+ ln))
61 hd (ring-minus1 hd veclen))
62 (aset vec hd item)
63 (setcar ring hd)
64 (setcar (cdr ring) ln)))
65
54(defun ring-plus1 (index veclen) 66(defun ring-plus1 (index veclen)
55 "INDEX+1, with wraparound" 67 "INDEX+1, with wraparound"
56 (let ((new-index (+ index 1))) 68 (let ((new-index (+ index 1)))
@@ -72,8 +84,8 @@
72 (mod (1- (+ head (- ringlen index))) veclen)) 84 (mod (1- (+ head (- ringlen index))) veclen))
73 85
74(defun ring-insert (ring item) 86(defun ring-insert (ring item)
75 "Insert a new item onto the ring. If the ring is full, dump the oldest 87 "Insert onto ring RING the item ITEM, as the newest (last) item.
76item to make room." 88If the ring is full, dump the oldest item to make room."
77 (let* ((vec (cdr (cdr ring))) 89 (let* ((vec (cdr (cdr ring)))
78 (veclen (length vec)) 90 (veclen (length vec))
79 (hd (car ring)) 91 (hd (car ring))