|
|
|
|
|
by simonask
59 days ago
|
|
Depending on the shape of the graph (arbitrarily connected, DAG, etc.), it just boils down to whatever convenient way you have of storing lists. Node data in one list. Indices of node parents in another list of the same length. If you need to find children quickly, you can have another list of lists containing children indices. The key is to consider the node’s position in the list as its ID, and refer to nodes by that index instead of the pointer. In most cases, this model is both easier to work with and more performant. For example, you can usually get by with 32-bit indices instead of 64-bit pointers, so things are much more likely to be in cache. |
|