MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / algorithm_stable_sort

Function algorithm_stable_sort

algorithm/algorithm.c:214–233  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

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/* ================================================================== */

Callers

nothing calls this directly

Calls 1

mergeSortInternalFunction · 0.85

Tested by

no test coverage detected