commit bb3e3d5057cda81a0a2bdacca8a9fd8ca15ae16b Author: wes Date: Wed Jul 5 12:18:03 2017 -0400 first commit diff --git a/.bfilter.c.swp b/.bfilter.c.swp new file mode 100644 index 0000000..cefa3fc Binary files /dev/null and b/.bfilter.c.swp differ diff --git a/.bfilter.h.swp b/.bfilter.h.swp new file mode 100644 index 0000000..d7d59f7 Binary files /dev/null and b/.bfilter.h.swp differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3385a07 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +default: bfilter.c bfilter.h + $(CC) -g -DTOK_LIB -Wall -Wextra -std=gnu99 -Wpointer-arith -Wmissing-prototypes -lmaa -lm -L. -O3 ./bfilter.c -o test -Wl,-rpath,/home/wes/bfilter; + +unsafe: bfilter.c bfilter.h + $(CC) -DNDEBUG -DTOK_LIB -Wall -std=gnu99 -Wextra -Wpointer-arith -Wmissing-prototypes -lmaa -lm -L. -O3 ./bfilter.c -o bfilter -Wl,-rpath,/home/wes/bfilter; diff --git a/bfilter.c b/bfilter.c new file mode 100644 index 0000000..85f9661 --- /dev/null +++ b/bfilter.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include +#include "error.h" +#include "maa.h" +#include "bfilter.h" + +int countbits(int n) { + int c = 0; + while (n >>= 1) { + c++; + } + return c+1; +} + +int +printbits(int n) { + int c = countbits(n); + int i = c; + int *bits = malloc((sizeof (int)) * c); + + while (n >= 2) { + bits[i-1] = n & 1; + i--; + n >>= 1; + } + bits[i-1] = n & 1; + for (int i = 0; i < c; i++) { + printf("%d", bits[i]); + } + printf("\n"); + free(bits); + return 0; +} + +int* +new_bitarray(int size) { + int *barray = malloc((sizeof (int)) * size); + int i; + for(i = 0; i < size; i++) { + barray[i] = 0; + } + return barray; +} + +int +setbit(int* arr, int k) { + /* The position in the array of the int we're looking at */ + int i = k/32; + + /* The position of the bit in the int itself */ + int pos = k % 32; + + unsigned int flag = 1; + + /* Shift the flag to the position of the bit we want to set */ + flag = flag << pos; + + arr[i] = arr[i] | flag; + + return 0; +} + +int +main (void) { + int *test = new_bitarray(5); + setbit(test, 6); + setbit(test, 4); + setbit(test, 2); + printbits(test[0]); + return EXIT_SUCCESS; +} + diff --git a/bfilter.h b/bfilter.h new file mode 100644 index 0000000..a244beb --- /dev/null +++ b/bfilter.h @@ -0,0 +1,14 @@ +typedef + struct { + size_t number; + int *arr; + } + bit_array_t; + +int countbits(int); + +int printbits(int); + +int *new_bitarray(int); + +int setbit(int*, int); diff --git a/error.h b/error.h new file mode 100644 index 0000000..24bfcc3 --- /dev/null +++ b/error.h @@ -0,0 +1 @@ +#define CHECK(ptr) if ((ptr) == NULL) { printf("Failed to allocate memory\n"); exit(EXIT_FAILURE); } diff --git a/libfnv b/libfnv new file mode 160000 index 0000000..c8d4fbe --- /dev/null +++ b/libfnv @@ -0,0 +1 @@ +Subproject commit c8d4fbe1138b93f6413557f24b346111f67081f5 diff --git a/printbits.py b/printbits.py new file mode 100755 index 0000000..430c499 --- /dev/null +++ b/printbits.py @@ -0,0 +1,21 @@ +#! /usr/bin/env python2 + +def printbits(n): + if n < 2: + return str(n & 1) + rest = n >> 1 + d = n & 1 + return printbits(rest) + str(d) + +def modifybit(n): + return 1 << n + +test = 0b10010101111 + +print bin(test) +print bin(test | modifybit(3)) + +# bin((1 << 6) - 2) + +#print bin(1292002343) +#print printbits(1292002343) diff --git a/roadnottaken b/roadnottaken new file mode 100644 index 0000000..6558308 --- /dev/null +++ b/roadnottaken @@ -0,0 +1,23 @@ +Two roads diverged in a yellow wood, +And sorry I could not travel both +And be one traveler, long I stood +And looked down one as far as I could +To where it bent in the undergrowth; + +Then took the other, as just as fair, +And having perhaps the better claim, +Because it was grassy and wanted wear; +Though as for that the passing there +Had worn them really about the same, + +And both that morning equally lay +In leaves no step had trodden black. +Oh, I kept the first for another day! +Yet knowing how way leads on to way, +I doubted if I should ever come back. + +I shall be telling this with a sigh +Somewhere ages and ages hence: +Two roads diverged in a wood, and I— +I took the one less traveled by, +And that has made all the difference.