module Algebra.Graph.NonEmpty.AdjacencyMap (
AdjacencyMap, toNonEmpty, fromNonEmpty,
vertex, edge, overlay, connect, vertices1, edges1, overlays1, connects1,
isSubgraphOf,
hasVertex, hasEdge, vertexCount, edgeCount, vertexList1, edgeList,
vertexSet, edgeSet, preSet, postSet,
path1, circuit1, clique1, biclique1, star, stars1, tree,
removeVertex1, removeEdge, replaceVertex, mergeVertices, transpose, gmap,
induce1, induceJust1,
closure, reflexiveClosure, symmetricClosure, transitiveClosure,
consistent
) where
import Prelude hiding (reverse)
import Control.DeepSeq
import Data.Coerce
import Data.List ((\\))
import Data.List.NonEmpty (NonEmpty (..), nonEmpty, toList, reverse)
import Data.Maybe
import Data.Set (Set)
import Data.String
import Data.Tree
import GHC.Generics
import qualified Algebra.Graph.AdjacencyMap as AM
import qualified Data.Set as Set
newtype AdjacencyMap a = NAM { AdjacencyMap a -> AdjacencyMap a
am :: AM.AdjacencyMap a }
deriving (AdjacencyMap a -> AdjacencyMap a -> Bool
(AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> Eq (AdjacencyMap a)
forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c/= :: forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
== :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c== :: forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
Eq, (forall x. AdjacencyMap a -> Rep (AdjacencyMap a) x)
-> (forall x. Rep (AdjacencyMap a) x -> AdjacencyMap a)
-> Generic (AdjacencyMap a)
forall x. Rep (AdjacencyMap a) x -> AdjacencyMap a
forall x. AdjacencyMap a -> Rep (AdjacencyMap a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (AdjacencyMap a) x -> AdjacencyMap a
forall a x. AdjacencyMap a -> Rep (AdjacencyMap a) x
$cto :: forall a x. Rep (AdjacencyMap a) x -> AdjacencyMap a
$cfrom :: forall a x. AdjacencyMap a -> Rep (AdjacencyMap a) x
Generic, String -> AdjacencyMap a
(String -> AdjacencyMap a) -> IsString (AdjacencyMap a)
forall a. IsString a => String -> AdjacencyMap a
forall a. (String -> a) -> IsString a
fromString :: String -> AdjacencyMap a
$cfromString :: forall a. IsString a => String -> AdjacencyMap a
IsString, AdjacencyMap a -> ()
(AdjacencyMap a -> ()) -> NFData (AdjacencyMap a)
forall a. NFData a => AdjacencyMap a -> ()
forall a. (a -> ()) -> NFData a
rnf :: AdjacencyMap a -> ()
$crnf :: forall a. NFData a => AdjacencyMap a -> ()
NFData, Eq (AdjacencyMap a)
Eq (AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a -> Ordering)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> Ord (AdjacencyMap a)
AdjacencyMap a -> AdjacencyMap a -> Bool
AdjacencyMap a -> AdjacencyMap a -> Ordering
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (AdjacencyMap a)
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Ordering
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
min :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
$cmin :: forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
max :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
$cmax :: forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
>= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c>= :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
> :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c> :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
<= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c<= :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
< :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c< :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
compare :: AdjacencyMap a -> AdjacencyMap a -> Ordering
$ccompare :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (AdjacencyMap a)
Ord)
instance (Ord a, Num a) => Num (AdjacencyMap a) where
fromInteger :: Integer -> AdjacencyMap a
fromInteger = a -> AdjacencyMap a
forall a. a -> AdjacencyMap a
vertex (a -> AdjacencyMap a)
-> (Integer -> a) -> Integer -> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger
+ :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
(+) = AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
overlay
* :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
(*) = AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
connect
signum :: AdjacencyMap a -> AdjacencyMap a
signum = String -> AdjacencyMap a -> AdjacencyMap a
forall a. HasCallStack => String -> a
error String
"NonEmpty.AdjacencyMap.signum cannot be implemented."
abs :: AdjacencyMap a -> AdjacencyMap a
abs = AdjacencyMap a -> AdjacencyMap a
forall a. a -> a
id
negate :: AdjacencyMap a -> AdjacencyMap a
negate = AdjacencyMap a -> AdjacencyMap a
forall a. a -> a
id
instance (Ord a, Show a) => Show (AdjacencyMap a) where
showsPrec :: Int -> AdjacencyMap a -> ShowS
showsPrec Int
p AdjacencyMap a
nam
| [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
vs = String -> ShowS
forall a. HasCallStack => String -> a
error String
"NonEmpty.AdjacencyMap.Show: Graph is empty"
| [(a, a)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(a, a)]
es = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [a] -> ShowS
forall a. Show a => [a] -> ShowS
vshow [a]
vs
| [a]
vs [a] -> [a] -> Bool
forall a. Eq a => a -> a -> Bool
== [a]
used = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [(a, a)] -> ShowS
forall a a. (Show a, Show a) => [(a, a)] -> ShowS
eshow [(a, a)]
es
| Bool
otherwise = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"overlay (" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> ShowS
forall a. Show a => [a] -> ShowS
vshow ([a]
vs [a] -> [a] -> [a]
forall a. Eq a => [a] -> [a] -> [a]
\\ [a]
used) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
") (" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, a)] -> ShowS
forall a a. (Show a, Show a) => [(a, a)] -> ShowS
eshow [(a, a)]
es ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
")"
where
vs :: [a]
vs = NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList (AdjacencyMap a -> NonEmpty a
forall a. AdjacencyMap a -> NonEmpty a
vertexList1 AdjacencyMap a
nam)
es :: [(a, a)]
es = AdjacencyMap a -> [(a, a)]
forall a. AdjacencyMap a -> [(a, a)]
edgeList AdjacencyMap a
nam
vshow :: [a] -> ShowS
vshow [a
x] = String -> ShowS
showString String
"vertex " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
x
vshow [a]
xs = String -> ShowS
showString String
"vertices1 " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [a]
xs
eshow :: [(a, a)] -> ShowS
eshow [(a
x, a
y)] = String -> ShowS
showString String
"edge " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
x ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
y
eshow [(a, a)]
xs = String -> ShowS
showString String
"edges1 " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [(a, a)] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [(a, a)]
xs
used :: [a]
used = Set a -> [a]
forall a. Set a -> [a]
Set.toAscList (Set a -> [a]) -> Set a -> [a]
forall a b. (a -> b) -> a -> b
$ [a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList ([a] -> Set a) -> [a] -> Set a
forall a b. (a -> b) -> a -> b
$ ([a] -> [a] -> [a]) -> ([a], [a]) -> [a]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
(++) (([a], [a]) -> [a]) -> ([a], [a]) -> [a]
forall a b. (a -> b) -> a -> b
$ [(a, a)] -> ([a], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip [(a, a)]
es
instance Ord a => Semigroup (AdjacencyMap a) where
<> :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
(<>) = AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
overlay
unsafeNonEmpty :: [a] -> NonEmpty a
unsafeNonEmpty :: [a] -> NonEmpty a
unsafeNonEmpty = NonEmpty a -> Maybe (NonEmpty a) -> NonEmpty a
forall a. a -> Maybe a -> a
fromMaybe (String -> NonEmpty a
forall a. HasCallStack => String -> a
error String
msg) (Maybe (NonEmpty a) -> NonEmpty a)
-> ([a] -> Maybe (NonEmpty a)) -> [a] -> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty
where
msg :: String
msg = String
"Algebra.Graph.AdjacencyMap.unsafeNonEmpty: Graph is empty"
toNonEmpty :: AM.AdjacencyMap a -> Maybe (AdjacencyMap a)
toNonEmpty :: AdjacencyMap a -> Maybe (AdjacencyMap a)
toNonEmpty AdjacencyMap a
x | AdjacencyMap a -> Bool
forall a. AdjacencyMap a -> Bool
AM.isEmpty AdjacencyMap a
x = Maybe (AdjacencyMap a)
forall a. Maybe a
Nothing
| Bool
otherwise = AdjacencyMap a -> Maybe (AdjacencyMap a)
forall a. a -> Maybe a
Just (AdjacencyMap a -> AdjacencyMap a
forall a. AdjacencyMap a -> AdjacencyMap a
NAM AdjacencyMap a
x)
fromNonEmpty :: AdjacencyMap a -> AM.AdjacencyMap a
fromNonEmpty :: AdjacencyMap a -> AdjacencyMap a
fromNonEmpty = AdjacencyMap a -> AdjacencyMap a
forall a. AdjacencyMap a -> AdjacencyMap a
am
vertex :: a -> AdjacencyMap a
vertex :: a -> AdjacencyMap a
vertex = (a -> AdjacencyMap a) -> a -> AdjacencyMap a
coerce a -> AdjacencyMap a
forall a. a -> AdjacencyMap a
AM.vertex
{-# NOINLINE [1] vertex #-}
edge :: Ord a => a -> a -> AdjacencyMap a
edge :: a -> a -> AdjacencyMap a
edge = (a -> a -> AdjacencyMap a) -> a -> a -> AdjacencyMap a
coerce a -> a -> AdjacencyMap a
forall a. Ord a => a -> a -> AdjacencyMap a
AM.edge
overlay :: Ord a => AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
overlay :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
overlay = (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.overlay
{-# NOINLINE [1] overlay #-}
connect :: Ord a => AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
connect :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
connect = (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.connect
{-# NOINLINE [1] connect #-}
vertices1 :: Ord a => NonEmpty a -> AdjacencyMap a
vertices1 :: NonEmpty a -> AdjacencyMap a
vertices1 = ([a] -> AdjacencyMap a) -> [a] -> AdjacencyMap a
coerce [a] -> AdjacencyMap a
forall a. Ord a => [a] -> AdjacencyMap a
AM.vertices ([a] -> AdjacencyMap a)
-> (NonEmpty a -> [a]) -> NonEmpty a -> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
{-# NOINLINE [1] vertices1 #-}
edges1 :: Ord a => NonEmpty (a, a) -> AdjacencyMap a
edges1 :: NonEmpty (a, a) -> AdjacencyMap a
edges1 = ([(a, a)] -> AdjacencyMap a) -> [(a, a)] -> AdjacencyMap a
coerce [(a, a)] -> AdjacencyMap a
forall a. Ord a => [(a, a)] -> AdjacencyMap a
AM.edges ([(a, a)] -> AdjacencyMap a)
-> (NonEmpty (a, a) -> [(a, a)])
-> NonEmpty (a, a)
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (a, a) -> [(a, a)]
forall a. NonEmpty a -> [a]
toList
overlays1 :: Ord a => NonEmpty (AdjacencyMap a) -> AdjacencyMap a
overlays1 :: NonEmpty (AdjacencyMap a) -> AdjacencyMap a
overlays1 = ([AdjacencyMap a] -> AdjacencyMap a)
-> [AdjacencyMap a] -> AdjacencyMap a
coerce [AdjacencyMap a] -> AdjacencyMap a
forall a. Ord a => [AdjacencyMap a] -> AdjacencyMap a
AM.overlays ([AdjacencyMap a] -> AdjacencyMap a)
-> (NonEmpty (AdjacencyMap a) -> [AdjacencyMap a])
-> NonEmpty (AdjacencyMap a)
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (AdjacencyMap a) -> [AdjacencyMap a]
forall a. NonEmpty a -> [a]
toList
{-# NOINLINE overlays1 #-}
connects1 :: Ord a => NonEmpty (AdjacencyMap a) -> AdjacencyMap a
connects1 :: NonEmpty (AdjacencyMap a) -> AdjacencyMap a
connects1 = ([AdjacencyMap a] -> AdjacencyMap a)
-> [AdjacencyMap a] -> AdjacencyMap a
coerce [AdjacencyMap a] -> AdjacencyMap a
forall a. Ord a => [AdjacencyMap a] -> AdjacencyMap a
AM.connects ([AdjacencyMap a] -> AdjacencyMap a)
-> (NonEmpty (AdjacencyMap a) -> [AdjacencyMap a])
-> NonEmpty (AdjacencyMap a)
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (AdjacencyMap a) -> [AdjacencyMap a]
forall a. NonEmpty a -> [a]
toList
{-# NOINLINE connects1 #-}
isSubgraphOf :: Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
isSubgraphOf :: AdjacencyMap a -> AdjacencyMap a -> Bool
isSubgraphOf = (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> AdjacencyMap a -> AdjacencyMap a -> Bool
coerce AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
AM.isSubgraphOf
hasVertex :: Ord a => a -> AdjacencyMap a -> Bool
hasVertex :: a -> AdjacencyMap a -> Bool
hasVertex = (a -> AdjacencyMap a -> Bool) -> a -> AdjacencyMap a -> Bool
coerce a -> AdjacencyMap a -> Bool
forall a. Ord a => a -> AdjacencyMap a -> Bool
AM.hasVertex
hasEdge :: Ord a => a -> a -> AdjacencyMap a -> Bool
hasEdge :: a -> a -> AdjacencyMap a -> Bool
hasEdge = (a -> a -> AdjacencyMap a -> Bool)
-> a -> a -> AdjacencyMap a -> Bool
coerce a -> a -> AdjacencyMap a -> Bool
forall a. Ord a => a -> a -> AdjacencyMap a -> Bool
AM.hasEdge
vertexCount :: AdjacencyMap a -> Int
vertexCount :: AdjacencyMap a -> Int
vertexCount = (AdjacencyMap a -> Int) -> AdjacencyMap a -> Int
coerce AdjacencyMap a -> Int
forall a. AdjacencyMap a -> Int
AM.vertexCount
edgeCount :: AdjacencyMap a -> Int
edgeCount :: AdjacencyMap a -> Int
edgeCount = (AdjacencyMap a -> Int) -> AdjacencyMap a -> Int
coerce AdjacencyMap a -> Int
forall a. AdjacencyMap a -> Int
AM.edgeCount
vertexList1 :: AdjacencyMap a -> NonEmpty a
vertexList1 :: AdjacencyMap a -> NonEmpty a
vertexList1 = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
unsafeNonEmpty ([a] -> NonEmpty a)
-> (AdjacencyMap a -> [a]) -> AdjacencyMap a -> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AdjacencyMap a -> [a]) -> AdjacencyMap a -> [a]
coerce AdjacencyMap a -> [a]
forall a. AdjacencyMap a -> [a]
AM.vertexList
edgeList :: AdjacencyMap a -> [(a, a)]
edgeList :: AdjacencyMap a -> [(a, a)]
edgeList = (AdjacencyMap a -> [(a, a)]) -> AdjacencyMap a -> [(a, a)]
coerce AdjacencyMap a -> [(a, a)]
forall a. AdjacencyMap a -> [(a, a)]
AM.edgeList
vertexSet :: AdjacencyMap a -> Set a
vertexSet :: AdjacencyMap a -> Set a
vertexSet = (AdjacencyMap a -> Set a) -> AdjacencyMap a -> Set a
coerce AdjacencyMap a -> Set a
forall a. AdjacencyMap a -> Set a
AM.vertexSet
edgeSet :: Ord a => AdjacencyMap a -> Set (a, a)
edgeSet :: AdjacencyMap a -> Set (a, a)
edgeSet = (AdjacencyMap a -> Set (a, a)) -> AdjacencyMap a -> Set (a, a)
coerce AdjacencyMap a -> Set (a, a)
forall a. Eq a => AdjacencyMap a -> Set (a, a)
AM.edgeSet
preSet :: Ord a => a -> AdjacencyMap a -> Set.Set a
preSet :: a -> AdjacencyMap a -> Set a
preSet = (a -> AdjacencyMap a -> Set a) -> a -> AdjacencyMap a -> Set a
coerce a -> AdjacencyMap a -> Set a
forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.preSet
postSet :: Ord a => a -> AdjacencyMap a -> Set a
postSet :: a -> AdjacencyMap a -> Set a
postSet = (a -> AdjacencyMap a -> Set a) -> a -> AdjacencyMap a -> Set a
coerce a -> AdjacencyMap a -> Set a
forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.postSet
path1 :: Ord a => NonEmpty a -> AdjacencyMap a
path1 :: NonEmpty a -> AdjacencyMap a
path1 = ([a] -> AdjacencyMap a) -> [a] -> AdjacencyMap a
coerce [a] -> AdjacencyMap a
forall a. Ord a => [a] -> AdjacencyMap a
AM.path ([a] -> AdjacencyMap a)
-> (NonEmpty a -> [a]) -> NonEmpty a -> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
circuit1 :: Ord a => NonEmpty a -> AdjacencyMap a
circuit1 :: NonEmpty a -> AdjacencyMap a
circuit1 = ([a] -> AdjacencyMap a) -> [a] -> AdjacencyMap a
coerce [a] -> AdjacencyMap a
forall a. Ord a => [a] -> AdjacencyMap a
AM.circuit ([a] -> AdjacencyMap a)
-> (NonEmpty a -> [a]) -> NonEmpty a -> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
clique1 :: Ord a => NonEmpty a -> AdjacencyMap a
clique1 :: NonEmpty a -> AdjacencyMap a
clique1 = ([a] -> AdjacencyMap a) -> [a] -> AdjacencyMap a
coerce [a] -> AdjacencyMap a
forall a. Ord a => [a] -> AdjacencyMap a
AM.clique ([a] -> AdjacencyMap a)
-> (NonEmpty a -> [a]) -> NonEmpty a -> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
{-# NOINLINE [1] clique1 #-}
biclique1 :: Ord a => NonEmpty a -> NonEmpty a -> AdjacencyMap a
biclique1 :: NonEmpty a -> NonEmpty a -> AdjacencyMap a
biclique1 NonEmpty a
xs NonEmpty a
ys = ([a] -> [a] -> AdjacencyMap a) -> [a] -> [a] -> AdjacencyMap a
coerce [a] -> [a] -> AdjacencyMap a
forall a. Ord a => [a] -> [a] -> AdjacencyMap a
AM.biclique (NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList NonEmpty a
xs) (NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList NonEmpty a
ys)
star :: Ord a => a -> [a] -> AdjacencyMap a
star :: a -> [a] -> AdjacencyMap a
star = (a -> [a] -> AdjacencyMap a) -> a -> [a] -> AdjacencyMap a
coerce a -> [a] -> AdjacencyMap a
forall a. Ord a => a -> [a] -> AdjacencyMap a
AM.star
{-# INLINE star #-}
stars1 :: Ord a => NonEmpty (a, [a]) -> AdjacencyMap a
stars1 :: NonEmpty (a, [a]) -> AdjacencyMap a
stars1 = ([(a, [a])] -> AdjacencyMap a) -> [(a, [a])] -> AdjacencyMap a
coerce [(a, [a])] -> AdjacencyMap a
forall a. Ord a => [(a, [a])] -> AdjacencyMap a
AM.stars ([(a, [a])] -> AdjacencyMap a)
-> (NonEmpty (a, [a]) -> [(a, [a])])
-> NonEmpty (a, [a])
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (a, [a]) -> [(a, [a])]
forall a. NonEmpty a -> [a]
toList
tree :: Ord a => Tree a -> AdjacencyMap a
tree :: Tree a -> AdjacencyMap a
tree = (Tree a -> AdjacencyMap a) -> Tree a -> AdjacencyMap a
coerce Tree a -> AdjacencyMap a
forall a. Ord a => Tree a -> AdjacencyMap a
AM.tree
removeVertex1 :: Ord a => a -> AdjacencyMap a -> Maybe (AdjacencyMap a)
removeVertex1 :: a -> AdjacencyMap a -> Maybe (AdjacencyMap a)
removeVertex1 = (AdjacencyMap a -> Maybe (AdjacencyMap a))
-> (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a
-> Maybe (AdjacencyMap a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AdjacencyMap a -> Maybe (AdjacencyMap a)
forall a. AdjacencyMap a -> Maybe (AdjacencyMap a)
toNonEmpty ((AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> Maybe (AdjacencyMap a))
-> (a -> AdjacencyMap a -> AdjacencyMap a)
-> a
-> AdjacencyMap a
-> Maybe (AdjacencyMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> AdjacencyMap a -> AdjacencyMap a)
-> a -> AdjacencyMap a -> AdjacencyMap a
coerce a -> AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => a -> AdjacencyMap a -> AdjacencyMap a
AM.removeVertex
removeEdge :: Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
removeEdge :: a -> a -> AdjacencyMap a -> AdjacencyMap a
removeEdge = (a -> a -> AdjacencyMap a -> AdjacencyMap a)
-> a -> a -> AdjacencyMap a -> AdjacencyMap a
coerce a -> a -> AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
AM.removeEdge
replaceVertex :: Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
replaceVertex :: a -> a -> AdjacencyMap a -> AdjacencyMap a
replaceVertex = (a -> a -> AdjacencyMap a -> AdjacencyMap a)
-> a -> a -> AdjacencyMap a -> AdjacencyMap a
coerce a -> a -> AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
AM.replaceVertex
mergeVertices :: Ord a => (a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a
mergeVertices :: (a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a
mergeVertices = ((a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a)
-> (a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a
coerce (a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
(a -> Bool) -> a -> AdjacencyMap a -> AdjacencyMap a
AM.mergeVertices
transpose :: Ord a => AdjacencyMap a -> AdjacencyMap a
transpose :: AdjacencyMap a -> AdjacencyMap a
transpose = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transpose
{-# NOINLINE [1] transpose #-}
{-# RULES
"transpose/vertex" forall x. transpose (vertex x) = vertex x
"transpose/overlay" forall g1 g2. transpose (overlay g1 g2) = overlay (transpose g1) (transpose g2)
"transpose/connect" forall g1 g2. transpose (connect g1 g2) = connect (transpose g2) (transpose g1)
"transpose/overlays1" forall xs. transpose (overlays1 xs) = overlays1 (fmap transpose xs)
"transpose/connects1" forall xs. transpose (connects1 xs) = connects1 (reverse (fmap transpose xs))
"transpose/vertices1" forall xs. transpose (vertices1 xs) = vertices1 xs
"transpose/clique1" forall xs. transpose (clique1 xs) = clique1 (reverse xs)
#-}
gmap :: (Ord a, Ord b) => (a -> b) -> AdjacencyMap a -> AdjacencyMap b
gmap :: (a -> b) -> AdjacencyMap a -> AdjacencyMap b
gmap = ((a -> b) -> AdjacencyMap a -> AdjacencyMap b)
-> (a -> b) -> AdjacencyMap a -> AdjacencyMap b
coerce (a -> b) -> AdjacencyMap a -> AdjacencyMap b
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap
induce1 :: (a -> Bool) -> AdjacencyMap a -> Maybe (AdjacencyMap a)
induce1 :: (a -> Bool) -> AdjacencyMap a -> Maybe (AdjacencyMap a)
induce1 = (AdjacencyMap a -> Maybe (AdjacencyMap a))
-> (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a
-> Maybe (AdjacencyMap a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AdjacencyMap a -> Maybe (AdjacencyMap a)
forall a. AdjacencyMap a -> Maybe (AdjacencyMap a)
toNonEmpty ((AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> Maybe (AdjacencyMap a))
-> ((a -> Bool) -> AdjacencyMap a -> AdjacencyMap a)
-> (a -> Bool)
-> AdjacencyMap a
-> Maybe (AdjacencyMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> Bool) -> AdjacencyMap a -> AdjacencyMap a)
-> (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
coerce (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
forall a. (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
AM.induce
induceJust1 :: Ord a => AdjacencyMap (Maybe a) -> Maybe (AdjacencyMap a)
induceJust1 :: AdjacencyMap (Maybe a) -> Maybe (AdjacencyMap a)
induceJust1 = AdjacencyMap a -> Maybe (AdjacencyMap a)
forall a. AdjacencyMap a -> Maybe (AdjacencyMap a)
toNonEmpty (AdjacencyMap a -> Maybe (AdjacencyMap a))
-> (AdjacencyMap (Maybe a) -> AdjacencyMap a)
-> AdjacencyMap (Maybe a)
-> Maybe (AdjacencyMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyMap (Maybe a) -> AdjacencyMap a
forall a. Ord a => AdjacencyMap (Maybe a) -> AdjacencyMap a
AM.induceJust (AdjacencyMap (Maybe a) -> AdjacencyMap a)
-> (AdjacencyMap (Maybe a) -> AdjacencyMap (Maybe a))
-> AdjacencyMap (Maybe a)
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyMap (Maybe a) -> AdjacencyMap (Maybe a)
coerce
closure :: Ord a => AdjacencyMap a -> AdjacencyMap a
closure :: AdjacencyMap a -> AdjacencyMap a
closure = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.closure
reflexiveClosure :: Ord a => AdjacencyMap a -> AdjacencyMap a
reflexiveClosure :: AdjacencyMap a -> AdjacencyMap a
reflexiveClosure = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.reflexiveClosure
symmetricClosure :: Ord a => AdjacencyMap a -> AdjacencyMap a
symmetricClosure :: AdjacencyMap a -> AdjacencyMap a
symmetricClosure = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.symmetricClosure
transitiveClosure :: Ord a => AdjacencyMap a -> AdjacencyMap a
transitiveClosure :: AdjacencyMap a -> AdjacencyMap a
transitiveClosure = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transitiveClosure
consistent :: Ord a => AdjacencyMap a -> Bool
consistent :: AdjacencyMap a -> Bool
consistent (NAM AdjacencyMap a
x) = AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> Bool
AM.consistent AdjacencyMap a
x Bool -> Bool -> Bool
&& Bool -> Bool
not (AdjacencyMap a -> Bool
forall a. AdjacencyMap a -> Bool
AM.isEmpty AdjacencyMap a
x)