| Copyright | (c) Andrey Mokhov 2016-2018 |
|---|---|
| License | MIT (see the file LICENSE) |
| Maintainer | andrey.mokhov@gmail.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Algebra.Graph.Relation.Symmetric
Contents
Description
An abstract implementation of symmetric binary relations. Use Algebra.Graph.Class for polymorphic construction and manipulation.
Synopsis
- data SymmetricRelation a
- fromRelation :: Relation a -> SymmetricRelation a
- toRelation :: Ord a => SymmetricRelation a -> Relation a
- neighbours :: Ord a => a -> SymmetricRelation a -> Set a
Data structure
data SymmetricRelation a Source #
The SymmetricRelation data type represents a symmetric binary relation
over a set of elements. Symmetric relations satisfy all laws of the
Undirected type class and, in particular, the
commutativity of connect:
connectx y ==connecty x
The Show instance produces symmetrically closed expressions:
show (1 :: SymmetricRelation Int) == "vertex 1" show (1 * 2 :: SymmetricRelation Int) == "edges [(1,2),(2,1)]"
Instances
fromRelation :: Relation a -> SymmetricRelation a Source #
Construct a symmetric relation from a Relation.
Complexity: O(1) time.
toRelation :: Ord a => SymmetricRelation a -> Relation a Source #
Extract the underlying relation. Complexity: O(m*log(m)) time.
Graph properties
neighbours :: Ord a => a -> SymmetricRelation a -> Set a Source #
The set of neighbours of an element x is the set of elements that are
related to it, i.e. neighbours x == { a | aRx }. In the context of undirected
graphs, this corresponds to the set of adjacent vertices of vertex x.
neighbours xempty== Set.emptyneighbours x (vertexx) == Set.emptyneighbours x (edgex y) == Set.fromList[y] neighbours y (edgex y) == Set.fromList[x]