changeset 8031:4b45aa6d5d76

(ring-insert-at-beginning): New function. Don't visit the file, just read it.
author Richard M. Stallman <rms@gnu.org>
date Thu, 23 Jun 1994 23:11:02 +0000
parents d5d12df7b186
children 936532a595dd
files lisp/emacs-lisp/ring.el
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/ring.el	Thu Jun 23 21:35:48 1994 +0000
+++ b/lisp/emacs-lisp/ring.el	Thu Jun 23 23:11:02 1994 +0000
@@ -51,6 +51,18 @@
   "Make a ring that can contain SIZE elements."
   (cons 0 (cons 0 (make-vector size nil))))
 
+(defun ring-insert-at-beginning (ring item)
+  "Add to RING the item ITEM.  Add it at the front (the early end)."
+  (let* ((vec (cdr (cdr ring))) 
+	 (veclen (length vec))
+	 (hd (car ring))
+	 (ln (car (cdr ring))))
+    (setq ln (min veclen (1+ ln))
+	  hd (ring-minus1 hd veclen))
+    (aset vec hd item)
+    (setcar ring hd)
+    (setcar (cdr ring) ln)))
+
 (defun ring-plus1 (index veclen)
   "INDEX+1, with wraparound"
   (let ((new-index (+ index 1)))
@@ -72,8 +84,8 @@
   (mod (1- (+ head (- ringlen index))) veclen))
 
 (defun ring-insert (ring item)
-  "Insert a new item onto the ring. If the ring is full, dump the oldest
-item to make room."       
+  "Insert onto ring RING the item ITEM, as the newest (last) item.
+If the ring is full, dump the oldest item to make room."       
   (let* ((vec (cdr (cdr ring))) 
 	 (veclen (length vec))
 	 (hd (car ring))