name attribute is treated in a special way by the internals of the Python interface; in particular, the
name attribute is indexed internally in a Python dict so looking up the ID of a node given its
name attribute is an O(1) operation (on average). The index is invalidated if you mutate the graph or change the
name attribute. This happens here and here in the C implementation of the Python interface.
Furthermore, there are dedicated code paths for handling
g.vs.find(name="something"), which is the idiomatic way to get a handle for the
Vertex object corresponding to the given name. (Note that
Vertex objects are ephemeral, though, they are essentially a container for a graph and a vertex index, so they become invalid when you mutate the graph). So,
g.vs.find(name="something") should be able to look up a vertex with a given name in constant amortized time.
Also, any method of the
Graph object that accepts a single vertex index as an input should also accept a vertex name instead, and it will look up the index of the vertex corresponding the given name using the index. So, if you have a vertex with
name equal to
"A" and you want to get its degreee, you can simply call
g.degree("A"). For example:
>>> from igraph import Graph
>>> g=Graph.GRG(25, 0.4)
>>> g.vs["name"] = list("ABCDEFGHIJKLMNOPQRSTUVWXY")
>>> g.degree(8) == g.degree("I")
Note that the existence of the index assumes that the vertex names are unique, but this is not enforced in any way If you accidentally assign the same name to two vertices, the index will map the name to one of the vertices but it’s unspecified which one will be the “winner” (and you won’t get any warnings either).