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

Discussion in 'Python' started by George Sakkis, Jan 29, 2007.

  1. 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.next() == v

    True
    >>> g.vertices.next() 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
     
    George Sakkis, Jan 29, 2007
    #1
    1. Advertising

  2. > 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.
     
    Szabolcs Nagy, Jan 29, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dr. Colombes
    Replies:
    9
    Views:
    387
    Claudio Grondi
    Jan 4, 2006
  2. Jef Driesen
    Replies:
    3
    Views:
    2,553
    mlimber
    Jan 24, 2006
  3. Almoni
    Replies:
    0
    Views:
    3,104
    Almoni
    Jan 17, 2010
  4. Replies:
    3
    Views:
    180
    Horst Duchene
    Apr 20, 2005
  5. Emilio Mayorga
    Replies:
    6
    Views:
    341
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page