Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (de lzwCompress (Lst File)
- (let (Codes 65535 Dict)
- (balance 'Dict
- (make
- (for C Codes
- (link (cons (char C) C)) ) ) )
- (out File
- (let W (pop 'Lst)
- (for C Lst
- (let WC (pack W C)
- (if (lup Dict WC)
- (setq W WC)
- (printsp (cdr (lup Dict W)))
- (idx 'Dict (cons WC (inc 'Codes)) T)
- (setq W C) ) ) )
- (and W (printsp (cdr (lup Dict W)))) ) ) ) )
- (de lzwDecompress (File)
- (let (Codes 65535 Dict)
- (balance 'Dict
- (make
- (for C Codes
- (link (list C (char C))) ) ) )
- (make
- (let W NIL
- (in File
- (while (read)
- (let WC (if (lup Dict @) (cdr @) (cons (last W) W))
- (chain (reverse WC))
- (when W
- (idx 'Dict (cons (inc 'Codes) (cons (last WC) W)) T) )
- (setq W WC) ) ) ) ) ) ) )
- NIL
- : (lzwCompress (chop "TOBEORNOTTOBEORTOBEORNOT") "a")
- -> 65543
- : (in "a" (echo))
- 84 79 66 69 79 82 78 79 84 65536 65538 65540 65545 65539 65541 65543 -> T
- : (pack (lzwDecompress "a"))
- -> "TOBEORNOTTOBEORTOBEORNOT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement