MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / isAlreadySortedImpl

Function isAlreadySortedImpl

src/Interpreters/sortBlock.cpp:270–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269template <typename Comparator>
270bool 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
296template <typename Comparator>

Callers 1

isAlreadySortedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected