W3C home > Mailing lists > Public > www-archive@w3.org > January 2014

Graph::delete_vertex should not use _edges_at (in all cases)

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Date: Fri, 24 Jan 2014 00:02:52 +0100
To: bug-graph@rt.cpan.org
Message-ID: <9473e9581l20n1kjt7225lgrtkgkcd23po@hive.bjoern.hoehrmann.de>

  In Graph.pm v0.96 the `delete_vertex` function is excruciatingly slow,
at least for the graphs I usually handle. Devel::NYTProf told me this is
caused by _edges_at. I have also found that retrieving and deleting the
edges around a vertex I want to delete is very fast, so

  sub delete_vertex_fast {
      my $g = shift;
      my $V = $g->[ $g->SUPER::_V ];
      return $g unless $V->has_path( @_ );

      $g->delete_edge($_[0], $_) for $g->successors($_[0]);
      $g->delete_edge($_, $_[0]) for $g->predecessors($_[0]);

      $V->del_path( @_ );
      $g->[ $g->SUPER::_G ]++;
      return $g;

is something I am considering using in a derived package. Testing shows
a speedup of an order of magnitude at least (and I intend to test this
is kept in proper working condition by cloning random graphs, deleting
the same random vertices in both of them, and comparing the result). If
a new maintainer is found for the module, I am happy to write a patch.

Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
Received on Thursday, 23 January 2014 23:03:16 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:44:28 UTC