setExpanded method
Sets the expansion flag for key. key must be registered.
By default propagates the change through _ancestorsExpandedByNid for
descendants so ancestor-expansion queries stay O(1). Pass propagate
as false in bulk paths that rebuild the cache wholesale via
rebuildAllAncestorsExpanded — per-call propagation would compound to
O(N × subtree) across the batch.
Implementation
void setExpanded(TKey key, bool expanded, {bool propagate = true}) {
final nid = nids[key]!;
final newVal = expanded ? 1 : 0;
if (_expandedByNid[nid] == newVal) return;
_expandedByNid[nid] = newVal;
// Children's ae bit equals expanded(key) && ae(key). If ae(key) is 0,
// children's ae is already 0 and unaffected by this flip.
if (propagate && _ancestorsExpandedByNid[nid] != 0) {
_propagateAncestorsExpandedToDescendants(key, newVal);
}
}