[Boost.Graph] graph.vertices property creates new objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Sakkis

    #1

    [Boost.Graph] graph.vertices property creates new objects

    I've just started toying with the python bindings of BGL and I'm
    puzzled from the following:
    >>from boost.graph import Graph
    >>g = Graph()
    >>v = g.add_vertex()
    >>g.vertices.ne xt() == v
    True
    >>g.vertices.ne xt() is v
    False

    It seems that the vertices iterator creates new vertex objects every
    time instead of iterating over the existing ones. This essentially
    prevents, among other things, storing vertices as keys in a dictionary
    since the hashes of the stored and the new vertex differ although they
    compare equal. Is this really what's happening, and if so, why ?

    George

  • Szabolcs Nagy

    #2
    Re: [Boost.Graph] graph.vertices property creates new objects

    It seems that the vertices iterator creates new vertex objects every
    time instead of iterating over the existing ones. This essentially
    i don't know much about bgl, but this is possible since vertices are
    most likely not stored as python objects inside boost
    prevents, among other things, storing vertices as keys in a dictionary
    since the hashes of the stored and the new vertex differ although they
    compare equal. Is this really what's happening, and if so, why ?
    that sounds bad, fortunately __hash__ can be overriden so even if id()
    differs hash() can be the same for the same vertex.
    if __hash__ is not handled then it's a bug in bgl imho.

    Comment

    Working...