Skip to content

Instantly share code, notes, and snippets.

@reterVision
Created January 10, 2014 08:42
Show Gist options
  • Save reterVision/a81fc239e65445de59fe to your computer and use it in GitHub Desktop.
Save reterVision/a81fc239e65445de59fe to your computer and use it in GitHub Desktop.
Bitsort
#include <stdio.h>
#include <string.h>
#define BITSTEPWORD 32
#define SHIFT 5
#define MASK 0x1F
#define NUM 10000000
int array[1 + NUM / BITSTEPWORD];
void clear()
{
memset(array, 0, sizeof(array));
}
void set(int i)
{
array[i >> SHIFT] |= (1 << (i & MASK));
}
void clr(int i)
{
array[i >> SHIFT] &= ~(1 << (i & MASK));
}
int test(int i)
{
return array[i >> SHIFT] & (1 << (i & MASK));
}
int main(int argc, char* argv[])
{
int i;
clear();
printf("Before set anything:\n");
for (i=0; i<200; i++)
{
printf("%d ", array[i]);
}
printf("\n\n");
for (i=0; i<100; i++)
{
printf("%d ", i*2);
set(i*2);
}
printf("\n\n");
for (i=0; i<200; i++)
{
if (test(i))
printf("%d ", i);
}
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment