Skip to content

Throw a BoundsError when setting an attribute for a vertex that doesn't exist #2

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

Closed
CameronBieganek opened this issue May 8, 2020 · 5 comments

Comments

@CameronBieganek
Copy link

The current behavior is that g[:a] = "hello" sets the vertex attribute for vertex :a to "hello" and it creates a new vertex with the index :a if it doesn't exist already. This syntax looks convenient, but I think it's a bit dangerous. Normally in Julia if you try to set a value at an index that doesn't exist, you get a BoundsError. I think it would be best to stick with that convention here. So if you want to add a vertex you have to explicitly add it via add_vertex!(g, :a, "hello").

@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

I modeled this behavior on Dict, which does create new indexes.

@bramtayl
Copy link
Collaborator

bramtayl commented May 9, 2020

Given that Dict does the same thing, I'm not too concerned, but feel free to reopen if you disagree.

@bramtayl bramtayl closed this as completed May 9, 2020
@CameronBieganek
Copy link
Author

CameronBieganek commented May 10, 2020

One thing that I like about the SimpleGraphs API is that the data structure used to store the graph is abstracted away from the user. In other words, the user uses add_vertex! and add_edge! without any hint of how the graph is stored under the hood. But with the MetaGraphsNext API, it's pretty clear that the graph is stored as a dictionary.

Also, I find it a little weird that if I want to add a new vertex with no metadata, I have to do this:

g[:a] = nothing

(and likewise for adding edges with no metadata).

EDIT:
It's intuitive for access to meta data to follow the dictionary API, but it's not very intuitive for manipulations of the graph structure to follow the dictionary API.

@bramtayl
Copy link
Collaborator

I'm not a big fan of g[:a] = nothing either... I could just add a method

add_vertex!(g::MetaGraph, label) = add_vertex!(g, label, nothing)

?

@CameronBieganek
Copy link
Author

I could just add a method

Yeah, that seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants