Created
March 24, 2019 16:42
-
-
Save nrdmn/9ab36e302c2ae26f7017d2c8e3ee68d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.HashMap.Strict as M | |
import qualified Data.ByteString.Char8 as B | |
import Data.List (sortOn) | |
import Data.List.Split (chunksOf) | |
import Control.Parallel.Strategies (parMap, rdeepseq) | |
main = do | |
words <- B.words <$> B.getContents | |
let result = sortOn snd $ M.toList $ foldl (M.unionWith (+)) M.empty $ parMap rdeepseq (foldl (\acc x -> M.insertWith (+) x (1 :: Integer) acc) M.empty) (chunksOf 50000 words) | |
B.putStr . B.concat $ result >>= (\(a,b) -> [B.pack $ show b, B.singleton '\t', a, B.singleton '\n']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment