adopt method

({bool grew, bool isNew, int nid}) adopt(
  1. TKey key
)

Allocates a nid for key (or returns the existing one) and resets every dense per-nid slot to its default. Grows the dense arrays via _ensureDenseCapacity when a fresh slot is appended; the onCapacityGrew callback fires from inside that path.

Implementation

({int nid, bool isNew, bool grew}) adopt(TKey key) {
  final result = nids.allocate(key);
  final nid = result.nid;
  if (!result.isNew) {
    return result;
  }
  if (result.grew) {
    _dataByNid.add(null);
    _childrenByNid.add(null);
    _ensureDenseCapacity(nids.length);
  } else {
    _dataByNid[nid] = null;
    _childrenByNid[nid] = null;
  }
  _parentByNid[nid] = kNoParentNid;
  _depthByNid[nid] = 0;
  _expandedByNid[nid] = 0;
  _ancestorsExpandedByNid[nid] = 1;
  return result;
}