Skip to content

Instantly share code, notes, and snippets.

@gene-ressler
Created June 7, 2018 02:13
Show Gist options
  • Save gene-ressler/09a9b5204f93f599e8602311f9f6869b to your computer and use it in GitHub Desktop.
Save gene-ressler/09a9b5204f93f599e8602311f9f6869b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
// An radix 2 sort with nice properties.
void sort(unsigned *a, int len)
{
unsigned *s = a, *d = malloc(len * sizeof *d), *t, bit, is, id0, id1;
for (bit = 1; bit; bit <<= 1, t = s, s = d, d = t)
for (is = id0 = 0, id1 = len; is < len; ++is)
d[((s[is] >> 1) ^ s[is]) & bit ? --id1 : id0++] = s[is];
free(d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment