Skip to content

Commit

Permalink
homework2 log tree
Browse files Browse the repository at this point in the history
  • Loading branch information
saidrahmi committed May 1, 2019
1 parent e21756f commit 36d6a90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions week2/homework/LogAnalysis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ parseMessage s = case words s of
parse :: String -> [LogMessage]
parse file = map parseMessage (lines file)

{--insert :: LogMessage -> MessageTree -> MessageTree
insert message (Node l m r)
| (LogMessage _ ts _) > (getTimeStamp m) = Leaf--}
insert :: LogMessage -> MessageTree -> MessageTree
insert newmsg Leaf = Node Leaf newmsg Leaf
insert newmsg (Node left oldmsg right)
| time newmsg > time oldmsg = Node left oldmsg (insert newmsg right)
| otherwise = Node (insert newmsg left) oldmsg right
insert (Unknown _) tree = tree

getTimeStamp :: LogMessage -> Int
getTimeStamp (LogMessage _ ts _) = ts
{--timestamp :: LogMessage -> Maybe TimeStamp
timestamp (Unknown _) = Nothing
timestamp (LogMessage t _ _) = case t of
(Error _) -> Just time
Info -> Just time
Warning -> Just time--}

time :: LogMessage -> TimeStamp
time (LogMessage _ ts _) = ts
time (LogMessage (Error _) ts _) = ts

0 comments on commit 36d6a90

Please sign in to comment.