pnevyk / gryf

Graph data structure library aspiring to be convenient, versatile, correct and performant.
MIT License
69 stars 1 forks source link

Implicit graph helper struct #32

Open pnevyk opened 1 year ago

pnevyk commented 1 year ago

Inspired by pathfinding crate, it would be nice to have a possibility to specify a structure of an implicit graph just by providing a function to get the neighbors of a vertex. Currently, it is necessary to implement several traits (Neighbors and *Weak traits).

There could be a struct Implicit that would be a wrapper over a generic F that would represent a function implementing the Neighbors::neighbors_directed. The rest of Neighbors trait plus all *Weak traits would be implemented by the wrapper.

The implementation of Neighbors::neighbors will be probably a bit tricky, it needs to correctly handle undirected and directed graphs. And the type of Neighbors::NeighborsIter will need to be something like Box<dyn Iterator> so that the implementation of Neighbors::neighbors can chain outgoing and incoming edges.

pnevyk commented 9 months ago

And alternative or complement might be to implement all the mentioned traits for any appropriate F: Fn(...) -> ..., so that a function or closure could be sent directly in place of graph G.