* @brief Sorts an array using a stable merge sort algorithm. * * @param base Pointer to the start of the array. * @param num Number of elements in the array. * @param size Size of each element in bytes. * @param comp Comparison function used to order the elements. */
| 212 | uint32_t r = rng(); |
| 213 | /* The rejected tail is the top (2^32 mod b) < b values. A draw below |
| 214 | 2^32 - b can never be in it, so the exact limit (a second |
| 215 | division) is only computed for the rare draw in the top b values. */ |
| 216 | if (r > UINT32_C(0xFFFFFFFF) - b) { |
| 217 | uint32_t tail = (uint32_t)((UINT64_C(1) << 32) % b); /* 2^32 mod b */ |
| 218 | while (tail != 0 && r > UINT32_C(0xFFFFFFFF) - tail) { |
| 219 | r = rng(); |
| 220 | } |
| 221 | } |
| 222 | return (size_t)(r % b); /* 32-bit division */ |
| 223 | } |
| 224 | uint64_t b = (uint64_t)bound; |
| 225 | uint64_t rem = (UINT64_MAX % b + 1) % b; /* 2^64 mod b */ |
| 226 | uint64_t r; |
| 227 | do { |
| 228 | r = ((uint64_t)rng() << 32) | (uint64_t)rng(); |
| 229 | } while (rem != 0 && r > UINT64_MAX - rem); |
| 230 | return (size_t)(r % b); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /* ================================================================== */ |
| 235 | /* Filtering core (filter, copy_if, remove_copy_if) */ |
| 236 | /* ================================================================== */ |
nothing calls this directly
no test coverage detected