From 9cbd38561213763dbbcefdfabd1519369d442113 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 17 Mar 2019 23:04:36 +0100 Subject: added info about cache hit and simple haskell for sorting by line-length --- freedomain/Lookup.hs | 10 ++++++---- freedomain/sorti.hs | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100755 freedomain/sorti.hs (limited to 'freedomain') diff --git a/freedomain/Lookup.hs b/freedomain/Lookup.hs index ecaba49..413f80b 100644 --- a/freedomain/Lookup.hs +++ b/freedomain/Lookup.hs @@ -82,14 +82,16 @@ domainChecker :: [String -> IO Bool] -> MVar [String] -> MVar [(Bool,String)] domainChecker chk mvin mvout cache = nxtDom >>= \dom -> when (dom/="") $ do c<-readMVar cache - r<-case M.lookup dom c of - Just xx-> return xx + (r,ch)<-case M.lookup dom c of + Just xx-> return (xx,True) Nothing-> do x<-multiCheck chk dom addCache x dom - return x + return (x,False) outDom r dom - putStrLn $ dom ++ " " ++ (if r then "[\ESC[31m\STXTaken\ESC[m\STX]" else "[\ESC[32m\STXFree\ESC[m\STX]") + putStrLn $ dom ++ " " + ++ (if r then "[\ESC[31m\STXTaken\ESC[m\STX]" else "[\ESC[32m\STXFree\ESC[m\STX]") + ++ (if ch then " (\ESC[34m\STXcache hit\ESC[m\STX)" else "") domainChecker chk mvin mvout cache where outDom res dom =modifyMVar mvout $ \d -> diff --git a/freedomain/sorti.hs b/freedomain/sorti.hs new file mode 100755 index 0000000..3c3f8cd --- /dev/null +++ b/freedomain/sorti.hs @@ -0,0 +1,7 @@ +#!/usr/bin/env stack +-- stack --resolver lts-12.5 script + +import Data.List +import Data.Function + +main = interact $ unlines . sortBy (compare `on` length) . lines -- cgit v1.2.3