-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1023 from keynslug/fix/scope-include-loop
Prevent infinite recursion when enumerating document POIs
- Loading branch information
Showing
7 changed files
with
135 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
-ifndef(__TRANSITIVE_H__). | ||
-define(__TRANSITIVE_H__, included). | ||
|
||
-include("transitive.hrl"). | ||
-include("definition.hrl"). | ||
|
||
-endif. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-module(els_fungraph). | ||
|
||
-type id_fun(NodeT) :: fun((NodeT) -> _NodeID). | ||
-type edges_fun(NodeT) :: fun((NodeT) -> list(NodeT)). | ||
|
||
-opaque graph(NodeT) :: {?MODULE, id_fun(NodeT), edges_fun(NodeT)}. | ||
|
||
-export_type([graph/1]). | ||
|
||
-export([new/2]). | ||
-export([traverse/4]). | ||
|
||
-spec new(id_fun(NodeT), edges_fun(NodeT)) -> graph(NodeT). | ||
new(IdFun, EdgesFun) -> | ||
{?MODULE, IdFun, EdgesFun}. | ||
|
||
-type acc_fun(NodeT, AccT) :: | ||
fun((_Node :: NodeT, _From :: NodeT, AccT) -> AccT). | ||
|
||
-spec traverse(acc_fun(NodeT, AccT), AccT, NodeT, graph(NodeT)) -> AccT. | ||
traverse(AccFun, Acc, From, G) -> | ||
traverse(AccFun, Acc, [From], sets:new(), G). | ||
|
||
-spec traverse(acc_fun(NodeT, AccT), AccT, [NodeT], sets:set(), graph(NodeT)) -> | ||
AccT. | ||
traverse(AccFun, Acc, [Node | Rest], Visited, G = {?MODULE, IdFun, EdgesFun}) -> | ||
{AdjacentNodes, VisitedNext} = lists:foldr( | ||
fun(Adjacent, {NodesAcc, VisitedAcc}) -> | ||
ID = IdFun(Adjacent), | ||
case sets:is_element(ID, VisitedAcc) of | ||
false -> {[Adjacent | NodesAcc], sets:add_element(ID, VisitedAcc)}; | ||
true -> {NodesAcc, VisitedAcc} | ||
end | ||
end, | ||
{[], Visited}, | ||
EdgesFun(Node) | ||
), | ||
AccNext = lists:foldl( | ||
fun(Adjacent, AccIn) -> AccFun(Adjacent, Node, AccIn) end, | ||
Acc, | ||
AdjacentNodes | ||
), | ||
traverse(AccFun, AccNext, AdjacentNodes ++ Rest, VisitedNext, G); | ||
traverse(_AccFun, Acc, [], _Visited, _G) -> | ||
Acc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-module(els_fungraph_SUITE). | ||
|
||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
-export([all/0]). | ||
|
||
-export([dense_graph_traversal/1]). | ||
|
||
-spec all() -> [atom()]. | ||
all() -> | ||
[dense_graph_traversal]. | ||
|
||
-spec dense_graph_traversal(_Config) -> ok. | ||
dense_graph_traversal(_) -> | ||
MaxID = 40, | ||
% Visited nodes must be unique | ||
?assertEqual( | ||
lists:reverse(lists:seq(1, MaxID)), | ||
els_fungraph:traverse( | ||
fun(ID, _From, Acc) -> [ID | Acc] end, | ||
[], | ||
1, | ||
els_fungraph:new( | ||
fun(ID) -> ID end, | ||
fun(ID) -> | ||
% Each node has edges to nodes in range [ID; ID * 2] | ||
[NextID || NextID <- lists:seq(ID, ID * 2), NextID =< MaxID] | ||
end | ||
) | ||
) | ||
). |