cleanup
This commit is contained in:
parent
670d584204
commit
2e803fe746
1 changed files with 11 additions and 18 deletions
23
huffman.lisp
23
huffman.lisp
|
|
@ -159,10 +159,8 @@
|
||||||
(loop for c = (read-byte instream nil nil)
|
(loop for c = (read-byte instream nil nil)
|
||||||
while c
|
while c
|
||||||
do (setq bit-stream (bitstream-push bit-stream (gethash c encoding-map)))
|
do (setq bit-stream (bitstream-push bit-stream (gethash c encoding-map)))
|
||||||
do (stream-drain-bitstream outstream bit-stream 8))
|
(stream-drain-bitstream outstream bit-stream 8))
|
||||||
(stream-drain-bitstream outstream bit-stream 1)
|
(stream-drain-bitstream outstream bit-stream 1)))))
|
||||||
)
|
|
||||||
)))
|
|
||||||
|
|
||||||
(defun decode (instream outstream)
|
(defun decode (instream outstream)
|
||||||
(let ((canon (stream2canon instream))
|
(let ((canon (stream2canon instream))
|
||||||
|
|
@ -171,19 +169,14 @@
|
||||||
do (setf (gethash (cdr pair) decoding-map) (car pair)))
|
do (setf (gethash (cdr pair) decoding-map) (car pair)))
|
||||||
(let ((len (read-number instream)) (source (cons 0 0)) (sink (cons 0 0)))
|
(let ((len (read-number instream)) (source (cons 0 0)) (sink (cons 0 0)))
|
||||||
(loop for i from 1 to len
|
(loop for i from 1 to len
|
||||||
do
|
do (loop until (gethash sink decoding-map)
|
||||||
(loop until (gethash sink decoding-map)
|
do (when (= (cdr source) 0)
|
||||||
do (progn
|
|
||||||
(when (= (cdr source) 0)
|
|
||||||
(setq source (cons (read-byte instream) 8)))
|
(setq source (cons (read-byte instream) 8)))
|
||||||
(multiple-value-bind (new-source popped) (bitstream-pop1 source)
|
(multiple-value-bind (new-source popped) (bitstream-pop1 source)
|
||||||
(setq source new-source)
|
(setq source new-source)
|
||||||
(setq sink (bitstream-push sink (cons popped 1)))))
|
(setq sink (bitstream-push sink (cons popped 1))))
|
||||||
finally (write-byte (gethash sink decoding-map) outstream)
|
finally (write-byte (gethash sink decoding-map) outstream)
|
||||||
(setq sink (cons 0 0)))
|
(setq sink (cons 0 0)))))))
|
||||||
)
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
(defmacro with-stream-translate (in-filename out-filename &body body)
|
(defmacro with-stream-translate (in-filename out-filename &body body)
|
||||||
`(with-open-file (instream ,in-filename :element-type '(unsigned-byte 8) :direction :input)
|
`(with-open-file (instream ,in-filename :element-type '(unsigned-byte 8) :direction :input)
|
||||||
|
|
@ -199,5 +192,5 @@
|
||||||
;(main (list "_" "e" "test-input.txt" "test-output.txt.hf"))
|
;(main (list "_" "e" "test-input.txt" "test-output.txt.hf"))
|
||||||
;(main (list "_" "d" "test-output.txt.hf" "test-output.txt"))
|
;(main (list "_" "d" "test-output.txt.hf" "test-output.txt"))
|
||||||
|
|
||||||
;; (setq uiop:*image-entry-point* #'main)
|
(setq uiop:*image-entry-point* #'main)
|
||||||
;; (uiop:dump-image "build/huffman" :executable t)
|
(uiop:dump-image "build/huffman" :executable t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue