Graph library for Python (was: Re: python bijection)
M.-A. Lemburg
mal at egenix.com
Mon Dec 7 14:51:15 EST 2009
geremy condra wrote:
> How interested are you in a C port of graphine? I haven't had
> any specific requests for it, but if its something you need I
> can shuffle it towards the top of the to do pile.
There are two main reasons for a C implementation:
1. performance
2. memory footprint
These are important when using graphs with lots of nodes or
when using lots of graphs or operations on graphs in tight
loops.
However, to get such a new type into the core, you need to start
a PEP process and hash out the API some more, esp. with respect
to integration with the other core types, such as dictionaries
and lists of tuples for both creation and as alternative
representation.
Some other comments (in no particular order):
* the "name" default of using id(node) is not ideal, since
id(node) will return the address of the object and that
can be subject to reuse within the lifetime of the process;
using a global (thread-safe) counter would be safer
* Graph.__init__ should be able to take a list or set
of nodes and edges as initializer
* Graph.__setitem__ could be mapped to .add_node() for
convenience
* Graph.__length__ could be mapped to .size() for
convenience
* Graph.__iter__ could be mapped to an iterator using
the fastest traversal method for the graph nodes
(ie. order does not matter, it's only important that
all nodes are found as fast as possible)
* Graph could also benefit from some bulk update methods,
e.g. to update weights on all edges or nodes by passing
in a dictionary mapping names to attribute values
* Graph could benefit from some bulk query methods,
such as .get_node_attributes() and .add_edges().
* Node.__getitem__ could be mapped to .data.__getitem__
(following the approach taken by ElementTree); same
for Edge.__getitem__
* Node.__setitem__ could be mapped to .data.__setitem__
(following the approach taken by ElementTree); same
for Edge.__setitem__
* I'd add a DirectedEdge alias for Edge and a new
UndirectedEdge as subclass which has is_directed=False;
makes code more readable
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Dec 07 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list