* @brief Finds the last occurrence of a subsequence in a range. * * This function searches for the last occurrence of the sequence `[base2, base2 + num2 * size2)` in the range * `[base1, base1 + num1 * size1)`. * * @param base1 Pointer to the start of the main array. * @param num1 Number of elements in the main array. * @param size1 Size of each element in the main array in bytes. * @param
| 381 | if (comp(cur, cur - sz) < 0) { |
| 382 | alg_copy_elem(tmp, cur, sz); |
| 383 | char *hole = cur; |
| 384 | do { |
| 385 | alg_copy_elem(hole, hole - sz, sz); |
| 386 | hole -= sz; |
| 387 | } while ((!guarded || hole != a) && comp(tmp, hole - sz) < 0); |
| 388 | alg_copy_elem(hole, tmp, sz); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /* Insertion sort that gives up after PDQ_PARTIAL_LIMIT element moves; true |
| 394 | * when it sorted the range. */ |
| 395 | ALG_INLINE int pdq_partial_insertion(char *a, size_t n, size_t sz, AlgorithmCompareFunc comp, char *tmp) { |
| 396 | size_t moved = 0; |
| 397 | for (size_t i = 1; i < n; ++i) { |
| 398 | char *cur = a + i * sz; |
| 399 | if (comp(cur, cur - sz) < 0) { |
| 400 | alg_copy_elem(tmp, cur, sz); |
| 401 | char *hole = cur; |
| 402 | do { |
| 403 | alg_copy_elem(hole, hole - sz, sz); |
| 404 | hole -= sz; |
| 405 | } while (hole != a && comp(tmp, hole - sz) < 0); |
| 406 | alg_copy_elem(hole, tmp, sz); |
| 407 | moved += (size_t)(cur - hole) / sz; |
| 408 | if (moved > PDQ_PARTIAL_LIMIT) { |
| 409 | return 0; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | return 1; |
| 414 | } |
| 415 | |
| 416 | /* Sift a[i] down the max-heap a[0, end). With `tmp` the element travels |
| 417 | * through it; without (no memory for a large element) it is swapped down. */ |
| 418 | static void pdq_sift_down(char *a, size_t i, size_t end, size_t sz, AlgorithmCompareFunc comp, char *tmp) { |
| 419 | if (tmp) { |
| 420 | alg_copy_elem(tmp, a + i * sz, sz); |
| 421 | } |
| 422 | for (;;) { |
| 423 | size_t c = 2 * i + 1; |
| 424 | if (c >= end) { |
| 425 | break; |
nothing calls this directly
no outgoing calls
no test coverage detected