diff --git a/examples/README.jl b/examples/README.jl index 5f39305..e3cbe5c 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -91,18 +91,6 @@ g₁ ⊔ g₂ # Same as above rename_vertices(v -> v[1], subgraph(v -> v[2] == 1, g₁ ⊔ g₂)) rename_vertices(v -> v[1], subgraph(v -> v[2] == 2, g₁ ⊔ g₂)) -## #' Additionally, we can use standard array concatenation syntax, such as: -## #+ term=true -## -## [g; g] -## -## #' which is equivalent to `vcat(g, g)` or: -## #+ term=true -## -## [g;; g] -## -## #' which is the same as `hcat(g, g)`. - #' ## Generating this README #' This file was generated with [Weave.jl](https://github.com/JunoLab/Weave.jl) with the following commands: diff --git a/src/abstractnamedgraph.jl b/src/abstractnamedgraph.jl index 8a02734..325fa93 100644 --- a/src/abstractnamedgraph.jl +++ b/src/abstractnamedgraph.jl @@ -196,7 +196,9 @@ function degree_histogram(g::AbstractNamedGraph, degfn=degree) return hist end -function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out) +function _neighborhood( + graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out +) parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx) parent_vertices = neighborhood( parent_graph(graph), vertex_to_parent_vertex(graph, vertex), d, parent_distmx; dir @@ -206,9 +208,25 @@ function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph ] end -function neighborhood_dists( - graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out +function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out) + return _neighborhood(graph, vertex, d, distmx; dir) +end + +# Fix for ambiguity error with `AbstractGraph` version +function neighborhood( + graph::AbstractNamedGraph, vertex::Integer, d, distmx=weights(graph); dir=:out +) + return _neighborhood(graph, vertex, d, distmx; dir) +end + +# Fix for ambiguity error with `AbstractGraph` version +function neighborhood( + graph::AbstractNamedGraph, vertex::Integer, d, distmx::AbstractMatrix{<:Real}; dir=:out ) + return _neighborhood(graph, vertex, d, distmx; dir) +end + +function _neighborhood_dists(graph::AbstractNamedGraph, vertex, d, distmx; dir) parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx) parent_vertices_and_dists = neighborhood_dists( parent_graph(graph), vertex_to_parent_vertex(graph, vertex), d, parent_distmx; dir @@ -219,6 +237,30 @@ function neighborhood_dists( ] end +function neighborhood_dists( + graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out +) + return _neighborhood_dists(graph, vertex, d, distmx; dir) +end + +# Fix for ambiguity error with `AbstractGraph` version +function neighborhood_dists( + graph::AbstractNamedGraph, vertex::Integer, d, distmx=weights(graph); dir=:out +) + return _neighborhood_dists(graph, vertex, d, distmx; dir) +end + +# Fix for ambiguity error with `AbstractGraph` version +function neighborhood_dists( + graph::AbstractNamedGraph, + vertex::Integer, + d, + distmx::AbstractMatrix{<:Real}=weights(graph); + dir=:out, +) + return _neighborhood_dists(graph, vertex, d, distmx; dir) +end + function _mincut(graph::AbstractNamedGraph, distmx) parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx) parent_parity, bestcut = mincut(parent_graph(graph), parent_distmx) diff --git a/test/test_namedgraph.jl b/test/test_namedgraph.jl index 7885f05..37582e6 100644 --- a/test/test_namedgraph.jl +++ b/test/test_namedgraph.jl @@ -131,6 +131,11 @@ end ((1, 4), 3), ] @test issetequal(neighborhood_dists(g, (1, 1), 3), ns_ds) + + # Test ambiguity with Graphs.jl AbstractGraph definition + g = named_path_graph(5) + @test issetequal(neighborhood(g, 3, 1), [2, 3, 4]) + @test issetequal(neighborhood_dists(g, 3, 1), [(2, 1), (3, 0), (4, 1)]) end @testset "Basics (directed)" begin g = NamedDiGraph(["A", "B", "C", "D"])