graph-core 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+38/−3 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Graph: removeNode :: Node -> Graph -> Graph
+ Data.Graph.NodeManager: removeNodeHandle :: (Hashable k, Eq k) => Node -> NodeManager k -> NodeManager k
Files
- graph-core.cabal +2/−2
- src/Data/Graph.hs +1/−1
- src/Data/Graph/NodeManager.hs +10/−0
- src/Data/Graph/PureCore.hs +13/−0
- src/Test/Core.hs +12/−0
graph-core.cabal view
@@ -1,11 +1,11 @@ name: graph-core-version: 0.1.0.0+version: 0.2.0.0 synopsis: Fast, memory efficient and persistent graph implementation description: A small package providing a powerful and easy to use Haskell graph implementation. homepage: https://github.com/factisresearch/graph-core license: MIT license-file: LICENSE-author: Stefan Wehr <wehr@cp-med.com>, David Leuschner <leuschner@cp-med.com>, Alexander Thiemann <thiemann@cp-med.com>+author: Stefan Wehr <wehr@cp-med.com>, David Leuschner <leuschner@cp-med.com>, Niklas Baumstark, Jonathan Dimond, Alexander Thiemann <thiemann@cp-med.com> maintainer: Alexander Thiemann <thiemann@cp-med.com> copyright: (c) 2014 factis research GmbH category: Data
src/Data/Graph.hs view
@@ -11,7 +11,7 @@ , edgeCount , hull, rhull, hullFold, hullFoldM, rhullFold , addEdge, addEdges, removeEdge, removeEdges- , addNode, solitaireNodes+ , addNode, removeNode, solitaireNodes , edgesAdj ) where
src/Data/Graph/NodeManager.hs view
@@ -7,6 +7,7 @@ , emptyNode , initNodeManager, emptyNodeManager, getNodeMap , getNodeHandle, getExistingNodeHandle, lookupNode, unsafeLookupNode+ , removeNodeHandle , getNewNodesSince, keys, hasKey, nodes, toList , isConsistent )@@ -91,6 +92,15 @@ , nm_nextNode = i + 1 } return i++removeNodeHandle :: (Hashable k, Eq k) => Node -> NodeManager k -> NodeManager k+removeNodeHandle i nm@(NodeManager{..}) =+ case IM.lookup i nm_nodeToKey of+ Just k ->+ nm { nm_nodeToKey = IM.delete i nm_nodeToKey+ , nm_keyToNode = HM.delete k nm_keyToNode+ }+ Nothing -> nm getExistingNodeHandle :: (Hashable k, Eq k) => k -> NodeManager k -> Maybe Node getExistingNodeHandle k (NodeManager{..}) = HM.lookup k nm_keyToNode
src/Data/Graph/PureCore.hs view
@@ -116,6 +116,19 @@ addNode x g = g { g_adj = IM.insertWith (\_new old -> old) x VU.empty (g_adj g) } +removeNode :: Node -> Graph -> Graph+removeNode x g =+ let rmInAdj adj localF =+ foldl (\adjList child ->+ IM.adjust (VU.filter (/=x)) child adjList+ ) (IM.delete x adj) $ VU.toList (localF g x)++ newAdj = rmInAdj (g_adj g) parents+ newRAdj = rmInAdj (g_radj g) children+ in g { g_adj = newAdj+ , g_radj = newRAdj+ }+ addEdge :: Node -> Node -> Graph -> Graph addEdge x y g@(Graph{..}) = if hasEdge x y g
src/Test/Core.hs view
@@ -30,6 +30,18 @@ do assertEqual (fromAdj [(1, [2]), (2, [3,4]), (3, [4]), (4, [])]) (removeEdges [e (1,3), e (4,1)] testGraphA) +test_removeNode :: IO ()+test_removeNode =+ let orig = fromAdj [(1, [2]), (2, [3,4]), (3, [4]), (4, [])]+ res1 = fromAdj [(1, [2]), (2, [3]), (3, [])]+ res2 = fromAdj [(1, [2]), (2, [4]), (4, [])]+ res3 = fromAdj [(1, []), (3, [4]), (4, [])]++ in do assertEqual res1 (removeNode 4 orig)+ assertEqual res2 (removeNode 3 orig)+ assertEqual res3 (removeNode 2 orig)+ assertEqual orig (removeNode 5 orig)+ test_hull :: IO () test_hull = do assertEqual (IS.fromList [4]) (hull testGraphA 4)