Sort a temporary ordering and then replace m_index
when done: success.
template <typename Compare>
void stableSort(Compare compare)
{
auto order = m_index;
std::stable_sort(
order.begin(),
order.end(),
[this, &compare](const PointId a, const PointId b)
{
return compare(PointRef(*this, a), PointRef(*this, b));
});
m_index = order;
}
Output:
$ ./bin/pdal_filters_sort_test --gtest_filter=SortFilterTest.seventeen
Note: Google Test filter = SortFilterTest.seventeen
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from SortFilterTest
[ RUN ] SortFilterTest.seventeen
Before:
0: 1.44555
1: 15.1574
2: 3.22473
3: 6.76614
4: 12.6397
5: 9.52663
6: 13.7626
7: 8.69911
8: 16.9164
9: 16.4324
10: 7.24286
11: 11.101
12: 16.3461
13: 14.5858
14: 4.99844
15: 7.04896
16: 8.75318
After:
0: 1.44555
1: 3.22473
2: 4.99844
3: 6.76614
4: 7.04896
5: 7.24286
6: 8.69911
7: 8.75318
8: 9.52663
9: 11.101
10: 12.6397
11: 13.7626
12: 14.5858
13: 15.1574
14: 16.3461
15: 16.4324
16: 16.9164
[ OK ] SortFilterTest.seventeen (0 ms)
[----------] 1 test from SortFilterTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.