Skip to content

Replace "code" with "index" #17

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
gdalle opened this issue Sep 7, 2021 · 8 comments
Closed

Replace "code" with "index" #17

gdalle opened this issue Sep 7, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@gdalle
Copy link
Member

gdalle commented Sep 7, 2021

The whole MetaGraphsNext package uses the word "code" for what is usually called the index of a vertex. Maybe we could change that to get closer to LightGraphs conventions?

@gdalle
Copy link
Member Author

gdalle commented Nov 11, 2021

Not sure who's still watching this repo, but @bramtayl I might move forward with this

@bramtayl
Copy link
Collaborator

I'm still watching. Still agree with #16 (comment) but I'm ok changing it too.

@gdalle
Copy link
Member Author

gdalle commented Nov 11, 2021

If I understand correctly, you worry that there may be a confusion between

  • the method that takes a label and returns the vertex index (currently named code_for)
  • the method getindex that takes a label and returns the vertex metadata

I hadn't understood this before, and I think you're right. What would you think about an approach à la MetaGraphs, where getindex actually returns the vertex index instead of the metadata? It would make some of the code a bit heavier, but I think we may gain in clarity?

@gdalle
Copy link
Member Author

gdalle commented Nov 11, 2021

Of course that would mean going from a Dict to an Array for vertex- and edge-level metadata, but maybe we would even gain some performance in the process?

@bramtayl
Copy link
Collaborator

bramtayl commented Nov 12, 2021

In base, getindex means roughly get_at_index: you pass an index to a dict, and Julia returns what exists at that index. It has the convenient dictionary[index] syntax.

setindex! roughly means set_at_index!: you pass an index and a value to a dict, and Julia puts the value at that index. It has the convenient dictionary[index] = value syntax.

Because these have a convenient syntax, I wanted to reserve them for very common operations (using labels instead of codes, which I encourage). I think it might be confusing if we call codes indices, but pass labels (not codes/indices) to getindex and setindex!.

getindex actually returns the vertex index instead of the metadata

That might be ok, but then how would `setindex! work?

@gdalle
Copy link
Member Author

gdalle commented Nov 12, 2021

I see how this might be confusing, however due to the convenient dictionary[index] syntax, users will never call the function getindex themselves. As for setindex!, I think in my setting we would throw an error.
In the end it comes down to the most common operation you want to perform:

  • if you love tampering with metadata, g[label] = data is fine
  • if you love applying graph algorithms, g[label] = index / code is better because it gives you access to index-based LightGraphs routines

@gdalle
Copy link
Member Author

gdalle commented Nov 12, 2021

I guess I'm more used to building the metadata on vertices and edges once and for all, and applying lots of graph algorithms afterwards, which is why the second option made more sense to me

@gdalle
Copy link
Member Author

gdalle commented Nov 29, 2021

Closing this for now

@gdalle gdalle closed this as completed Nov 29, 2021
@gdalle gdalle added the enhancement New feature or request label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants