Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all_neighbor_labels function #77

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 collect(all_neighbor_labels(mg, label_1)) ==
union(outneighbor_labels(mg, label_1), inneighbor_labels(mg, label_1))
apriljunge marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
Loading