parseAdjacency function
Parses the compact text form produced by serializeAdjacency back into an
Adjacency list sized to maxNodeIndex + 1.
An empty or whitespace-only string yields an empty graph. Malformed integer tokens throw FormatException. Node entries may appear in any order; gaps in the index range become isolated nodes.
Example:
parseAdjacency('0>1,2;1;2>0'); // [[1, 2], [], [0]]
Audited: 2026-06-12 11:26 EDT
Implementation
Adjacency parseAdjacency(String text) {
final String trimmed = text.trim();
if (trimmed.isEmpty) return <List<int>>[];
// First pass: parse each "index>neighbors" record into (index, neighbors).
final List<(int, List<int>)> records = <(int, List<int>)>[
for (final String part in trimmed.split(';'))
if (part.isNotEmpty) _parseRecord(part),
];
return _assemble(records);
}