Skip to content

Commit

Permalink
Sped up string compression and decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
barbuz committed Sep 18, 2017
1 parent 203809a commit d5c3dd5
Show file tree
Hide file tree
Showing 3 changed files with 749,141 additions and 749,140 deletions.
5 changes: 3 additions & 2 deletions DecompressString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ decompressString s = go "" s where
--We need to read it at runtime, otherwise compilation is too slow and memory-hungry
--dictionary = Map.fromDistinctAscList $ map read $ lines listdict where
dictionary :: [(String,String)]
dictionary = map read $lines listdict where
dictionary = map parse $lines listdict where
parse s | (first,tab:second) <- span (/='\t') s = (second,first)
listdict = unsafePerformIO $ getDict
getDict = do
path <- getExecutablePath
readFile $ replaceFileName path "dict.hs"
readFile $ replaceFileName path "dictionary.tsv"
8 changes: 4 additions & 4 deletions compressString.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.List ((\\), nub, inits)
import System.Environment (getArgs)
import Debug.Trace (trace)

type Node = (Int,[String],String)

main = do args <- getArgs
dictionary <- readFile "dict.hs"
dictionary <- readFile "dictionary.tsv"
putStr $ unlines $ compressString (head args) $ buildDict dictionary
where
buildDict text = Map.fromList $ map (swap.read) $ lines text
swap (a,b) = (b,a)
buildDict text = Map.fromList $ map splitTab $ lines text
splitTab s | (first,tab:second) <- span (/='\t') s = (first,second)

compressString :: String -> Map.Map String String -> [String]
compressString s dictionary = astar [(length s, [""],map replaceNewlines s)] where
Expand Down
Loading

0 comments on commit d5c3dd5

Please sign in to comment.