1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 05:07:35 +00:00

AK: Make quick_sort() a little more ergonomic

Now it actually defaults to "a < b" comparison, instead of forcing you
to provide a trivial less-than comparator. Also you can pass in any
collection type that has .begin() and .end() and we'll sort it for you.
This commit is contained in:
Andreas Kling 2020-03-03 16:01:37 +01:00
parent 058cd1241e
commit 686ade6b5a
14 changed files with 35 additions and 23 deletions

View file

@ -221,7 +221,7 @@ int main(int argc, char** argv)
Vector<Index> byte_vector;
expand_list(tokens, byte_vector);
quick_sort(byte_vector.begin(), byte_vector.end(), [](auto& a, auto& b) { return a.m_from < b.m_from; });
quick_sort(byte_vector, [](auto& a, auto& b) { return a.m_from < b.m_from; });
/* Process each file */
for (auto& file : files) {
cut_file(file, byte_vector);

View file

@ -326,7 +326,7 @@ int do_file_system_object_long(const char* path)
files.append(move(metadata));
}
quick_sort(files.begin(), files.end(), [](auto& a, auto& b) {
quick_sort(files, [](auto& a, auto& b) {
if (flag_sort_by_timestamp) {
if (flag_reverse_sort)
return a.stat.st_mtime > b.stat.st_mtime;
@ -382,7 +382,7 @@ int do_file_system_object_short(const char* path)
if (names.last().length() > longest_name)
longest_name = name.length();
}
quick_sort(names.begin(), names.end(), [](auto& a, auto& b) { return a < b; });
quick_sort(names);
size_t printed_on_row = 0;
size_t nprinted = 0;

View file

@ -50,7 +50,7 @@ int main(int argc, char** argv)
lines.append(buffer);
}
quick_sort(lines.begin(), lines.end(), [](auto& a, auto& b) {
quick_sort(lines, [](auto& a, auto& b) {
return strcmp(a.characters(), b.characters()) < 0;
});

View file

@ -184,7 +184,7 @@ int main(int, char**)
threads.append(&it.value);
}
quick_sort(threads.begin(), threads.end(), [](auto* p1, auto* p2) {
quick_sort(threads, [](auto* p1, auto* p2) {
return p2->times_scheduled_since_prev < p1->times_scheduled_since_prev;
});