liveSiblingAt method

TKey? liveSiblingAt(
  1. TKey? parent,
  2. int index
)

The live sibling at index under parent (or among the roots when parent is null), or null when index is out of range.

Non-allocating variant of getLiveChildren(parent)[index] / liveRootKeys[index], for the per-build and per-pointer-move paths that want ONE neighbour rather than the list. Both of those return a fresh copy of the whole sibling list, which is pure waste when the caller indexes it once and discards it. Same motivation as liveChildCount and hasLiveChildren.

Implementation

TKey? liveSiblingAt(TKey? parent, int index) {
  if (index < 0) {
    return null;
  }
  final List<TKey> full;
  if (parent == null) {
    full = _roots;
  } else {
    final children = _childListOf(parent);
    if (children == null) {
      return null;
    }
    full = children;
  }
  if (_anim.pendingDeletionCount == 0) {
    return index < full.length ? full[index] : null;
  }
  int live = 0;
  for (final k in full) {
    if (_isPendingDeletion(k)) {
      continue;
    }
    if (live == index) {
      return k;
    }
    live++;
  }
  return null;
}