Support both directed and undirected graphs for views
redbug312 opened this issue · comments
I'm trying to implement UndirectedView
. I notice the views focus on the non-trivial case e.g. DirectedView
for undirected, ReverseView
for directed. This may cause trouble if algorithms contain views like this
pub struct BiBFS<'a, G, I = DefaultIdMap>
where
G: NodeProvider<Dir = Directed>, // ReverseView requires Directed
I: IdMap,
{
forward: &'a G,
reverse: ReverseView<'a, G>,
starting_nodes: Vec<NodeId>,
ending_nodes: Vec<NodeId>,
state: State<I>,
}
Here BiBFS
can only support directed graphs, and it must define another structure for undirected graphs. I think the views should cover the trivial case to avoid that.
Algorithms shouldn't contain the struct itself. The role of the provide
layer is exactly this. It decouples the algorithm from the underlying structures. For example if the algorithm relies on ReverseView
, it should work with any directed storage. Becuase ReverseView
is itself a directed storage(which just proxies the calls to provider functions).
So I believe your example should look like this:
pub struct BiBFS<'a, G, V, I = DefaultIdMap>
where
G: NodeProvider<Dir = Directed>, // ReverseView requires Directed
V: FrozenView<Graph = G>,
I: IdMap,
{
forward: &'a G,
reverse: &'a V,
starting_nodes: Vec<NodeId>,
ending_nodes: Vec<NodeId>,
state: State<I>,
}