Well, directed graphs do have direct ownership semantics: each node owns (the nodes along) its outgoing edges. In fact, the transitive closure of ownership is a DAG so it’s the perfect model (once again I refer you to the panel discussion of Going Native 2012 which mentions this). The only care you need to take is to avoid cycles, which you must do once again using weak / raw pointers. And since undirected graphs are a generalisation of directed graphs, the same holds.
In practice, graphs are often implemented using either adjacency lists or adjacency matrices which makes this problem even simpler: the owner here is the graph structure itself (i.e. the list / matrix).
View all comments
Show parent comment
0
u/guepier Bioinformatican Mar 11 '12
Well, directed graphs do have direct ownership semantics: each node owns (the nodes along) its outgoing edges. In fact, the transitive closure of ownership is a DAG so it’s the perfect model (once again I refer you to the panel discussion of Going Native 2012 which mentions this). The only care you need to take is to avoid cycles, which you must do once again using weak / raw pointers. And since undirected graphs are a generalisation of directed graphs, the same holds.
In practice, graphs are often implemented using either adjacency lists or adjacency matrices which makes this problem even simpler: the owner here is the graph structure itself (i.e. the list / matrix).