Changeset 39733 in project


Ignore:
Timestamp:
03/17/21 01:54:57 (3 months ago)
Author:
Kon Lovett
Message:

set limited-cursor in cont

File:
1 edited

Legend:

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

    r39732 r39733  
    66;; - Uses (chicken fixnum) & (only record-variants define-record-type-variant)
    77
    8 (define-inline (fxabs n) (if (fx< n 0) (fxneg n) n))
     8(define-inline (fxneg? n) (fx< n 0))
     9(define-inline (fxabs n) (if (fxneg? n) (fxneg n) n))
    910
    1011;; Queue Unlimited
     
    135136;; Queue Limited
    136137
     138;circular buffer: s <= e: s = e -> empty, |e - s| = n -> full, s < e -> some
     139;
     140; inc i: (i + 1)      mod n
     141; dec i: (i + (n-1))  mod n
     142
    137143;the identifier needs to be defined by somebody
    138144(define queue-limited 'queue-limited)
     
    145151
    146152(define-inline (%make-empty-queue-limited lm)
    147   (%make-queue-limited (make-vector (fx+ lm 1) (void)) 0 0) )
    148 
    149 ;circular buffer: s <= e: s = e -> empty, |e - s| = n -> full, s < e -> some
    150 ;
    151 ; inc i: (i + 1)      mod n
    152 ; dec i: (i + (n-1))  mod n
     153  ;limit of 2 is lower-bound otherwise always s = e!
     154  ;limit + 1 so
     155  (%make-queue-limited (make-vector (fx+ (fxmax 2 lm) 1) (void)) 0 0) )
    153156
    154157(define-inline (%queue-limited-peek q i)    (vector-ref (%queue-limited-vector q) i))
     
    158161  (fx- (vector-length (%queue-limited-vector q)) 1) )
    159162
     163(define-inline (%queue-limited-limit-set! q v)
     164  (error '%queue-limited-limit-set! "immutable" v) )
     165
    160166(define-inline (%queue-limited-index-inc q i)
    161167  (fxmod (fx+ i 1) (%queue-limited-limit q)) )
    162168
    163169(define-inline (%queue-limited-index-dec q i)
    164   (fxmod (fx+ i (fx- (vector-length (%queue-limited-vector q)) 1)) (%queue-limited-limit q)) )
     170  (fxmod (fx+ i (fx- (%queue-limited-limit q) 1)) (%queue-limited-limit q)) )
    165171
    166172(define-inline (%queue-limited-start-inc! q)
     
    175181(define-inline (%queue-limited-end-dec! q)
    176182  (%queue-limited-end-set! q (%queue-limited-index-dec q (%queue-limited-end q))) )
    177 
    178 (define-inline (%queue-limited-limit-set! q v)
    179   (error '%queue-limited-limit-set! "immutable" v) )
    180183
    181184(define-inline (%queue-limited-count q)
     
    217220        (loop i-1 (cdr ls)) ) ) ) )
    218221
    219 ;index
    220222(define-inline (%make-queue-limited-cursor) (cons -1 (void)))
    221223(define-inline (%queue-limited-cursor? c) (pair? c))
     
    243245
    244246(define-inline (%queue-limited-cursor-continue! q c)
     247  ;#; ;assert index is end - 1
     248  (%queue-limited-cursor-index-set! c
     249    (%queue-limited-index-dec q (%queue-limited-cursor-index c)))
    245250  #; ;assert index is end - 1
    246251  (%queue-limited-cursor-index-set! c
    247     (%queue-limited-index-dec q (%queue-limited-end q)))
    248   (void) )
     252    (%queue-limited-index-dec q (%queue-limited-end q))) )
    249253
    250254(define-inline (%queue-limited-cursor-rewind! q c)
Note: See TracChangeset for help on using the changeset viewer.