Skip to content

Commit d2062f3

Browse files
authored
Add all_neighbor_labels function (#77)
* Add all_neighbor_labels function Solves #76 * Change all_neighbor_labels test to be independent of order --------- Co-authored-by: Gregor Wehrle <[email protected]>
1 parent cf77b53 commit d2062f3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/MetaGraphsNext.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ using SimpleTraits
1111

1212
export MetaGraph
1313
export label_for, code_for
14-
export labels, edge_labels, neighbor_labels, outneighbor_labels, inneighbor_labels
14+
export labels,
15+
edge_labels, neighbor_labels, outneighbor_labels, inneighbor_labels, all_neighbor_labels
1516
export set_data!
1617
export weighttype, default_weight, get_weight_function
1718
export MGFormat, DOTFormat

src/graphs.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function Graphs.outneighbors(meta_graph::MetaGraph, code::Integer)
4343
return outneighbors(meta_graph.graph, code)
4444
end
4545

46+
function Graphs.all_neighbors(meta_graph::MetaGraph, code::Integer)
47+
return all_neighbors(meta_graph.graph, code)
48+
end
49+
4650
function Base.issubset(meta_graph::MetaGraph, h::MetaGraph)
4751
# no checking of: matching vertex label, or matching edge data
4852
return issubset(meta_graph.graph, h.graph)
@@ -101,6 +105,16 @@ function inneighbor_labels(meta_graph::MetaGraph, label)
101105
return (label_for(meta_graph, code_1) for code_1 in inneighbors(meta_graph, code_2))
102106
end
103107

108+
"""
109+
all_neighbor_labels(meta_graph, label)
110+
111+
Iterate through all labels of all neighbors of the vertex `code` with label `label`, in the same order as the codes obtained by `all_neighbors(meta_graph, code)`.
112+
"""
113+
function all_neighbor_labels(meta_graph::MetaGraph, label)
114+
code_1 = code_for(meta_graph, label)
115+
return (label_for(meta_graph, code_2) for code_2 in all_neighbors(meta_graph, code_1))
116+
end
117+
104118
## Set vertex and edge data
105119

106120
"""

test/misc.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function test_labels_codes(mg::MetaGraph)
2020
for label_0 in inneighbor_labels(mg, label_1)
2121
@test has_edge(mg, code_for(mg, label_0), code_for(mg, label_1))
2222
end
23+
@test Set(all_neighbor_labels(mg, label_1)) ==
24+
Set(union(outneighbor_labels(mg, label_1), inneighbor_labels(mg, label_1)))
2325
end
2426
end
2527

0 commit comments

Comments
 (0)