| 268 | |
| 269 | template <typename Comparator> |
| 270 | bool isAlreadySortedImpl(size_t rows, Comparator compare) |
| 271 | { |
| 272 | /** If the rows are not too few, then let's make a quick attempt to verify that the block is not sorted. |
| 273 | * Constants - at random. |
| 274 | */ |
| 275 | static constexpr size_t num_rows_to_try = 10; |
| 276 | if (rows > num_rows_to_try * 5) |
| 277 | { |
| 278 | for (size_t i = 1; i < num_rows_to_try; ++i) |
| 279 | { |
| 280 | size_t prev_position = rows * (i - 1) / num_rows_to_try; |
| 281 | size_t curr_position = rows * i / num_rows_to_try; |
| 282 | |
| 283 | if (compare(curr_position, prev_position)) |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | for (size_t i = 1; i < rows; ++i) |
| 289 | if (compare(i, i - 1)) |
| 290 | return false; |
| 291 | |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | #ifndef NDEBUG |
| 296 | template <typename Comparator> |