Skip to content

Commit

Permalink
Add all_neighbor_labels function (#77)
Browse files Browse the repository at this point in the history
* Add all_neighbor_labels function

Solves #76

* Change all_neighbor_labels test to be independent of order

---------

Co-authored-by: Gregor Wehrle <g.wehrle@tu-braunschweig.de>
  • Loading branch information
apriljunge and apriljunge committed Mar 18, 2024
1 parent cf77b53 commit d2062f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/MetaGraphsNext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ using SimpleTraits

export MetaGraph
export label_for, code_for
export labels, edge_labels, neighbor_labels, outneighbor_labels, inneighbor_labels
export labels,
edge_labels, neighbor_labels, outneighbor_labels, inneighbor_labels, all_neighbor_labels
export set_data!
export weighttype, default_weight, get_weight_function
export MGFormat, DOTFormat
Expand Down
14 changes: 14 additions & 0 deletions src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function Graphs.outneighbors(meta_graph::MetaGraph, code::Integer)
return outneighbors(meta_graph.graph, code)
end

function Graphs.all_neighbors(meta_graph::MetaGraph, code::Integer)
return all_neighbors(meta_graph.graph, code)
end

function Base.issubset(meta_graph::MetaGraph, h::MetaGraph)
# no checking of: matching vertex label, or matching edge data
return issubset(meta_graph.graph, h.graph)
Expand Down Expand Up @@ -101,6 +105,16 @@ function inneighbor_labels(meta_graph::MetaGraph, label)
return (label_for(meta_graph, code_1) for code_1 in inneighbors(meta_graph, code_2))
end

"""
all_neighbor_labels(meta_graph, label)
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)`.
"""
function all_neighbor_labels(meta_graph::MetaGraph, label)
code_1 = code_for(meta_graph, label)
return (label_for(meta_graph, code_2) for code_2 in all_neighbors(meta_graph, code_1))
end

## Set vertex and edge data

"""
Expand Down
2 changes: 2 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function test_labels_codes(mg::MetaGraph)
for label_0 in inneighbor_labels(mg, label_1)
@test has_edge(mg, code_for(mg, label_0), code_for(mg, label_1))
end
@test Set(all_neighbor_labels(mg, label_1)) ==
Set(union(outneighbor_labels(mg, label_1), inneighbor_labels(mg, label_1)))
end
end

Expand Down

0 comments on commit d2062f3

Please sign in to comment.