Skip to content

Commit f383c54

Browse files
authored
Merge pull request #24 from DarkLord0206/master
Checked for uniqueness of the label
2 parents 8ac9017 + 7af9354 commit f383c54

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Manifest.toml
22
docs/build/
3+
.vscode/settings.json

docs/src/tutorial_graphs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ julia> has_vertex(cities, 4)
6464
false
6565
```
6666

67+
Note that we can't add the same city (i.e. vertex label) twice:
68+
69+
```jldoctest graphs
70+
julia> add_vertex!(cities, :London, "Italy")
71+
false
72+
73+
julia> nv(cities)
74+
3
75+
```
76+
6777
We then check the set of edges:
6878

6979
```jldoctest graphs

src/graphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ end
7878
7979
Add a vertex to MetaGraph `g` with label `label` having metadata `data`.
8080
81-
Return true if the vertex has been added, false otherwise.
81+
Return true if the vertex has been added, false incase the label already exists or vertex was not added.
8282
"""
8383
function Graphs.add_vertex!(g::MetaGraph, label, data)
84+
if haskey(g,label)
85+
return false
86+
end
8487
added = add_vertex!(g.graph)
8588
if added
8689
v = nv(g)

0 commit comments

Comments
 (0)