Fastest way to populate a DataTree from arrays

Fastest way to populate a DataTree from arrays. I have the following arrays ( Point3d[n][][] ), three dimensional that is. Each sub-array may have different length, and the third dimension arrays (darkest) should be merged into one single (long) Branch in the Datatree (0…4 --> one long array):


I create my raw data using arrays to avoid data races with Parallel.For, but adding the array content to the Datatree takes 6 times longer than creating the data in the arrays… I couldn’t find any Datatree.Capacity property to speed things up.

// Rolf

OK, I found that I can append a path with tree.AddRange(…) if I prepare the arrays with the final type (GH_Point instead of Point3d, etc). Code:

    // Pack the array results into a Datatree
    var tv_tree = new DataTree<GH_Point>();
    for (var i = 0; i < ctv_arr.Length; i++)
      var path = new GH_Path(0, i);
      if (ctv_arr[i] == null) { break; }
      // append the third (last) dimension to the same path
      for (var d = 0; d < ctv_arr[i].Length; d++)
        if (ctv_arr[i][d] == null) { break; }
        tv_tree.AddRange(ctv_arr[i][d], path);        

It just worx.

// Rolf

1 Like