djbsort(3)
π djbsort(3) β bestie's guide to sorting ur numbers π
okay so listen. this is djbsort(3), a lil library that sorts arrays of integers and floating-point numbers. no cap, it's the moment. π¦
β¨ NAME β¨
djbsort β sorts an array of integers or floating-point numbers π
πΈ SYNOPSIS πΈ
so when ur using djbsort, first things first:
#include <djbsort.h>
and link it with -ldjbsort. periodt. π
now the sorting part. pick ur type, bestie:
int32_t x[n];
...
djbsort_int32(x,n);
djbsort_int32down(x,n);
uint32_t x[n];
...
djbsort_uint32(x,n);
djbsort_uint32down(x,n);
float x[n];
...
djbsort_float32(x,n);
djbsort_float32down(x,n);
int64_t x[n];
...
djbsort_int64(x,n);
djbsort_int64down(x,n);
uint64_t x[n];
...
djbsort_uint64(x,n);
djbsort_uint64down(x,n);
double x[n];
...
djbsort_float64(x,n);
djbsort_float64down(x,n);
π DESCRIPTION π
so djbsort takes an array x of n numeric elements and sorts it, dropping the sorted result right back into that same array. iconic behavior honestly. β¨
the down functions? they sort in reverse order. lowkey the rebel siblings of the family. π
here's the thing tho β the djbsort functions guarantee success. like, no failing, no vibes-based uncertainty. they sort in place, and they do not allocate memory beyond a small amount of stack space. so chill, ur heap is safe. π«Ά
each function just returns without doing anything if n is 1 or 0. and the n type is a signed long long, so it can also be negative β in which case the function also returns without doing anything. why, u ask? (for any sorting library, a caller might sort all elements of a size-n array past the mth by sorting x+m,n-m; but what happens if n happens to be smaller than m and the caller does not check for this? returning immediately on negative inputs is much more likely to be the desired behavior than crashing.) so yeah, that's the lore. π
β οΈ but beware, bestie β this still does not deal with the problem of caller arithmetic overflowing if, e.g.,mandnaresize_ton a 32-bit machine. so watch ur math, fr fr. π
each function guarantees that the outputs are exactly the inputs permuted into non-decreasing order β or non-increasing order for the down functions. no sneaky edits, no mystery elements. some sorting libraries do NOT provide this guarantee for floating-point arrays: they might replace some types of NaNs with other types of NaNs, or might even crash for floating-point inputs containing NaNs. π not here tho. we don't do that.
now, other libraries have sorting functions too, and they're typically slower than djbsort, but they get the flexibility of sorting other data types. for the record:
- heapsort (in
libc) β sorts arbitrary types in place using a comparison callback - mergesort (in
libbsd) β sorts arbitrary types using a comparison callback; typically faster than heapsort but does not sort in place - qsort (in
libc) β sorts arbitrary types in place using a comparison callback; typically faster than mergesort but much slower for some inputs - radixsort (in
libbsd) β sorts pointers to strings in place std::sort(in the C++ standard library) β sorts arbitrary comparable types using templates
so like. if u need ~variety~ they got u. if u need speed and exact guarantees, u know where to be. π
π SEE ALSO π
okay that's the whole page bestie, we ate and left no crumbs ππ this was djbsort(3) β that's the title and the manual name, slay β and the page signs off as djbsort(3) at the bottom, which is also where the source/version and date live. mwah, go sort something pretty. π§β¨
π¦ where this page comes from
- epel 10: libdjbsort-devel 20260621-1.el10_3 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- epel 9: libdjbsort-devel 20260621-1.el9 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 43: libdjbsort-devel 20260621-1.fc43 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 43: libdjbsort-devel 20260621-1.fc43 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 44: libdjbsort-devel 20260621-1.fc44 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 44: libdjbsort-devel 20260621-1.fc44 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms