dominikbraun / graph

A library for creating generic graph data structures and modifying, analyzing, and visualizing them.
https://graph.dominikbraun.io
Apache License 2.0
1.8k stars 94 forks source link

Function for creating a graph with the same traits as another graph #105

Closed dominikbraun closed 1 year ago

dominikbraun commented 1 year ago

There should be a function (or method) that creates (or updates) a graph so that the graph has the same traits and hash as a given input graph, for example NewWithSameTraitsAs[K comparable, T any](g Graph[K, T]) (Graph[K, T], error) or Graph.TraitsFrom[K comparable, T any](source Graph[K, T]). Note that these two suggestions have the problem that they don't indicate that the hashing function is adopted as well.

This call should then be replaced accordingly: https://github.com/dominikbraun/graph/blob/af07d9489ab096a0fe898b53892076c4ce800480/trees.go#L38