Plaster
New
List
Login
common-lisp
default
anonymous
2021.12.02 01:59:19
(defun bitmap (predicate) (let ((bitmap (make-array char-code-limit :initial-element 0 :element-type 'bit))) (loop for n below char-code-limit for c = (code-char n) when (and (not (null n)) (funcall predicate c)) do (setf (bit bitmap n) 1)) bitmap)) (defun compress-end (bitmap) (values (subseq bitmap 0 (position 1 bitmap :from-end t)) (position 1 bitmap :from-end t))) (defun compress-pages (bitmap page-size) (coerce (loop for n below (length bitmap) by page-size for p = (subseq bitmap n (min (length bitmap) (+ n page-size))) collect (cond ((every (alexandria:curry #'= 1) p) 't) ((every (alexandria:curry #'= 0) p) 'nil) (t p))) 'vector)) (defun size (page-map) (+ (* 8 (length page-map)) ; 8 bytes/pointer (loop for page across page-map when (vectorp page) sum (/ (length page) 8)))) ; 8 bits/byte (loop for n in '(8 16 32 64 128 256 512 1024 2048 4096 8192 16384) collect (list n (size (compress-pages (compress-end (bitmap #'alphanumericp)) n))))
Raw
Annotate
Repaste
Edit