Sfoglia il codice sorgente

Fixed flow_graph:from_list/3 to correctly add edges.

Paul Downen 14 anni fa
parent
commit
e31c4ed75c
1 ha cambiato i file con 7 aggiunte e 4 eliminazioni
  1. 7 4
      src/flow_graph.erl

+ 7 - 4
src/flow_graph.erl

@@ -12,7 +12,7 @@
 -export([valid_edge/1, valid_edge_list/1, valid_graph/1]).
 
 % Use the orddict module for clarity, and the dict module for speed.
--define(DICT, dict).
+-define(DICT, orddict).
 
 % flow_graph ::= {in    : vertex,
 %                 out   : vertex,
@@ -103,8 +103,11 @@ singleton(V = #vertex{}) ->
     #flow_graph{in=V, out=V, graph=orddict:store(V, [], ?DICT:new())}.
 
 from_list(In = #vertex{}, Out = #vertex{}, Edges) ->
-    G = lists:fold(fun(E, G) -> add_edge(G, E) end, ?DICT:new(), Edges),
-    #flow_graph{in=In, out=Out, graph=G}.
+    FG = lists:foldl(fun(E, G) -> add_edge(G, E) end,
+		     #flow_graph{in=In, out=Out, graph=?DICT:new()},
+		     Edges),
+    G2 = ?DICT:update(Out, fun(X)->X end, [], FG#flow_graph.graph),
+    FG#flow_graph{graph=G2}.
 
 %% Graph manipulation
 
@@ -121,7 +124,7 @@ out_edges(#flow_graph{graph=G}, #vertex{ref=R}) ->
 
 add_edge(FG = #flow_graph{graph=G}, E = #edge{from=From}) ->
     Add = fun(Edges) -> [E|Edges] end,
-    FG#flow_graph{graph=?DICT:update(From, Add, [], G)}.
+    FG#flow_graph{graph=?DICT:update(From, Add, [E], G)}.
 
 % Checks for validity
 valid_edge(#edge{from=From, to=To, through=Through}) ->