Handbook
Glossary
(generate-codes) ( huff-tree -- code-dict )
Vocabulary
compression
.
huffman
.
private
Inputs
huff-tree
an
object
Outputs
code-dict
an
object
Definition
USING:
accessors
assocs
bit-arrays
combinators
hashtables
kernel
sequences
;
IN:
compression.huffman.private
:
(generate-codes)
( huff-tree -- code-dict )
{
{
[
dup
leaf?
]
[
code>>
?{
}
swap
H{
}
clone
?set-at
]
}
{
[
dup
left>>
not
]
[
right>>
(generate-codes)
[
?{
t
}
prepend
]
assoc-map
]
}
{
[
dup
right>>
not
]
[
left>>
(generate-codes)
[
?{
f
}
prepend
]
assoc-map
]
}
[
[
left>>
(generate-codes)
[
?{
f
}
prepend
]
assoc-map
]
[
right>>
(generate-codes)
[
?{
t
}
prepend
]
assoc-map
]
bi
assoc-union!
]
}
cond
;