mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-08 20:10:15 +00:00
29 lines
620 B
C++
29 lines
620 B
C++
#pragma once
|
|
|
|
namespace mapbox {
|
|
namespace geometry {
|
|
namespace wagyu {
|
|
|
|
template <typename It, class Compare, class MethodOnSwap>
|
|
void bubble_sort(It begin, It end, Compare c, MethodOnSwap m) {
|
|
if (begin == end) {
|
|
return;
|
|
}
|
|
bool modified = false;
|
|
auto last = end - 1;
|
|
do {
|
|
modified = false;
|
|
for (auto itr = begin; itr != last; ++itr) {
|
|
auto next = std::next(itr);
|
|
if (!c(*itr, *next)) {
|
|
m(*itr, *next);
|
|
std::iter_swap(itr, next);
|
|
modified = true;
|
|
}
|
|
}
|
|
} while (modified);
|
|
}
|
|
}
|
|
}
|
|
}
|