Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a toList function

  • Loading branch information...
commit 355c148c0df6f2df70d068d6157c480d116f5af3 1 parent 5c5c19c
@batterseapower authored
Showing with 8 additions and 0 deletions.
  1. +8 −0 Data/Graph/Wrapper.hs
View
8 Data/Graph/Wrapper.hs
@@ -15,6 +15,7 @@ module Data.Graph.Wrapper (
vertex,
fromListSimple, fromList, fromListBy, fromVerticesEdges,
+ toList,
vertices, edges, successors,
@@ -158,6 +159,13 @@ indexGVertex' key_map k = go 0 (snd (bounds key_map))
GT -> go (mid + 1) b
where mid = (a + b) `div` 2
+
+-- | Morally, the inverse of 'fromList'. The order of the elements in the output list is unspecified, as is the order of the edges
+-- in each node's adjacency list. For this reason, @toList . fromList@ is not necessarily the identity function.
+toList :: Ord i => Graph i v -> [(i, v, [i])]
+toList g = [(indexGVertexArray g ! m, gVertexVertexArray g ! m, map (indexGVertexArray g !) ns) | (m, ns) <- assocs (graph g)]
+
+
-- | Exhaustive list of vertices in the graph
vertices :: Graph i v -> [i]
vertices g = map (gVertexIndex g) $ G.vertices (graph g)
Please sign in to comment.
Something went wrong with that request. Please try again.