4 ms·
You can store index of the node in parent m_children collection. Iteration on array is faster (cache locality) than DL list traversal. And there are issues whe
by c-smile 4y ago
You can store index of the node in parent m_children collection.
Iteration on array is faster (cache locality) than DL list traversal. And there are issues when you traverse tree while changing it.
In any case I've found that storing child nodes as m_children collection is more convenient in many cases. At least in Sciter (https://sciter.com https://sciter.com).
struct node {
weak_ref<element> m_parent;
uint m_node_index;
}
struct element : node {
vector<ref<node>> m_children; // strict ownership, sic!
}