Changeset 39733 in project
- Timestamp:
- 03/17/21 01:54:57 (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release/5/mailbox/trunk/inline-queue.scm
r39732 r39733 6 6 ;; - Uses (chicken fixnum) & (only record-variants define-record-type-variant) 7 7 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)) 9 10 10 11 ;; Queue Unlimited … … 135 136 ;; Queue Limited 136 137 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 137 143 ;the identifier needs to be defined by somebody 138 144 (define queue-limited 'queue-limited) … … 145 151 146 152 (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) ) 153 156 154 157 (define-inline (%queue-limited-peek q i) (vector-ref (%queue-limited-vector q) i)) … … 158 161 (fx- (vector-length (%queue-limited-vector q)) 1) ) 159 162 163 (define-inline (%queue-limited-limit-set! q v) 164 (error '%queue-limited-limit-set! "immutable" v) ) 165 160 166 (define-inline (%queue-limited-index-inc q i) 161 167 (fxmod (fx+ i 1) (%queue-limited-limit q)) ) 162 168 163 169 (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)) ) 165 171 166 172 (define-inline (%queue-limited-start-inc! q) … … 175 181 (define-inline (%queue-limited-end-dec! q) 176 182 (%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) )180 183 181 184 (define-inline (%queue-limited-count q) … … 217 220 (loop i-1 (cdr ls)) ) ) ) ) 218 221 219 ;index220 222 (define-inline (%make-queue-limited-cursor) (cons -1 (void))) 221 223 (define-inline (%queue-limited-cursor? c) (pair? c)) … … 243 245 244 246 (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))) 245 250 #; ;assert index is end - 1 246 251 (%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))) ) 249 253 250 254 (define-inline (%queue-limited-cursor-rewind! q c)
Note: See TracChangeset
for help on using the changeset viewer.