Lars Stoltenow


Graph::Fast - graph data structures and algorithms, just faster.


 # todo


Graph::Fast implements a mathematical abstract data structure, called graph, that models relations between objects with vertices and edges.

Graph::Fast vs Graph

While Graph is a module with a lot of features, it is not really fast. Graph::Fast doesn't implement all the features, but it is much faster. Graph::Fast is for you if you need the most important things done very fast.


Available functions are:

new(optional options...)

Constructs a new Graph::Fast object.

The constructor takes optional parameters as a hash. Currently there are no options.


Returns the number of edges in the graph.


Returns the number of vertices in the graph.


Adds a vertex with the specified name to the graph. Names must be unique. It is safe to call this with a name that already exists in the graph.


Deletes a vertex with the specified name from the graph. All edges that go from or to the specified edges will be deleted as well. It is safe to call this with a name that doesn't exist.

add_edge($from => $to, $weight, $user_data)

Adds a directed edge to the graph, pointing from vertex named $from to $to. The edge has a weight of $weight. Application-specific data can be added to the edge.

del_edge($from => $to)

Removes an edge that points from named vertex $from to $to from the graph.

It is safe to call this for edges that do not exist.

dijkstra($from => $to)

Invokes Dijkstra's algorithm on the graph to find the shortest path from source vertex $from to destination vertex $to.

If a path is found, it is returned as a list of edges. The edges are hashrefs with from, to, weight and possibly user_data keys. If no path is found, an empty list is returned.


Many features are missing. This includes basic features.

Vertices currently cannot be deleted once added to the graph.

It is unclear how to deal with multiedges (two different edges that connect the same pair of vertices). The behaviour will likely change in the future. Currently edges can and will exist only once.




Graph - slower, but a lot more features

Boost::Graph - faster, written in C++


Made 2010 by Lars Stoltenow. This is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

Hosting generously
sponsored by Bytemark