rebuild method

void rebuild(
  1. void build()
)

Convenience for clear+rebuild paths. Suppresses callbacks, clears the order, runs the closure (which populates via addKey), then rebuilds the reverse-index buffer (since addKey only appends to orderNids and does not write indexByNid) and runs the O(N) post-order subtree-size pass. Owns "clear + fill + finalize all derived state" so the closure body shrinks to just the populate work.

Implementation

void rebuild(void Function() build) {
  runWithSubtreeSizeUpdatesSuppressed(() {
    clear();
    build();
    rebuildIndex();
    _rebuildSubtreeSizes();
  });
}