From bb3e3d5057cda81a0a2bdacca8a9fd8ca15ae16b Mon Sep 17 00:00:00 2001 From: wes Date: Wed, 5 Jul 2017 12:18:03 -0400 Subject: [PATCH] first commit --- .bfilter.c.swp | Bin 0 -> 12288 bytes .bfilter.h.swp | Bin 0 -> 12288 bytes .gitignore | 1 + Makefile | 5 ++++ bfilter.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ bfilter.h | 14 +++++++++ error.h | 1 + libfnv | 1 + printbits.py | 21 ++++++++++++++ roadnottaken | 23 +++++++++++++++ 10 files changed, 143 insertions(+) create mode 100644 .bfilter.c.swp create mode 100644 .bfilter.h.swp create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 bfilter.c create mode 100644 bfilter.h create mode 100644 error.h create mode 160000 libfnv create mode 100755 printbits.py create mode 100644 roadnottaken diff --git a/.bfilter.c.swp b/.bfilter.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..cefa3fc2c552c7bb628c22d428b3486bb1b92e25 GIT binary patch literal 12288 zcmeI2O=w(I6vuB|h(%*dU06i%IHm2InS4yrDuqm@lv1P%D>R88w57axb0>4j%YEU! zJ5H-cY1iGmlWw}OEmY`21WVm1v?4D305>iaQCw9-6#wVWo5@TPjL=o^4E%WSo_oIT z|K2+!B=yQGCtjk%6BUKeE~QrgJoEZ*-`7WKPb$^X8C$pfWG+mXw)9f!9VDErH%;tx z+Ivn!{~=IZL;+FY!4zn_=J?^!g@e;m{;KaSJV#ILUU;ya5-kdd0-}H@APR^AqJStM z3Wx&RN&&YrqTWTv59M8-%AX_ap7~H7qJStM3Wx%tfG8jehytR3C?E=m0-}H@uniRm z8%kZ@q14Vt(LDbC-~0Xl*PTjz13m+{z!h*AoCg}rgCn2@4uGe?!{D#SmHGqx41NMX zf*-(F;A3zDTmlz?1+RjW;3${{0eA%bGKzTcHMk4zfZN~`@DX?)B)|d;}7l*K`}6329jr5Cud5Q9u+B1w?`WlLD)XDAlf=S~~vPiTQJL3&)NfpPQS3 zc_lU0)s4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ev/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.