Skip to content

Allow simultaneous use of the primitive index and the custom index #4

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 · 7 comments

Comments

@CameronBieganek
Copy link

Suppose I have a graph g with 2 nodes, which are labeled :a and :b by a custom vertex. It would be nice if I could freely mix my usage of the primitive index (the underlying integer index) and the custom index. For example, it would be nice if the following were allowed:

# Access vertex attributes:
g[1]
g[:a]

# Access edge attributes:
g[1, 2]
g[1, :b]
g[:a, 2]
g[:a, :b]

# Add vertices:
add_vertex!(g)      # adds a vertex without the custom index set
add_vertex!(g, :c)  # add a vertex with custom index set to :c

# Add edges:
add_edge!(g, 2, 3)
add_edge!(g, 2, :c)
add_edge!(g, :b, 3)
add_edge!(g, :b, :c)

I think in order for this to work, you would have to do one of the following:

  • Disallow the usage of Integers for the custom index.
  • Wrap custom indices in a special type, like V(:a) or V(2). (Then custom indices could still be integers.)
@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

I agree this would be a nice feature to have and I'd be inclined to go with the second option. Even in the second option, we'd have to disallow V to be used as the label type. That is, either option would require putting some restrictions on the type. When I designed the package, I had intended users to mostly add vertexes and edges through indexing; functions which refer to vertex code like add_edge! are intended only for compatibility with AbstractGraph.

@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

A minimal step would be adding a sentence like the last one in my comment above to the docstring.

@bramtayl
Copy link
Collaborator

bramtayl commented May 9, 2020

Hopefully the clarifications in 8080aab and 8080aab should help; feel free to reopen if not

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

CameronBieganek commented May 10, 2020

Even in the second option, we'd have to disallow V to be used as the label type. That is, either option would require putting some restrictions on the type.

I'm not sure I follow you here. Do you mean that V(V(:a)) would have to be explicitly disallowed? I would hope that no one would be silly enough to try that. 🙂

@bramtayl
Copy link
Collaborator

I was wrong, nevermind. I was thinking that you would have to disallow V as a vertex code, but AbstractGraphs are required to have integers as vertex codes. Yes, I think passing vertex labels wrapped in a type is would be a reasonable option. Maybe we can bikeshed the name? I'm not a big fan of abbreviations

@bramtayl bramtayl reopened this May 10, 2020
@CameronBieganek
Copy link
Author

CameronBieganek commented May 11, 2020

Well, I was thinking something like

struct VertexIndex{T}
    i::T
end

const V = VertexIndex

That way you can use the full name in your method definitions, but the abbreviation when you are indexing. Otherwise things like

g[VertexIndex(:a), VertexIndex(:b)] = "hello"

would get a bit bulky.

However, I'm kind of going around in circles on this as I think about it. It would be nice to be able to use bare symbols like g[:a, :b], and being able to do g[1, :b] is probably not that important.

As long I'm able to pick either the simple integer index or a custom index at the beginning of a project, after I've made that choice I would probably stick with that choice for all of my indexing operations for that project. So, in other words, the indexing status quo on master is probably fine. :)

@bramtayl
Copy link
Collaborator

Ok, well, feel free to open a PR if you think this would be useful.

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