Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Huffman-coding/PicoLisp/huffman-coding.l
Normal file
18
Task/Huffman-coding/PicoLisp/huffman-coding.l
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(de prio (Idx)
|
||||
(while (cadr Idx) (setq Idx @))
|
||||
(car Idx) )
|
||||
|
||||
(let (A NIL P NIL L NIL)
|
||||
(for C (chop "this is an example for huffman encoding")
|
||||
(accu 'A C 1) ) # Count characters
|
||||
(for X A # Build index tree as priority queue
|
||||
(idx 'P (cons (cdr X) (car X)) T) )
|
||||
(while (or (cadr P) (cddr P)) # Remove entries, insert as nodes
|
||||
(let (A (car (idx 'P (prio P) NIL)) B (car (idx 'P (prio P) NIL)))
|
||||
(idx 'P (cons (+ (car A) (car B)) A B) T) ) )
|
||||
(setq P (car P))
|
||||
(recur (P L) # Traverse and print
|
||||
(if (atom (cdr P))
|
||||
(prinl (cdr P) " " L)
|
||||
(recurse (cadr P) (cons 0 L))
|
||||
(recurse (cddr P) (cons 1 L)) ) ) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue