September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import Data.List
|
||||
import Control.Arrow
|
||||
import Data.Ord
|
||||
import Data.List (group, insertBy, sort, sortBy)
|
||||
import Control.Arrow ((&&&), second)
|
||||
import Data.Ord (comparing)
|
||||
|
||||
data HTree a
|
||||
= Leaf a
|
||||
|
|
@ -10,7 +10,7 @@ data HTree a
|
|||
|
||||
test :: String -> IO ()
|
||||
test =
|
||||
mapM_ (\(a, b) -> putStrLn ('\'' : a : "\' : " ++ b)) .
|
||||
mapM_ (\(a, b) -> putStrLn ('\'' : a : ("' : " ++ b))) .
|
||||
serialize . huffmanTree . freq
|
||||
|
||||
serialize :: HTree a -> [(a, String)]
|
||||
|
|
@ -23,7 +23,7 @@ huffmanTree
|
|||
=> [(w, a)] -> HTree a
|
||||
huffmanTree =
|
||||
snd .
|
||||
head . until (null . tail) hstep . sortBy (comparing fst) . (second Leaf <$>)
|
||||
head . until (null . tail) hstep . sortBy (comparing fst) . fmap (second Leaf)
|
||||
|
||||
hstep
|
||||
:: (Ord a, Num a)
|
||||
|
|
@ -34,4 +34,7 @@ hstep ((w1, t1):(w2, t2):wts) =
|
|||
freq
|
||||
:: Ord a
|
||||
=> [a] -> [(Int, a)]
|
||||
freq = ((length &&& head) <$>) . group . sort
|
||||
freq = fmap (length &&& head) . group . sort
|
||||
|
||||
main :: IO ()
|
||||
main = test "this is an example for huffman encoding"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
*Main> test "this is an example for huffman encoding"
|
||||
'p' : 00000
|
||||
'r' : 00001
|
||||
'g' : 00010
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue