Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun bit-array-serialize (bit-array)
- (format nil "~S~%~:{~A*~A~:^ ~}~%"
- (array-dimensions bit-array)
- (bit-vector-rle (make-array (reduce (function *) (array-dimensions bit-array))
- :displaced-to bit-array))))
- (bit-array-serialize (make-sparse-bit-array '(100 200 50) 1/10000))
- (defun bit-array-deserialize (data)
- (with-input-from-string (*standard-input* data)
- (let ((dimensions (read)))
- (check-type dimensions list)
- (assert (every (function integerp) dimensions))
- (let* ((bit-array (make-array dimensions :element-type 'bit :initial-element 0))
- (bit-vector (make-array (reduce (function *) dimensions) :displaced-to bit-array)))
- (loop
- :for run := (read *standard-input* nil)
- :while run
- :do (let ((srun (string run)))
- (multiple-value-bind (start star) (parse-integer srun :junk-allowed t)
- (let ((length (parse-integer srun :start (1+ star))))
- (fill bit-vector 1 :start start :end (+ start length))))))
- bit-array))))
- (let ((small-bit-array (make-sparse-bit-array '(4 5 6) 1/10)))
- (assert (equalp small-bit-array (bit-array-deserialize (bit-array-serialize small-bit-array)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement