handleParentChanged method
Wired up as the subscriber for NodeStore.onParentChanged. Shifts
the moved subtree's contribution from the old parent's ancestor
chain to the new parent's chain. No-op when oldParent equals
newParent, when the moved subtree contributes nothing, or when
updates are currently suppressed (e.g. inside rebuild).
Safe even though NodeStore.setParent has already written
parentByNid[nid] = newParent at call time — the walks start from
oldParent / newParent (not from nid) and traverse ancestor
chains via the parentByNid callback; only the moved node's own
slot was overwritten, ancestor slots are untouched.
Implementation
void handleParentChanged(int nid, int oldParent, int newParent) {
if (_suppress) return;
if (oldParent == newParent) return;
if (nid < 0 || nid >= _subtreeSizeByNid.length) return;
final delta = _subtreeSizeByNid[nid];
if (delta == 0) return;
if (oldParent != kNoParentNid) {
bumpFromSelf(oldParent, -delta);
}
if (newParent != kNoParentNid) {
bumpFromSelf(newParent, delta);
}
}