@@ -44,15 +44,14 @@ julia> add_vertices!(g, 2)
44
44
"""
45
45
add_vertices! (g:: AbstractGraph , n:: Integer ) = sum ([add_vertex! (g) for i in 1 : n])
46
46
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
50
-
51
47
"""
52
48
indegree(g[, v])
53
49
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`.
50
+ Return a vector containing the indegrees of every vertex of the graph `g`, where
51
+ the indegree of a vertex is defined as the number of edges which end at that
52
+ vertex. If `v` is specified and is a single vertex, only return the indegree of
53
+ `v`. If `v` is specified and is a vector of vertices, only return the indegrees
54
+ of the vertices in `v`.
56
55
57
56
# Examples
58
57
```jldoctest
@@ -69,6 +68,14 @@ julia> indegree(g)
69
68
1
70
69
0
71
70
1
71
+
72
+ julia> indegree(g,[2,3])
73
+ 2-element Vector{Int64}:
74
+ 0
75
+ 1
76
+
77
+ julia> indegree(g,2)
78
+ 0
72
79
```
73
80
"""
74
81
indegree (g:: AbstractGraph , v:: Integer ) = length (inneighbors (g, v))
@@ -77,8 +84,11 @@ indegree(g::AbstractGraph, vs=vertices(g)) = [indegree(g, x) for x in vs]
77
84
"""
78
85
outdegree(g[, v])
79
86
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`.
87
+ Return a vector containing the outdegrees of every vertex of the graph `g`, where
88
+ the outdegree of a vertex is defined as the number of edges which start at that
89
+ vertex. If `v` is specified and is a single vertex, only return the outdegree of
90
+ `v`. If `v` is specified and is a vector of vertices, only return the outdegrees
91
+ of the vertices in `v`.
82
92
83
93
# Examples
84
94
```jldoctest
@@ -95,6 +105,14 @@ julia> outdegree(g)
95
105
0
96
106
1
97
107
1
108
+
109
+ julia> outdegree(g,[1,2])
110
+ 2-element Vector{Int64}:
111
+ 0
112
+ 1
113
+
114
+ julia> outdegree(g,2)
115
+ 1
98
116
```
99
117
"""
100
118
outdegree (g:: AbstractGraph , v:: Integer ) = length (outneighbors (g, v))
@@ -103,10 +121,12 @@ outdegree(g::AbstractGraph, vs=vertices(g)) = [outdegree(g, x) for x in vs]
103
121
"""
104
122
degree(g[, v])
105
123
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.
124
+ Return a vector containing the degrees of every vertex of the graph `g`, where
125
+ the degree of a vertex is defined as the number of edges which start or end at
126
+ that vertex. For directed graphs, the degree of a vertex is equal to the sum of
127
+ its indegree and outdegree. If `v` is specified and is a single vertex, only
128
+ return the degree of `v`. If `v` is specified and is a vector of vertices, only
129
+ return the degrees of the vertices in `v`.
110
130
111
131
# Examples
112
132
```jldoctest
@@ -123,6 +143,14 @@ julia> degree(g)
123
143
1
124
144
1
125
145
2
146
+
147
+ julia> degree(g,[1,3])
148
+ 2-element Vector{Int64}:
149
+ 1
150
+ 2
151
+
152
+ julia> degree(g,3)
153
+ 2
126
154
```
127
155
"""
128
156
function degree end
0 commit comments