title: How to implement a tree structure, but still be able to reference it as a flat array by index?
body: <p>I want to have a tree in memory, where each node can have multiple children. I would also need to reference this tree as a flat structure by index. for example:</p>
  
  <pre>
      a1
         b1
         b2
         b3
      c1
         d1
            e1
            e2
         d2
            f1
  </pre>
  
  <p>Would be represented as a flat structure as I laid out (i.e.; a1=0, b1=1, d1=5, etc..)</p>
  
  <p>Ideally I would want lookup by index to be O(1), and support insert, add, remove, etc.. with a bonus of it being threadsafe, but if that is not possible, let me know.</p>