setParent method

void setParent(
  1. TKey key,
  2. TKey? parent
)

Sets the parent of key to parent (or null for root) and refreshes the cached _ancestorsExpandedByNid bit for key, propagating the change through key's subtree.

Does not maintain the visibility-subtree-size cache (that lives on the controller) — callers that need that bookkeeping must capture the old parent first via parentNidOf and adjust externally before calling.

Implementation

void setParent(TKey key, TKey? parent) {
  final nid = nids[key]!;
  final newParentNid = parent == null ? kNoParentNid : nids[parent]!;
  _parentByNid[nid] = newParentNid;
  final newAe = _computeAncestorsExpandedNid(nid);
  if (_ancestorsExpandedByNid[nid] != newAe) {
    _ancestorsExpandedByNid[nid] = newAe;
    final childAe = (newAe != 0 && _expandedByNid[nid] != 0) ? 1 : 0;
    _propagateAncestorsExpandedToDescendants(key, childAe);
  }
}