topLevelIndexOf method
O(1) lookup of the top-level index for a node id, or -1 if not found. Uses findLogicalContainerId to resolve fragments to their container.
Implementation
int topLevelIndexOf(String fragmentOrNodeId) {
if (_nodeIndexDirty) _rebuildNodeIndex();
final idx = _topLevelIndex[fragmentOrNodeId];
if (idx != null) return idx;
final containerId = findLogicalContainerId(fragmentOrNodeId);
if (containerId != null) return _topLevelIndex[containerId] ?? -1;
return -1;
}