int-like 0.1.1 → 0.1.2
raw patch · 9 files changed
+36/−30 lines, 9 filesdep ~algebraic-graphssetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: algebraic-graphs
API changes (from Hackage documentation)
Files
- README.md +0/−2
- Setup.hs +0/−2
- int-like.cabal +4/−4
- src/IntLike/Equiv.hs +5/−3
- src/IntLike/Graph.hs +8/−6
- src/IntLike/Map.hs +3/−2
- src/IntLike/MultiMap.hs +6/−3
- src/IntLike/Set.hs +7/−5
- test/Main.hs +3/−3
README.md view
@@ -1,7 +1,5 @@ # int-like -[](https://circleci.com/gh/ejconlon/int-like/tree/master)- Newtype wrappers over `IntSet` and `IntMap` Never mix up `Int` newtypes again! Instead of working directly with an `IntSet`, you can work with `IntLikeSet MyIntNewtype` with more or less the same API. You might have to thread through some `Coercible` constraints, though.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
int-like.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack name: int-like-version: 0.1.1+version: 0.1.2 synopsis: Newtype wrappers over IntSet and IntMap description: Please see the README on GitHub at <https://github.com/ejconlon/int-like#readme> category: Data Structures@@ -63,7 +63,7 @@ TypeFamilies ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -fno-warn-unused-top-binds -fwrite-ide-info -hiedir=.hie build-depends:- algebraic-graphs >=0.5 && <0.7+ algebraic-graphs ==0.7.* , base >=4.12 && <5 , containers ==0.6.* , deepseq ==1.4.*@@ -105,7 +105,7 @@ TypeFamilies ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -fno-warn-unused-top-binds -fwrite-ide-info -hiedir=.hie -threaded -rtsopts -with-rtsopts=-N build-depends:- algebraic-graphs >=0.5 && <0.7+ algebraic-graphs ==0.7.* , base >=4.12 && <5 , containers ==0.6.* , deepseq ==1.4.*
src/IntLike/Equiv.hs view
@@ -9,7 +9,8 @@ , partialInsert , member , lookupClass- ) where+ )+where import Control.DeepSeq (NFData) import Data.Coerce (Coercible)@@ -23,8 +24,9 @@ data IntLikeEquiv k v = IntLikeEquiv { fwdView :: !(IntLikeMultiMap k v) , bwdView :: !(IntLikeMap v k)- } deriving stock (Eq, Show, Generic)- deriving anyclass (NFData)+ }+ deriving stock (Eq, Show, Generic)+ deriving anyclass (NFData) empty :: IntLikeEquiv k v empty = IntLikeEquiv ILMM.empty ILM.empty
src/IntLike/Graph.hs view
@@ -7,7 +7,8 @@ , reachable , Component (..) , undirectedComponents- ) where+ )+where import Algebra.Graph.AdjacencyIntMap (AdjacencyIntMap) import qualified Algebra.Graph.AdjacencyIntMap as AdjacencyIntMap@@ -25,7 +26,7 @@ import IntLike.Set (IntLikeSet (..)) import qualified IntLike.Set as ILS -newtype IntLikeGraph x = IntLikeGraph { unIntLikeGraph :: AdjacencyIntMap }+newtype IntLikeGraph x = IntLikeGraph {unIntLikeGraph :: AdjacencyIntMap} deriving newtype (Eq, Show, NFData) instance Coercible x Int => Graph (IntLikeGraph x) where@@ -52,15 +53,16 @@ {-# INLINE fromUndirectedEdges #-} reachable :: Coercible x Int => x -> IntLikeGraph x -> [x]-reachable x = coerce . AIMA.reachable (coerce x) . unIntLikeGraph+reachable x = coerce . flip AIMA.reachable (coerce x) . unIntLikeGraph {-# INLINE reachable #-} -newtype Component = Component { unComponent :: Int }+newtype Component = Component {unComponent :: Int} deriving stock (Show) deriving newtype (Eq, Ord, Enum, Hashable, NFData) undirectedComponents :: Coercible x Int => [(x, x)] -> IntLikeEquiv Component x-undirectedComponents es = go 0 startVs ILE.empty where+undirectedComponents es = go 0 startVs ILE.empty+ where g = fromUndirectedEdges es startVs = ILS.fromList (vertexList g) go i vs eqv =@@ -71,4 +73,4 @@ -- partial: ok by construction of graph and defn of reachable eqv' = foldl' (flip (ILE.partialInsert (Component i))) eqv rs vs'' = foldl' (flip ILS.delete) vs' rs- in go (i + 1) vs'' eqv'+ in go (i + 1) vs'' eqv'
src/IntLike/Map.hs view
@@ -24,7 +24,8 @@ , map , insertState , mapWithKey- ) where+ )+where import Control.DeepSeq (NFData) import Data.Coerce (Coercible, coerce)@@ -33,7 +34,7 @@ import IntLike.Set (IntLikeSet (..)) import Prelude hiding (filter, lookup, map, null) -newtype IntLikeMap x a = IntLikeMap { unIntLikeMap :: IntMap a }+newtype IntLikeMap x a = IntLikeMap {unIntLikeMap :: IntMap a} deriving stock (Show, Traversable) deriving newtype (Eq, Functor, Foldable, NFData, Semigroup, Monoid)
src/IntLike/MultiMap.hs view
@@ -8,7 +8,8 @@ , invertDisjoint , unsafeInvertDisjoint , fromInvertedMap- ) where+ )+where import Control.Monad (foldM) import Data.Coerce (Coercible)@@ -41,7 +42,8 @@ {-# INLINE member #-} invertDisjoint :: (Coercible k Int, Coercible v Int) => IntLikeMultiMap k v -> Either (k, k, v) (IntLikeMap v k)-invertDisjoint = foldM go1 ILM.empty . ILM.toList where+invertDisjoint = foldM go1 ILM.empty . ILM.toList+ where go1 m (k, vs) = foldM (go2 k) m (ILS.toList vs) go2 k m v = case ILM.lookup v m of@@ -49,7 +51,8 @@ Just k' -> Left (k, k', v) unsafeInvertDisjoint :: (Coercible k Int, Coercible v Int) => IntLikeMultiMap k v -> IntLikeMap v k-unsafeInvertDisjoint = foldl' go1 ILM.empty . ILM.toList where+unsafeInvertDisjoint = foldl' go1 ILM.empty . ILM.toList+ where go1 m (k, vs) = foldl' (go2 k) m (ILS.toList vs) go2 k m v = ILM.insert v k m
src/IntLike/Set.hs view
@@ -22,7 +22,8 @@ , insertState , orderedPairs , unorderedPairs- ) where+ )+where import Control.DeepSeq (NFData) import Data.Coerce (Coercible, coerce)@@ -31,7 +32,7 @@ import qualified Data.IntSet as IntSet import Prelude hiding (filter, map, null) -newtype IntLikeSet x = IntLikeSet { unIntLikeSet :: IntSet }+newtype IntLikeSet x = IntLikeSet {unIntLikeSet :: IntSet} deriving stock (Show) deriving newtype (Eq, NFData, Semigroup, Monoid) @@ -120,12 +121,13 @@ orderedPairs s = let vs = toList s in [(x, y) | x <- vs, y <- vs] unorderedPairs :: Coercible x Int => IntLikeSet x -> [(x, x)]-unorderedPairs = go1 . toList where+unorderedPairs = go1 . toList+ where go1 vs = case vs of [] -> []- x:xs -> go2 x xs xs+ x : xs -> go2 x xs xs go2 x vl vs = case vl of [] -> go1 vs- y:vl' -> (x, y):go2 x vl' vs+ y : vl' -> (x, y) : go2 x vl' vs
test/Main.hs view
@@ -5,9 +5,9 @@ testSimple :: TestTree testSimple = testCase "simple" $ do- let actual = (1 + 1) :: Int- expected = 2 :: Int- actual @?= expected+ let actual = (1 + 1) :: Int+ expected = 2 :: Int+ actual @?= expected -- TODO uh, write some tests!?! main :: IO ()