pnevyk / gryf

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

Add API for adding edges between vertices, inserted if not in graph #57

Closed pnevyk closed 1 year ago

pnevyk commented 1 year ago

This adds API for adding edges, while also adding given vertices if they are not yet present in the graph. In petgraph, there is GraphMap type for this use case. With a new storage which would use the same implementation as petgraph's GraphMap for storing vertices and edges and override find_vertex method, the performance characteristics for add_edge_connecting should be mostly the same as GraphMap::add_edge.

The definition of find_vertex on the Vertices trait requires only Eq trait. However, the implementation of GraphMap requires Ord + Hash. I believe that this is fine, because it is technically possible to put the constraints on the impl itself, i.e., impl<V, ...> Vertices for Map where V: Ord + Hash.