(bytevector-u8-ref b2 index))
(loop (fix:+ index 1))))))))
+(define (bytevector<? b1 b2)
+ (let ((l1 (bytevector-length b1))
+ (l2 (bytevector-length b2)))
+ (let ((end (fix:min l1 l2)))
+ (let loop ((index 0))
+ (if (fix:< index end)
+ (let ((u1 (bytevector-u8-ref b1 index))
+ (u2 (bytevector-u8-ref b2 index)))
+ (if (fix:= u1 u2)
+ (loop (fix:+ index 1))
+ (fix:< u1 u2)))
+ (fix:< l1 l2))))))
+
;; String hash primitives work on bytevectors too.
(define (bytevector-hash bytevector #!optional modulus)
(if (default-object? modulus)
(bytevector-copy bv 11 22)
bv1))))))
+(define-test 'bytevector<?
+ (lambda ()
+ (let ((lists (random-byte-lists 16 64)))
+ (for-each (lambda (l1)
+ (for-each (lambda (l2)
+ (assert-eqv (bytevector<? (bytes->bv l1)
+ (bytes->bv l2))
+ (byte-list<? l1 l2)))
+ lists))
+ lists))))
+
+(define (byte-list<? l1 l2)
+ (if (and (pair? l1) (pair? l2))
+ (if (fix:= (car l1) (car l2))
+ (byte-list<? (cdr l1) (cdr l2))
+ (fix:< (car l1) (car l2)))
+ (and (null? l1)
+ (not (null? l2)))))
+
(define (build-bytevector objects)
(let ((builder (bytevector-builder)))
(for-each builder objects)
(let ((start* (fix:+ start n)))
(if (fix:<= start* end)
(loop start* (cons (bytevector-copy bv start start*) bvs))
- (reverse! bvs))))))
\ No newline at end of file
+ (reverse! bvs))))))
+
+(define (random-byte-lists n max-length)
+ (map (lambda (i)
+ (declare (ignore i))
+ (random-byte-list max-length))
+ (iota n)))
+
+(define (random-byte-list max-length)
+ (map (lambda (i)
+ (declare (ignore i))
+ (random #x100))
+ (iota (random (+ max-length 1)))))
\ No newline at end of file