This commit is contained in:
WickedJack99
2024-01-21 16:54:03 +01:00
parent f82a356d1b
commit fb6935996b
31 changed files with 373 additions and 129 deletions

View File

@@ -43,7 +43,7 @@ getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir ::
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath
bindir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/bin"
libdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7/huffman-0.1-5hb8DvQH04kAhx22YvzXdK"
libdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7/huffman-0.1-FYSjga9JLF2kZjOZ6zeLt"
dynlibdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7"
datadir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/share/x86_64-linux-ghc-9.4.7/huffman-0.1"
libexecdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/libexec/x86_64-linux-ghc-9.4.7/huffman-0.1"

View File

@@ -153,10 +153,10 @@
#endif /* MIN_TOOL_VERSION_strip */
#ifndef CURRENT_PACKAGE_KEY
#define CURRENT_PACKAGE_KEY "huffman-0.1-5hb8DvQH04kAhx22YvzXdK"
#define CURRENT_PACKAGE_KEY "huffman-0.1-FYSjga9JLF2kZjOZ6zeLt"
#endif /* CURRENT_packageKey */
#ifndef CURRENT_COMPONENT_ID
#define CURRENT_COMPONENT_ID "huffman-0.1-5hb8DvQH04kAhx22YvzXdK"
#define CURRENT_COMPONENT_ID "huffman-0.1-FYSjga9JLF2kZjOZ6zeLt"
#endif /* CURRENT_COMPONENT_ID */
#ifndef CURRENT_PACKAGE_VERSION
#define CURRENT_PACKAGE_VERSION "0.1"

View File

@@ -43,7 +43,7 @@ getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir ::
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath
bindir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/bin"
libdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7/huffman-0.1-7oGsPwnMV4MIdxe92R26Zp-huffman-exe"
libdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7/huffman-0.1-23WUwl30C5UEHpdRSzT9lV-huffman-exe"
dynlibdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/lib/x86_64-linux-ghc-9.4.7"
datadir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/share/x86_64-linux-ghc-9.4.7/huffman-0.1"
libexecdir = "/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/.stack-work/install/x86_64-linux-tinfo6/bb0f3fab2049fedb4cba85d10a24b16a5e25afd3bd9adda8ddc0b2b676ff0e27/9.4.7/libexec/x86_64-linux-ghc-9.4.7/huffman-0.1"

View File

@@ -123,7 +123,7 @@
#endif /* MIN_TOOL_VERSION_strip */
#ifndef CURRENT_COMPONENT_ID
#define CURRENT_COMPONENT_ID "huffman-0.1-7oGsPwnMV4MIdxe92R26Zp-huffman-exe"
#define CURRENT_COMPONENT_ID "huffman-0.1-23WUwl30C5UEHpdRSzT9lV-huffman-exe"
#endif /* CURRENT_COMPONENT_ID */
#ifndef CURRENT_PACKAGE_VERSION
#define CURRENT_PACKAGE_VERSION "0.1"

View File

@@ -11,6 +11,6 @@
/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/src/Auxiliaries.hs:
hash: 5a404af397ad51d6d268ac0a318157dd9511d113c3fbfce35cc238d42974425f
/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/src/Huffman.hs:
hash: d08ec104d6db27dc13b5222e3c828e0c3ba8b0074350a3d0ffb298a0d7bd78b1
hash: c379eba92ecb90bbd210add96734d89b196535d973d68cbdb8f9c7195284211f
/usr/include/stdc-predef.h:
hash: d6bcc58441a423bbb3a52171fcd3b84d8b36e332a55221a1c3e6e899bc43ccb3

View File

@@ -9,6 +9,6 @@
/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/package.yaml:
hash: e9fcddf7857388c0e51188152e25a1d446e2e46628ed45552bdc3b635472171c
/home/a/Documents/Repositories/Anwendungsentwicklung_Haskell/Aufgabe_6/code/test/Tests.hs:
hash: 3ca5e27b2088e7a3ceff11746da999127e42a43fcb9431650eca06c193634c15
hash: d146588effdec1312dbcdc1609a1293ad40f1b8f14cea6b19181cbfa13e499cc
/usr/include/stdc-predef.h:
hash: d6bcc58441a423bbb3a52171fcd3b84d8b36e332a55221a1c3e6e899bc43ccb3

View File

@@ -0,0 +1,299 @@
/* DO NOT EDIT: This file is automatically generated by Cabal */
/* package huffman-0.1 */
#ifndef VERSION_huffman
#define VERSION_huffman "0.1"
#endif /* VERSION_huffman */
#ifndef MIN_VERSION_huffman
#define MIN_VERSION_huffman(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 1 || \
(major1) == 0 && (major2) == 1 && (minor) <= 0)
#endif /* MIN_VERSION_huffman */
/* package base-4.17.2.0 */
#ifndef VERSION_base
#define VERSION_base "4.17.2.0"
#endif /* VERSION_base */
#ifndef MIN_VERSION_base
#define MIN_VERSION_base(major1,major2,minor) (\
(major1) < 4 || \
(major1) == 4 && (major2) < 17 || \
(major1) == 4 && (major2) == 17 && (minor) <= 2)
#endif /* MIN_VERSION_base */
/* package binary-0.8.9.1 */
#ifndef VERSION_binary
#define VERSION_binary "0.8.9.1"
#endif /* VERSION_binary */
#ifndef MIN_VERSION_binary
#define MIN_VERSION_binary(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 8 || \
(major1) == 0 && (major2) == 8 && (minor) <= 9)
#endif /* MIN_VERSION_binary */
/* package bytestring-0.11.5.2 */
#ifndef VERSION_bytestring
#define VERSION_bytestring "0.11.5.2"
#endif /* VERSION_bytestring */
#ifndef MIN_VERSION_bytestring
#define MIN_VERSION_bytestring(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 11 || \
(major1) == 0 && (major2) == 11 && (minor) <= 5)
#endif /* MIN_VERSION_bytestring */
/* package containers-0.6.7 */
#ifndef VERSION_containers
#define VERSION_containers "0.6.7"
#endif /* VERSION_containers */
#ifndef MIN_VERSION_containers
#define MIN_VERSION_containers(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 6 || \
(major1) == 0 && (major2) == 6 && (minor) <= 7)
#endif /* MIN_VERSION_containers */
/* package filepath-1.4.2.2 */
#ifndef VERSION_filepath
#define VERSION_filepath "1.4.2.2"
#endif /* VERSION_filepath */
#ifndef MIN_VERSION_filepath
#define MIN_VERSION_filepath(major1,major2,minor) (\
(major1) < 1 || \
(major1) == 1 && (major2) < 4 || \
(major1) == 1 && (major2) == 4 && (minor) <= 2)
#endif /* MIN_VERSION_filepath */
/* tool gcc-13.2.0 */
#ifndef TOOL_VERSION_gcc
#define TOOL_VERSION_gcc "13.2.0"
#endif /* TOOL_VERSION_gcc */
#ifndef MIN_TOOL_VERSION_gcc
#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
(major1) < 13 || \
(major1) == 13 && (major2) < 2 || \
(major1) == 13 && (major2) == 2 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_gcc */
/* tool ghc-9.4.7 */
#ifndef TOOL_VERSION_ghc
#define TOOL_VERSION_ghc "9.4.7"
#endif /* TOOL_VERSION_ghc */
#ifndef MIN_TOOL_VERSION_ghc
#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_ghc */
/* tool ghc-pkg-9.4.7 */
#ifndef TOOL_VERSION_ghc_pkg
#define TOOL_VERSION_ghc_pkg "9.4.7"
#endif /* TOOL_VERSION_ghc_pkg */
#ifndef MIN_TOOL_VERSION_ghc_pkg
#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_ghc_pkg */
/* tool haddock-2.27.0 */
#ifndef TOOL_VERSION_haddock
#define TOOL_VERSION_haddock "2.27.0"
#endif /* TOOL_VERSION_haddock */
#ifndef MIN_TOOL_VERSION_haddock
#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 27 || \
(major1) == 2 && (major2) == 27 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_haddock */
/* tool hpc-0.68 */
#ifndef TOOL_VERSION_hpc
#define TOOL_VERSION_hpc "0.68"
#endif /* TOOL_VERSION_hpc */
#ifndef MIN_TOOL_VERSION_hpc
#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_hpc */
/* tool hsc2hs-0.68.8 */
#ifndef TOOL_VERSION_hsc2hs
#define TOOL_VERSION_hsc2hs "0.68.8"
#endif /* TOOL_VERSION_hsc2hs */
#ifndef MIN_TOOL_VERSION_hsc2hs
#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 8)
#endif /* MIN_TOOL_VERSION_hsc2hs */
/* tool pkg-config-2.0.2 */
#ifndef TOOL_VERSION_pkg_config
#define TOOL_VERSION_pkg_config "2.0.2"
#endif /* TOOL_VERSION_pkg_config */
#ifndef MIN_TOOL_VERSION_pkg_config
#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 0 || \
(major1) == 2 && (major2) == 0 && (minor) <= 2)
#endif /* MIN_TOOL_VERSION_pkg_config */
/* tool runghc-9.4.7 */
#ifndef TOOL_VERSION_runghc
#define TOOL_VERSION_runghc "9.4.7"
#endif /* TOOL_VERSION_runghc */
#ifndef MIN_TOOL_VERSION_runghc
#define MIN_TOOL_VERSION_runghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_runghc */
/* tool strip-2.41 */
#ifndef TOOL_VERSION_strip
#define TOOL_VERSION_strip "2.41"
#endif /* TOOL_VERSION_strip */
#ifndef MIN_TOOL_VERSION_strip
#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 41 || \
(major1) == 2 && (major2) == 41 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_strip */
#ifndef CURRENT_PACKAGE_KEY
#define CURRENT_PACKAGE_KEY "huffman-0.1-5hb8DvQH04kAhx22YvzXdK"
#endif /* CURRENT_packageKey */
#ifndef CURRENT_COMPONENT_ID
#define CURRENT_COMPONENT_ID "huffman-0.1-5hb8DvQH04kAhx22YvzXdK"
#endif /* CURRENT_COMPONENT_ID */
#ifndef CURRENT_PACKAGE_VERSION
#define CURRENT_PACKAGE_VERSION "0.1"
#endif /* CURRENT_PACKAGE_VERSION */
#undef CURRENT_PACKAGE_KEY
#undef CURRENT_COMPONENT_ID
/* DO NOT EDIT: This file is automatically generated by Cabal */
/* package huffman-0.1 */
#ifndef VERSION_huffman
#define VERSION_huffman "0.1"
#endif /* VERSION_huffman */
#ifndef MIN_VERSION_huffman
#define MIN_VERSION_huffman(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 1 || \
(major1) == 0 && (major2) == 1 && (minor) <= 0)
#endif /* MIN_VERSION_huffman */
/* package base-4.17.2.0 */
#ifndef VERSION_base
#define VERSION_base "4.17.2.0"
#endif /* VERSION_base */
#ifndef MIN_VERSION_base
#define MIN_VERSION_base(major1,major2,minor) (\
(major1) < 4 || \
(major1) == 4 && (major2) < 17 || \
(major1) == 4 && (major2) == 17 && (minor) <= 2)
#endif /* MIN_VERSION_base */
/* package huffman-0.1 */
#ifndef VERSION_huffman
#define VERSION_huffman "0.1"
#endif /* VERSION_huffman */
#ifndef MIN_VERSION_huffman
#define MIN_VERSION_huffman(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 1 || \
(major1) == 0 && (major2) == 1 && (minor) <= 0)
#endif /* MIN_VERSION_huffman */
/* tool gcc-13.2.0 */
#ifndef TOOL_VERSION_gcc
#define TOOL_VERSION_gcc "13.2.0"
#endif /* TOOL_VERSION_gcc */
#ifndef MIN_TOOL_VERSION_gcc
#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
(major1) < 13 || \
(major1) == 13 && (major2) < 2 || \
(major1) == 13 && (major2) == 2 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_gcc */
/* tool ghc-9.4.7 */
#ifndef TOOL_VERSION_ghc
#define TOOL_VERSION_ghc "9.4.7"
#endif /* TOOL_VERSION_ghc */
#ifndef MIN_TOOL_VERSION_ghc
#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_ghc */
/* tool ghc-pkg-9.4.7 */
#ifndef TOOL_VERSION_ghc_pkg
#define TOOL_VERSION_ghc_pkg "9.4.7"
#endif /* TOOL_VERSION_ghc_pkg */
#ifndef MIN_TOOL_VERSION_ghc_pkg
#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_ghc_pkg */
/* tool haddock-2.27.0 */
#ifndef TOOL_VERSION_haddock
#define TOOL_VERSION_haddock "2.27.0"
#endif /* TOOL_VERSION_haddock */
#ifndef MIN_TOOL_VERSION_haddock
#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 27 || \
(major1) == 2 && (major2) == 27 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_haddock */
/* tool hpc-0.68 */
#ifndef TOOL_VERSION_hpc
#define TOOL_VERSION_hpc "0.68"
#endif /* TOOL_VERSION_hpc */
#ifndef MIN_TOOL_VERSION_hpc
#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_hpc */
/* tool hsc2hs-0.68.8 */
#ifndef TOOL_VERSION_hsc2hs
#define TOOL_VERSION_hsc2hs "0.68.8"
#endif /* TOOL_VERSION_hsc2hs */
#ifndef MIN_TOOL_VERSION_hsc2hs
#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 8)
#endif /* MIN_TOOL_VERSION_hsc2hs */
/* tool pkg-config-2.0.2 */
#ifndef TOOL_VERSION_pkg_config
#define TOOL_VERSION_pkg_config "2.0.2"
#endif /* TOOL_VERSION_pkg_config */
#ifndef MIN_TOOL_VERSION_pkg_config
#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 0 || \
(major1) == 2 && (major2) == 0 && (minor) <= 2)
#endif /* MIN_TOOL_VERSION_pkg_config */
/* tool runghc-9.4.7 */
#ifndef TOOL_VERSION_runghc
#define TOOL_VERSION_runghc "9.4.7"
#endif /* TOOL_VERSION_runghc */
#ifndef MIN_TOOL_VERSION_runghc
#define MIN_TOOL_VERSION_runghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 4 || \
(major1) == 9 && (major2) == 4 && (minor) <= 7)
#endif /* MIN_TOOL_VERSION_runghc */
/* tool strip-2.41 */
#ifndef TOOL_VERSION_strip
#define TOOL_VERSION_strip "2.41"
#endif /* TOOL_VERSION_strip */
#ifndef MIN_TOOL_VERSION_strip
#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 41 || \
(major1) == 2 && (major2) == 41 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_strip */
#ifndef CURRENT_COMPONENT_ID
#define CURRENT_COMPONENT_ID "huffman-0.1-7oGsPwnMV4MIdxe92R26Zp-huffman-exe"
#endif /* CURRENT_COMPONENT_ID */
#ifndef CURRENT_PACKAGE_VERSION
#define CURRENT_PACKAGE_VERSION "0.1"
#endif /* CURRENT_PACKAGE_VERSION */
#undef CURRENT_PACKAGE_KEY
#undef CURRENT_COMPONENT_ID

View File

@@ -5,7 +5,7 @@ id: huffman-0.1-FYSjga9JLF2kZjOZ6zeLt
key: huffman-0.1-FYSjga9JLF2kZjOZ6zeLt
license: BSD-3-Clause
synopsis: huffman
abi: 109d1f676886f1fb02e4494eaa1e8634
abi: d6e2e1ad747b11372ae1e946a349112f
exposed: True
exposed-modules: Auxiliaries Huffman
hidden-modules: Paths_huffman

Binary file not shown.

View File

@@ -3,4 +3,7 @@ Aaron Adrian
Aaron Adrian
Aaron Adrian
Aaron Adrian
Aaron Adrian
Aaron Adrian
Aaron Adrian
Aaron Adrian

Binary file not shown.

Binary file not shown.

View File

@@ -6,8 +6,6 @@ import Data.Maybe (fromMaybe)
import Data.Char (toUpper)
import qualified Data.IntMap.Strict as IntMap
import System.IO
import Data.List (maximumBy, minimumBy)
import Text.Printf (printf)
type IntMap = IntMap.IntMap
type Map = Map.Map
@@ -20,6 +18,15 @@ type CodingTable = Map Char [Bit]
data Node = Leaf Char Int | Inner Node Node Int deriving (Show)
newtype HTree = Root Node deriving (Show)
getFrequency :: HTree -> Int
getFrequency (Root tree) =
case tree of
Leaf _ frequency -> frequency
Inner _ _ frequency -> frequency
getNode :: HTree -> Node
getNode (Root node) = node
exercise1TreeValid :: HTree
exercise1TreeValid = Root (Inner (Inner (Leaf 'E' 158) (Inner (Leaf 'N' 97) (Leaf 'I' 82) 179) 337) (Inner (Inner (Leaf 'R' 77) (Leaf 'S' 67) 144) (Inner (Leaf 'T' 64) (Leaf 'A' 61) 125) 269) 606)
@@ -166,7 +173,7 @@ instance Eq HTree where
buildHTree :: String -> HTree
buildHTree input =
let charFrequencyMap = combineFrequencies (addOccurences input)
in toHTree (toHTreeIntMap (toHTreeNodes charFrequencyMap)) (Root (Leaf 'A' 0))
in toHTree (toHTreeIntMap (toHTreeNodes charFrequencyMap))
--map ['r','a','i','n','a'] becomes [('r',1),('a',1),('i',1),('n',1),('a',1)]
addOccurences :: String -> [(Char,Int)]
@@ -184,86 +191,43 @@ toHTreeNodes frequenciesMap =
toHTreeIntMap :: [(Int, [HTree])] -> IntMap [HTree]
toHTreeIntMap = IntMap.fromListWith (++)
toHTree :: IntMap [HTree] -> HTree -> HTree
toHTree map lastTree =
let Root lastTreeRoot = lastTree
in case lastTreeRoot of
Leaf _ lastTreeRootFrequency ->
case IntMap.minView map of
Just (minimums, newMap) ->
case minimums of
[] -> toHTree newMap lastTree
[x] ->
let Root xRoot = x
in case xRoot of
Leaf _ xFrequency ->
if lastTreeRootFrequency == 0
then toHTree newMap x
else if lastTreeRootFrequency < xFrequency
then toHTree newMap (Root (Inner lastTreeRoot xRoot (lastTreeRootFrequency + xFrequency)))
else toHTree newMap (Root (Inner xRoot lastTreeRoot (lastTreeRootFrequency + xFrequency)))
Inner _ _ xFrequency ->
if lastTreeRootFrequency == 0
then toHTree newMap x
else if lastTreeRootFrequency < xFrequency
then toHTree newMap (Root (Inner lastTreeRoot xRoot (lastTreeRootFrequency + xFrequency)))
else toHTree newMap (Root (Inner xRoot lastTreeRoot (lastTreeRootFrequency + xFrequency)))
(x:y:rest) ->
let Root xRoot = x
Root yRoot = y
in case xRoot of
Leaf _ xFrequency ->
if lastTreeRootFrequency == 0
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner xRoot yRoot (xFrequency * 2)))
else if lastTreeRootFrequency < xFrequency
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner lastTreeRoot (Inner xRoot yRoot (xFrequency * 2)) (lastTreeRootFrequency + (xFrequency * 2))))
else toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner (Inner xRoot yRoot (xFrequency * 2)) lastTreeRoot (lastTreeRootFrequency + (xFrequency * 2))))
Inner _ _ xFrequency ->
if lastTreeRootFrequency == 0
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner xRoot yRoot (xFrequency * 2)))
else if lastTreeRootFrequency < xFrequency
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner lastTreeRoot (Inner xRoot yRoot (xFrequency * 2)) (lastTreeRootFrequency + (xFrequency * 2))))
else toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner (Inner xRoot yRoot (xFrequency * 2)) lastTreeRoot (lastTreeRootFrequency + (xFrequency * 2))))
_ -> lastTree
Inner _ _ lastTreeRootFrequency ->
case IntMap.minView map of
Just (minimums, newMap) ->
case minimums of
[] -> toHTree newMap lastTree
[x] ->
let Root xRoot = x
in case xRoot of
Leaf _ xFrequency ->
if lastTreeRootFrequency < xFrequency
then toHTree newMap (Root (Inner lastTreeRoot xRoot (lastTreeRootFrequency + xFrequency)))
else toHTree newMap (Root (Inner xRoot lastTreeRoot (lastTreeRootFrequency + xFrequency)))
Inner _ _ xFrequency ->
if lastTreeRootFrequency < xFrequency
then toHTree newMap (Root (Inner lastTreeRoot xRoot (lastTreeRootFrequency + xFrequency)))
else toHTree newMap (Root (Inner xRoot lastTreeRoot (lastTreeRootFrequency + xFrequency)))
(x:y:rest) ->
let Root xRoot = x
Root yRoot = y
in case xRoot of
Leaf _ xFrequency ->
if lastTreeRootFrequency < xFrequency
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner lastTreeRoot (Inner xRoot yRoot (xFrequency * 2)) (lastTreeRootFrequency + (xFrequency * 2))))
else toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner (Inner xRoot yRoot (xFrequency * 2)) lastTreeRoot (lastTreeRootFrequency + (xFrequency * 2))))
Inner _ _ xFrequency ->
if lastTreeRootFrequency < xFrequency
then toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner lastTreeRoot (Inner xRoot yRoot (xFrequency * 2)) (lastTreeRootFrequency + (xFrequency * 2))))
else toHTree (IntMap.insert xFrequency rest newMap) (Root (Inner (Inner xRoot yRoot (xFrequency * 2)) lastTreeRoot (lastTreeRootFrequency + (xFrequency * 2))))
_ -> lastTree
intMapAaron :: IntMap [HTree]
intMapAaron = IntMap.fromListWith (++) [(1,[Root (Leaf 'A' 1)]),(1,[Root (Leaf 'a' 1)]),(1,[Root (Leaf 'r' 1)]),(1,[Root (Leaf 'o' 1)]),(1,[Root (Leaf 'n' 1)])]
intMapB :: IntMap [HTree]
intMapB = IntMap.fromListWith (++) [(3,[Root (Leaf 'A' 3)]),(1,[Root (Leaf 'a' 1)]),(1,[Root (Leaf 'r' 1)]),(2,[Root (Leaf 'o' 2)]),(4,[Root (Leaf 'n' 4)])]
toHTree :: IntMap [HTree] -> HTree
toHTree map =
case IntMap.minView map of
Just (minimums, newMap) ->
case minimums of
[] ->
if IntMap.size newMap > 0
then toHTree newMap
else (Root (Leaf 'A' 0))
[x] ->
case IntMap.minView newMap of
Just (minimums2, newMap2) ->
case minimums2 of
[] -> x
(y:rest) -> toHTree (IntMap.insertWith (++) (getFrequency x + getFrequency y) [Root (Inner (getNode x) (getNode y) (getFrequency x + getFrequency y))] (IntMap.insertWith (++) (getFrequency y) rest newMap2))
_ -> x
(x:y:rest) ->
toHTree (IntMap.insertWith (++) (getFrequency x + getFrequency y) [Root (Inner (getNode x) (getNode y) (getFrequency x + getFrequency y))] (IntMap.insertWith (++) (getFrequency x) rest newMap))
_ -> case IntMap.maxView map of
Just (maximums, _) -> head maximums
_ -> (Root (Leaf ' ' 0))
-----------------------------------------------------------------------
-- Aufgabe 7 Test
-----------------------------------------------------------------------
treeAaron :: HTree
treeAaron = Root (Inner (Leaf 'A' 1) (Inner (Inner (Leaf 'n' 1) (Leaf 'a' 1) 2) (Inner (Leaf 'r' 1) (Leaf 'o' 1) 2) 4) 5)
treeAaron = Root (Inner (Inner (Leaf 'r' 1) (Leaf 'o' 1) 2) (Inner (Leaf 'A' 1) (Inner (Leaf 'n' 1) (Leaf 'a' 1) 2) 3) 5)
treeMISSISSIPPI :: HTree
treeMISSISSIPPI = Root (Inner (Inner (Leaf 'M' 1) (Leaf 'P' 2) 3) (Inner (Leaf 'S' 4) (Leaf 'I' 4) 8) 11)
treeMISSISSIPPI = Root (Inner (Leaf 'I' 4) (Inner (Inner (Leaf 'M' 1) (Leaf 'P' 2) 3) (Leaf 'S' 4) 7) 11)
treeAAABC :: HTree
treeAAABC = Root (Inner (Inner (Leaf 'C' 1) (Leaf 'B' 1) 2) (Leaf 'A' 3) 5)
@@ -272,42 +236,26 @@ treeAAABC = Root (Inner (Inner (Leaf 'C' 1) (Leaf 'B' 1) 2) (Leaf 'A' 3) 5)
-- Aufgabe 8
-----------------------------------------------------------------------
--type CodingTable = Map Char [Bit]
type Depth = Int
toDecodeTree :: CodingTable -> HTree
toDecodeTree table =
let listWithDepth = (codingListToCodingListWithDepth (codingTableToList table))
listWithDepthInverted = invertDepths listWithDepth (getMinimumDepth listWithDepth) (getMaximumDepth listWithDepth)
in buildHTree (depthListToString listWithDepthInverted)
toDecodeTree table = foldl1 mergeTrees $ map (uncurry partTree) (Map.toList table)
depthListToString :: [(Char, Depth)] -> String
depthListToString list =
case list of
[] -> ""
((char, depth):rest) -> (replicate depth char) ++ depthListToString rest
partTree :: Char -> [Bit] -> HTree
partTree char bits =
case bits of
[] -> Root (Leaf char 0)
(x:rest) ->
let next = partTree char rest in
case x of
Zero -> Root (Inner (getNode next) (Leaf 'e' 1) 0)
One -> Root (Inner (Leaf 'e' 1) (getNode next) 0)
invertDepths :: [(Char, Depth)] -> Depth -> Depth -> [(Char, Depth)]
invertDepths list minDepth maxDepth = map (\(char, depth) -> (char, (minDepth + maxDepth - depth))) list
codingTableToList :: CodingTable -> [(Char, [Bit])]
codingTableToList table = Map.toList table
codingListToCodingListWithDepth :: [(Char, [Bit])] -> [(Char, Depth)]
codingListToCodingListWithDepth tableList =
map (\(char, bitList) -> (char, length bitList)) tableList
getMaximumDepth :: [(Char, Depth)] -> Depth
getMaximumDepth = (\(_, d) -> d) . maximumBy compareByDepth
getMinimumDepth :: [(Char, Depth)] -> Depth
getMinimumDepth = (\(_, d) -> d) . minimumBy compareByDepth
compareByDepth :: (Char, Depth) -> (Char, Depth) -> Ordering
compareByDepth (_, depth1) (_, depth2)
| depth1 < depth2 = LT
| depth1 > depth2 = GT
| otherwise = EQ
mergeTrees :: HTree -> HTree -> HTree
mergeTrees (Root (Leaf char1 0)) (Root (Leaf char2 0)) = Root (Inner (Leaf char1 0) (Leaf char2 0) 0)
mergeTrees (Root (Leaf char 0)) (Root (Leaf 'e' 1)) = Root (Leaf char 0)
mergeTrees (Root (Leaf 'e' 1)) (Root (Leaf char 0)) = Root (Leaf char 0)
mergeTrees (Root (Inner left1 right1 _)) (Root (Inner left2 right2 _)) = Root (Inner (getNode (mergeTrees (Root left1) (Root left2))) (getNode (mergeTrees (Root right1) (Root right2))) 0)
mergeTrees (Root (Leaf _ _)) right = right
mergeTrees left (Root (Leaf _ _)) = left
-----------------------------------------------------------------------
-- Aufgabe 8 Test
@@ -317,7 +265,7 @@ testCodingTable :: CodingTable
testCodingTable = Map.fromList [('E', [Zero,Zero]), ('N', [Zero,One,Zero]), ('I', [Zero,One,One]), ('R', [One,Zero,Zero]), ('S', [One,Zero,One]), ('T', [One,One,Zero]), ('A', [One,One,One])]
testCodingTableHTree :: HTree
testCodingTableHTree = Root (Inner (Leaf 'E' 3) (Inner (Inner (Leaf 'I' 2) (Leaf 'A' 2) 4) (Inner (Inner (Leaf 'R' 2) (Leaf 'N' 2) 4) (Inner (Leaf 'T' 2) (Leaf 'S' 2) 4) 8) 12) 15)
testCodingTableHTree = Root (Inner (Inner (Leaf 'E' 0) (Inner (Leaf 'N' 0) (Leaf 'I' 0) 0) 0) (Inner (Inner (Leaf 'R' 0) (Leaf 'S' 0) 0) (Inner (Leaf 'T' 0) (Leaf 'A' 0) 0) 0) 0)
-----------------------------------------------------------------------
-- Aufgabe 9
@@ -331,11 +279,7 @@ encodeFile input output =
codingTable = toCodingTable htree
encodedContent = encode codingTable inputContent
fileContent = FileContent {fc_codingTable = (map (\(char, bitList) -> (char, Bitlist bitList)) (Map.toList codingTable)), fc_content = (Bitlist encodedContent)}
in do
printf ("\n" ++ show htree ++ "\n")
--printf (show codingTable ++ "\n")
--printf (show encodedContent ++ "\n")
binaryToFile output fileContent
in do binaryToFile output fileContent
decodeFile :: FilePath -> FilePath -> IO ()
decodeFile input output = do
@@ -344,9 +288,7 @@ decodeFile input output = do
encodedContent = fc_content fileContent
decodeTree = toDecodeTree (Map.fromList (map (\(char, Bitlist bitList) -> (char, bitList)) codingTable))
decodedString = decode decodeTree (bitlistToList encodedContent)
in do
printf ("\n" ++ show decodeTree)
withFile output WriteMode (\handle -> do hPutStr handle decodedString)
in do withFile output WriteMode (\handle -> do hPutStr handle decodedString)
bitlistToList :: Bitlist -> [Bit]
bitlistToList (Bitlist bits) = bits

View File

@@ -37,7 +37,7 @@ test_buildHTree = do
assertEqual "test buildHTree" treeMISSISSIPPI (buildHTree "MISSISSIPPI")
assertEqual "test buildHTree" treeAaron (buildHTree "Aaron")
assertEqual "test buildHTree" treeAAABC (buildHTree "AAABC")
assertEqual "test buildHTree" (Root (Leaf 'A' 0)) (buildHTree "")
assertEqual "test buildHTree" (Root (Leaf ' ' 0)) (buildHTree "")
assertEqual "test buildHTree" (Root (Leaf 'A' 1)) (buildHTree "A")
test_toDecodeTree :: IO ()
@@ -48,9 +48,9 @@ test_toFromWord8 :: IO ()
test_toFromWord8 = pure ()
test_encodeDecodeFile :: IO ()
test_encodeDecodeFile = do
_ <- encodeFile "Aaron.txt" "Aaron.comp"
decodeFile "Aaron.comp" "Aaron2.txt"
test_encodeDecodeFile = pure() --do
--_ <- encodeFile "hitchhiker.txt" "hitchhiker.comp"
-- decodeFile "hitchhiker.comp" "hitchhiker2.txt"
allTests :: Test
allTests =