Created
June 7, 2018 02:13
-
-
Save gene-ressler/09a9b5204f93f599e8602311f9f6869b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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