mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Refactor: inplace stable sort
This commit is contained in:
parent
29eebe4460
commit
f6614a3542
2 changed files with 8 additions and 5 deletions
|
@ -9,11 +9,8 @@ extension IterableExtension<T> on Iterable<T> {
|
|||
List<T> sorted([int Function(T a, T b)? compare]) => toList()..sort(compare);
|
||||
|
||||
/// Return a new stable sorted list
|
||||
List<T> stableSorted([int Function(T a, T b)? compare]) {
|
||||
final tmp = toList();
|
||||
mergeSort(tmp, compare: compare);
|
||||
return tmp;
|
||||
}
|
||||
List<T> stableSorted([int Function(T a, T b)? compare]) =>
|
||||
toList()..stableSort(compare);
|
||||
|
||||
/// Return a string representation of this iterable by joining the result of
|
||||
/// toString for each items
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
extension ListExtension<T> on List<T> {
|
||||
Iterable<T> takeIndex(List<int> indexes) => indexes.map((e) => this[e]);
|
||||
|
||||
|
@ -20,4 +22,8 @@ extension ListExtension<T> on List<T> {
|
|||
return sublist(start, math.min(stop, length));
|
||||
}
|
||||
}
|
||||
|
||||
void stableSort([int Function(T a, T b)? compare]) {
|
||||
mergeSort(this, compare: compare);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue