summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starling/ring-buffer.scm39
1 files changed, 11 insertions, 28 deletions
diff --git a/starling/ring-buffer.scm b/starling/ring-buffer.scm
index 2b67f78..1138755 100644
--- a/starling/ring-buffer.scm
+++ b/starling/ring-buffer.scm
@@ -5,7 +5,8 @@
ring-buffer-length
ring-buffer-put!
ring-buffer-get!
- ring-buffer-ref))
+ ring-buffer-ref
+ ring-buffer-clear!))
(define-record-type <ring-buffer>
(%make-ring-buffer vector length head tail)
@@ -52,30 +53,12 @@
(vector-ref v (modulo (+ (ring-buffer-head ring) i)
(vector-length v))))))
-;; (define (test)
-;; (define (do-test ring)
-;; (ring-buffer-put! ring 'h)
-;; (pk ring)
-;; (ring-buffer-put! ring 'e)
-;; (pk ring)
-;; (ring-buffer-put! ring 'l)
-;; (pk ring)
-;; (ring-buffer-put! ring 'l)
-;; (pk ring)
-;; (ring-buffer-put! ring 'o)
-;; (pk ring)
-;; (ring-buffer-put! ring 'w)
-;; (pk ring)
-;; (ring-buffer-put! ring 'o)
-;; (pk ring)
-;; (ring-buffer-put! ring 'r)
-;; (pk ring)
-;; (ring-buffer-put! ring 'l)
-;; (pk ring)
-;; (ring-buffer-put! ring 'd)
-;; (pk ring)
-;; (pk (ring-buffer-get! ring) (ring-buffer-get! ring) (ring-buffer-get! ring) (ring-buffer-get! ring))
-;; (pk ring))
-;; (let ((ring (make-ring-buffer 4)))
-;; (do-test ring)
-;; (do-test ring)))
+(define (ring-buffer-clear! ring)
+ (let ((l (ring-buffer-length ring))
+ (v (ring-buffer-vector ring)))
+ (set-ring-buffer-head! ring 0)
+ (set-ring-buffer-tail! ring 0)
+ (let loop ((i 0))
+ (when (< i l)
+ (vector-set! v i #f)
+ (loop (+ i 1))))))