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

Function algorithm_sort

algorithm/algorithm.c:244–274  ·  view source on GitHub ↗

* @brief Sorts an array using a non-stable quicksort 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

242#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))
243 unsigned long i;
244 _BitScanForward64(&i, x);
245 return (unsigned)i;
246#elif defined(_MSC_VER)
247 unsigned long i;
248 if ((uint32_t)x) {
249 _BitScanForward(&i, (unsigned long)(uint32_t)x);
250 return (unsigned)i;
251 }
252 _BitScanForward(&i, (unsigned long)(uint32_t)(x >> 32));
253 return (unsigned)i + 32;
254#else
255 unsigned n = 0;
256 while (!(x & 1u)) {
257 x >>= 1;
258 n++;
259 }
260 return n;
261#endif
262}
263
264/* Python truthiness for raw elements: true unless every byte is zero
265 * (0, 0.0, NULL, '\0', an all-zero struct). */
266ALG_INLINE int alg_is_truthy(const char *p, size_t sz) {
267 switch (sz) {
268 case 1: return p[0] != 0;
269 case 2: { uint16_t v; memcpy(&v, p, 2); return v != 0; }
270 case 4: { uint32_t v; memcpy(&v, p, 4); return v != 0; }
271 case 8: { uint64_t v; memcpy(&v, p, 8); return v != 0; }
272 default:
273 for (size_t i = 0; i < sz; i++) {
274 if (p[i]) {
275 return 1;
276 }
277 }

Callers 1

queue_sortFunction · 0.85

Calls 1

srt_introsortFunction · 0.85

Tested by

no test coverage detected