Skip to content

Commit 96bb8ff

Browse files
Update core.jl
Fixed the documentation of the functions indegree, outdegree and degree and removed the TODO comment in the source code that was asking for it.
1 parent 12ac6ba commit 96bb8ff

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

src/core.jl

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ julia> add_vertices!(g, 2)
4444
"""
4545
add_vertices!(g::AbstractGraph, n::Integer) = sum([add_vertex!(g) for i in 1:n])
4646

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

5148
"""
5249
indegree(g[, v])
5350
54-
Return a vector corresponding to the number of edges which end at each vertex in
55-
graph `g`. If `v` is specified, only return degrees for vertices in `v`.
51+
Return a vector containing the indegrees of every vertex of the graph `g`, where
52+
the indegree of a vertex is defined as the number of edges which end at that
53+
vertex. If `v` is specified and is a single vertex, only return the indegree of
54+
`v`. If `v` is specified and is a vector of vertices, only return the indegrees
55+
of the vertices in `v`.
5656
5757
# Examples
5858
```jldoctest
@@ -69,6 +69,14 @@ julia> indegree(g)
6969
1
7070
0
7171
1
72+
73+
julia> indegree(g,[2,3])
74+
2-element Vector{Int64}:
75+
0
76+
1
77+
78+
julia> indegree(g,2)
79+
0
7280
```
7381
"""
7482
indegree(g::AbstractGraph, v::Integer) = length(inneighbors(g, v))
@@ -77,8 +85,11 @@ indegree(g::AbstractGraph, vs=vertices(g)) = [indegree(g, x) for x in vs]
7785
"""
7886
outdegree(g[, v])
7987
80-
Return a vector corresponding to the number of edges which start at each vertex in
81-
graph `g`. If `v` is specified, only return degrees for vertices in `v`.
88+
Return a vector containing the outdegrees of every vertex of the graph `g`, where
89+
the outdegree of a vertex is defined as the number of edges which start at that
90+
vertex. If `v` is specified and is a single vertex, only return the outdegree of
91+
`v`. If `v` is specified and is a vector of vertices, only return the outdegrees
92+
of the vertices in `v`.
8293
8394
# Examples
8495
```jldoctest
@@ -95,6 +106,14 @@ julia> outdegree(g)
95106
0
96107
1
97108
1
109+
110+
julia> outdegree(g,[1,2])
111+
2-element Vector{Int64}:
112+
0
113+
1
114+
115+
julia> outdegree(g,2)
116+
1
98117
```
99118
"""
100119
outdegree(g::AbstractGraph, v::Integer) = length(outneighbors(g, v))
@@ -103,10 +122,12 @@ outdegree(g::AbstractGraph, vs=vertices(g)) = [outdegree(g, x) for x in vs]
103122
"""
104123
degree(g[, v])
105124
106-
Return a vector corresponding to the number of edges which start or end at each
107-
vertex in graph `g`. If `v` is specified, only return degrees for vertices in `v`.
108-
For directed graphs, this value equals the incoming plus outgoing edges.
109-
For undirected graphs, it equals the connected edges.
125+
Return a vector containing the degrees of every vertex of the graph `g`, where
126+
the degree of a vertex is defined as the number of edges which start or end at
127+
that vertex. For directed graphs, the degree of a vertex is equal to the sum of
128+
its indegree and outdegree. If `v` is specified and is a single vertex, only
129+
return the degree of `v`. If `v` is specified and is a vector of vertices, only
130+
return the degrees of the vertices in `v`.
110131
111132
# Examples
112133
```jldoctest
@@ -123,6 +144,14 @@ julia> degree(g)
123144
1
124145
1
125146
2
147+
148+
julia> degree(g,[1,3])
149+
2-element Vector{Int64}:
150+
1
151+
2
152+
153+
julia> degree(g,3)
154+
2
126155
```
127156
"""
128157
function degree end

0 commit comments

Comments
 (0)