Changeset 39728 in project


Ignore:
Timestamp:
03/17/21 00:00:25 (5 weeks ago)
Author:
Kon Lovett
Message:

elaborate queue-limited-push-back-list, fix queue-limited-index-dec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/mailbox/trunk/inline-queue.scm

    r39727 r39728  
    55;;
    66;; - Uses (chicken fixnum) & (only record-variants define-record-type-variant)
     7
     8(define-inline (fxabs n) (if (fx< n 0) (fxneg n) n))
    79
    810;; Queue Unlimited
     
    145147  (%make-queue-limited (make-vector (fx+ lm 1) (void)) 0 0) )
    146148
    147 ;circular buffer: vec[n] s <= e: s = e -> empty, s < e -> some, |e - s| = n -> full
     149;circular buffer: s <= e: s = e -> empty, |e - s| = n -> full, s < e -> some
    148150;
    149151; inc i: (i + 1)      mod n
     
    160162
    161163(define-inline (%queue-limited-index-dec q i)
    162   (fxmod (fx+ i (fx- (vector-length (%queue-limited-vector q)) 2)) (%queue-limited-limit q)) )
     164  (fxmod (fx+ i (fx- (vector-length (%queue-limited-vector q)) 1)) (%queue-limited-limit q)) )
    163165
    164166(define-inline (%queue-limited-limit-set! q v)
    165167  (error '%queue-limited-limit-set! "immutable" v) )
    166 
    167 (define-inline (fxabs n) (if (< n 0) (fxneg n) n))
    168168
    169169(define-inline (%queue-limited-count q)
     
    196196
    197197(define-inline (%queue-limited-push-back-list! q ls)
    198   ;NOTE move "down" from start to start-1; kinda like extract below
    199   (for-each (lambda (v) (%queue-limited-push-back! q v)) (reverse ls)) )
     198  ;assert enough room at the inn!
     199  ;move "down" from start to start-1; kinda like extract below
     200  (let loop ((i (%queue-limited-start q)) (ls (reverse ls)))
     201    (unless (null? ls)
     202      (let ((i-1 (%queue-limited-index-dec q i)))
     203        (%queue-limited-poke! q i-1 (car ls))
     204        (loop i-1 (cdr ls)) ) ) ) )
    200205
    201206;index
Note: See TracChangeset for help on using the changeset viewer.