added parallel graph-parsing, enabled profiling
This commit is contained in:
parent
6f04113745
commit
df9a0d46fd
BIN
dist/build/hgraph/hgraph
vendored
BIN
dist/build/hgraph/hgraph
vendored
Binary file not shown.
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph
vendored
BIN
dist/build/test-hgraph/test-hgraph
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
Binary file not shown.
2
dist/setup-config
vendored
2
dist/setup-config
vendored
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ executable hgraph
|
|||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
buildable: True
|
buildable: True
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
|
ghc-options: -threaded -rtsopts -eventlog
|
||||||
|
|
||||||
test-suite test-hgraph
|
test-suite test-hgraph
|
||||||
build-depends: QuickCheck -any, Stream -any, base -any,
|
build-depends: QuickCheck -any, Stream -any, base -any,
|
||||||
@ -21,4 +22,5 @@ test-suite test-hgraph
|
|||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
buildable: True
|
buildable: True
|
||||||
cpp-options: -DMAIN_FUNCTION=testMain
|
cpp-options: -DMAIN_FUNCTION=testMain
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
|
ghc-options: -threaded -rtsopts -eventlog
|
51
src/Main.hs
51
src/Main.hs
@ -29,13 +29,28 @@ import Control.Monad.Par.Scheds.Trace
|
|||||||
import qualified Data.Stream as S
|
import qualified Data.Stream as S
|
||||||
import Data.Either (lefts, rights)
|
import Data.Either (lefts, rights)
|
||||||
|
|
||||||
import Stream
|
import Stream hiding (map)
|
||||||
|
|
||||||
|
|
||||||
-- TODO: implement parser!
|
-- TODO: implement parser!
|
||||||
createGraph :: ByteString -> Either [Int] String
|
createGraph :: String -> Either [Int] String
|
||||||
createGraph _ = Left [1,2,3]
|
createGraph input = createGraph' input (Left [])
|
||||||
|
where
|
||||||
|
createGraph' :: String -> Either [Int] String -> Either [Int] String
|
||||||
|
createGraph' [] r = r
|
||||||
|
createGraph' (a:as) r =
|
||||||
|
let next = (createGraph' as r) in
|
||||||
|
case next of
|
||||||
|
Left xs ->
|
||||||
|
case a of
|
||||||
|
'0' -> Left $ 0:xs
|
||||||
|
'1' -> Left $ 1:xs
|
||||||
|
_ -> Right $ "cannot parse " ++ (a:as)
|
||||||
|
Right errstr ->
|
||||||
|
Right errstr
|
||||||
|
--createGraph input = Right $ "Parsing-error in line: " ++ input
|
||||||
|
|
||||||
|
-- TODO: not needed anymore. remove? Later use?
|
||||||
graphFolder :: [Either [Int] String] -> (Either [[Int]] String)
|
graphFolder :: [Either [Int] String] -> (Either [[Int]] String)
|
||||||
graphFolder [] = Right "empty Graph"
|
graphFolder [] = Right "empty Graph"
|
||||||
graphFolder l = graphFolder' l (Left [[]])
|
graphFolder l = graphFolder' l (Left [[]])
|
||||||
@ -60,6 +75,21 @@ graphFolder l = graphFolder' l (Left [[]])
|
|||||||
concatWith :: String -> String -> String -> String
|
concatWith :: String -> String -> String -> String
|
||||||
concatWith d a b = a ++ d ++ b
|
concatWith d a b = a ++ d ++ b
|
||||||
|
|
||||||
|
emptyLine :: String -> Bool
|
||||||
|
emptyLine "" = True
|
||||||
|
emptyLine "\n" = True
|
||||||
|
emptyLine "\r\n" = True
|
||||||
|
emptyLine "\r" = True
|
||||||
|
emptyLine _ = False
|
||||||
|
|
||||||
|
emptyLog :: [String] -> Bool
|
||||||
|
emptyLog [] = True
|
||||||
|
emptyLog a = emptyLine $ foldl1 (++) a
|
||||||
|
|
||||||
|
-- TODO: implement calculation
|
||||||
|
doCalculation :: [[Int]] -> ByteString
|
||||||
|
doCalculation a = B.pack $ (show a) ++ "\n"
|
||||||
|
|
||||||
exeMain = do
|
exeMain = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
input <- case args of
|
input <- case args of
|
||||||
@ -67,14 +97,17 @@ exeMain = do
|
|||||||
[] -> error "Error: No filename or stdinput (-) given."
|
[] -> error "Error: No filename or stdinput (-) given."
|
||||||
[file] -> B.readFile file
|
[file] -> B.readFile file
|
||||||
-- unrefined_graph::[Either [Int] String] - [Int] is Adjacency-Line, String is parse-Error
|
-- unrefined_graph::[Either [Int] String] - [Int] is Adjacency-Line, String is parse-Error
|
||||||
unrefined_graph <- return $ parMap (rparWith rdeepseq) (createGraph) (B.split '\n' input)
|
unrefined_graph <- return $ parMap (rparWith rdeepseq) --run parallel, evaluate fully
|
||||||
|
-- and filter empty lines
|
||||||
|
(createGraph) (filter (not . emptyLine)
|
||||||
|
-- split at \n, convert to String
|
||||||
|
(map B.unpack (B.split '\n' input)))
|
||||||
--egraph <- return $ graphFolder unrefined_graph
|
--egraph <- return $ graphFolder unrefined_graph
|
||||||
(graph, log) <- return (lefts unrefined_graph, rights unrefined_graph)
|
(graph, log) <- return (lefts unrefined_graph, rights unrefined_graph)
|
||||||
|
output <- return $ case emptyLog log of
|
||||||
--do stuff with graph
|
True -> doCalculation graph
|
||||||
|
_ -> B.pack $ "Error detected:\n" ++ (foldl (concatWith "\n") "" log) ++ "\n\n"
|
||||||
B.putStr $ B.pack (foldl (concatWith "\n") "" log) -- Print output
|
B.putStr output
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Entry point for unit tests.
|
-- Entry point for unit tests.
|
||||||
|
Loading…
Reference in New Issue
Block a user