summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Util.hs9
1 files changed, 2 insertions, 7 deletions
diff --git a/Util.hs b/Util.hs
index 9c3fbf0..55c61ca 100644
--- a/Util.hs
+++ b/Util.hs
@@ -1,7 +1,6 @@
{-# LANGUAGE TupleSections #-}
module Util where
-import Data.Function (on)
import Data.List
import qualified Data.Map.Strict as Map
@@ -14,11 +13,7 @@ uniq l = l
sortUniq :: Ord a => [a] -> [a]
sortUniq = uniq . sort
-oppositeGraph :: (Show a, Ord a) => Map.Map a [a] -> Map.Map a [a]
+oppositeGraph :: Ord a => Map.Map a [a] -> Map.Map a [a]
oppositeGraph graph =
let nodes = concat [k : vs | (k, vs) <- Map.assocs graph]
- edges = map ((,) <$> fst . head <*> map snd)
- . groupBy ((==) `on` fst)
- . sortOn fst
- $ [(to, from) | (from, tos) <- Map.assocs graph, to <- tos]
- in Map.fromList (map (,[]) nodes ++ edges)
+ in Map.fromListWith (++) (map (,[]) nodes ++ [(to, [from]) | (from, tos) <- Map.assocs graph, to <- tos])