closestShellJobIds function
The retained ids closest to requested, closest first, at most limit.
Ties break by id so the order is deterministic.
Implementation
List<String> closestShellJobIds(
String requested,
Iterable<String> retainedIds, {
int limit = 3,
}) {
final ranked = retainedIds.toList()
..sort((a, b) {
final byCloseness = shellJobIdCloseness(
requested,
a,
).compareTo(shellJobIdCloseness(requested, b));
return byCloseness != 0 ? byCloseness : a.compareTo(b);
});
if (ranked.length > limit) return ranked.sublist(0, limit);
return ranked;
}