Skip to content

Commit

Permalink
Add a toList function
Browse files Browse the repository at this point in the history
  • Loading branch information
batterseapower committed Mar 8, 2011
1 parent 5c5c19c commit 355c148
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Data/Graph/Wrapper.hs
Expand Up @@ -15,6 +15,7 @@ module Data.Graph.Wrapper (
vertex,

fromListSimple, fromList, fromListBy, fromVerticesEdges,
toList,

vertices, edges, successors,

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 355c148

Please sign in to comment.