A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
31
Task/LZW-compression/PicoLisp/lzw-compression.l
Normal file
31
Task/LZW-compression/PicoLisp/lzw-compression.l
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
(de lzwCompress (Lst)
|
||||
(let (Codes 255 Dict)
|
||||
(balance 'Dict
|
||||
(make
|
||||
(for C Codes
|
||||
(link (cons (char C) C)) ) ) )
|
||||
(make
|
||||
(let W (pop 'Lst)
|
||||
(for C Lst
|
||||
(let WC (pack W C)
|
||||
(if (lup Dict WC)
|
||||
(setq W WC)
|
||||
(link (cdr (lup Dict W)))
|
||||
(idx 'Dict (cons WC (inc 'Codes)) T)
|
||||
(setq W C) ) ) )
|
||||
(and W (link (cdr (lup Dict W)))) ) ) ) )
|
||||
|
||||
(de lzwDecompress (Lst)
|
||||
(let (Codes 255 Dict)
|
||||
(balance 'Dict
|
||||
(make
|
||||
(for C Codes
|
||||
(link (list C (char C))) ) ) )
|
||||
(make
|
||||
(let W NIL
|
||||
(for N Lst
|
||||
(let WC (if (lup Dict N) (cdr @) (cons (last W) W))
|
||||
(chain (reverse WC))
|
||||
(when W
|
||||
(idx 'Dict (cons (inc 'Codes) (cons (last WC) W)) T) )
|
||||
(setq W WC) ) ) ) ) ) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue