Skip to content

Docstring update for the indegree, outdegree and degree functions in core.jl #419

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
52 changes: 40 additions & 12 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ julia> add_vertices!(g, 2)
"""
add_vertices!(g::AbstractGraph, n::Integer) = sum([add_vertex!(g) for i in 1:n])

# TODO the behaviour of indegree (and as well outdegree and degree) is very
# badly documented for the case indegree(g, vs) where vs is not a single vertex
# but rather a collection of vertices

"""
indegree(g[, v])

Return a vector corresponding to the number of edges which end at each vertex in
graph `g`. If `v` is specified, only return degrees for vertices in `v`.
Return a vector containing the indegrees of every vertex of the graph `g`, where
the indegree of a vertex is defined as the number of edges which end at that
vertex. If `v` is specified and is a single vertex, only return the indegree of
`v`. If `v` is specified and is a vector of vertices, only return the indegrees
of the vertices in `v`.

# Examples
```jldoctest
Expand All @@ -69,6 +68,14 @@ julia> indegree(g)
1
0
1

julia> indegree(g,[2,3])
2-element Vector{Int64}:
0
1

julia> indegree(g,2)
0
```
"""
indegree(g::AbstractGraph, v::Integer) = length(inneighbors(g, v))
Expand All @@ -77,8 +84,11 @@ indegree(g::AbstractGraph, vs=vertices(g)) = [indegree(g, x) for x in vs]
"""
outdegree(g[, v])

Return a vector corresponding to the number of edges which start at each vertex in
graph `g`. If `v` is specified, only return degrees for vertices in `v`.
Return a vector containing the outdegrees of every vertex of the graph `g`, where
the outdegree of a vertex is defined as the number of edges which start at that
vertex. If `v` is specified and is a single vertex, only return the outdegree of
`v`. If `v` is specified and is a vector of vertices, only return the outdegrees
of the vertices in `v`.

# Examples
```jldoctest
Expand All @@ -95,6 +105,14 @@ julia> outdegree(g)
0
1
1

julia> outdegree(g,[1,2])
2-element Vector{Int64}:
0
1

julia> outdegree(g,2)
1
```
"""
outdegree(g::AbstractGraph, v::Integer) = length(outneighbors(g, v))
Expand All @@ -103,10 +121,12 @@ outdegree(g::AbstractGraph, vs=vertices(g)) = [outdegree(g, x) for x in vs]
"""
degree(g[, v])

Return a vector corresponding to the number of edges which start or end at each
vertex in graph `g`. If `v` is specified, only return degrees for vertices in `v`.
For directed graphs, this value equals the incoming plus outgoing edges.
For undirected graphs, it equals the connected edges.
Return a vector containing the degrees of every vertex of the graph `g`, where
the degree of a vertex is defined as the number of edges which start or end at
that vertex. For directed graphs, the degree of a vertex is equal to the sum of
its indegree and outdegree. If `v` is specified and is a single vertex, only
return the degree of `v`. If `v` is specified and is a vector of vertices, only
return the degrees of the vertices in `v`.

# Examples
```jldoctest
Expand All @@ -123,6 +143,14 @@ julia> degree(g)
1
1
2

julia> degree(g,[1,3])
2-element Vector{Int64}:
1
2

julia> degree(g,3)
2
```
"""
function degree end
Expand Down