Closed maxfischer2781 closed 6 years ago
Current thoughts:
neighbourhood
should correspond to __graphi_neighbourhood__
. This allows to dynamically add new algorithms without risking conflicts with the standard data model.neighbourhood(graph, *args, **kwargs)
graph.__graphi_neighbourhood__
is not defined, default.graph.__graphi_neighbourhood__(*args, **kwargs)
returns NotImplemented
, default.__operator__ = None
to forbid an operation, even if it is defined on a parent class.
graph.__graphi_neighbourhood__ = None
if an algorithm does not apply - e.g. an undirected algorithm on a directed graph.graph.__graphi_neighbourhood__ = NotImplemented
if an algorithm is not optimised - e.g. after changing the internal data structure.
The only explicit graph algorithm
neighbourhood
is defined as a method for historical reasons. This allows for optimisations depending on the data structure. However, this approach has several shortcomings:.abc.Graph
must re-implement every algorithm. This is especially the case for Cython extensions..abc.Graph
, which is a questionable choice for an ABC.I suggest an operator-like approach: each algorithm corresponds to one (or more) special methods. Graph implementations can provide such a method for efficient implementations. Otherwise, the algorithm uses a default implementation.