News for hackers. Stuff that matters.
Re:Ladybird: A new cross-platform browser project by Ygg2 on Monday September 12, 2022 @06:01PM (#32817592)
You usually keep next/previous sibling to speed up iteration

See: http://aosabook.org/en/posa/parsing-xml-at-the-speed-of-ligh...

Re:Ladybird: A new cross-platform browser project by c-smile on Monday September 12, 2022 @10:36PM (#32820107)
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).

    struct node {
      weak_ref<element> m_parent;
      uint              m_node_index;
    }

    struct element : node {
      vector<ref<node>> m_children; // strict ownership, sic!
   }