5 changed files with 71 additions and 6 deletions
@ -1,5 +1,6 @@ |
|||||
default: bfilter.c bfilter.h |
default: bfilter.c bfilter.h |
||||
$(CC) -g -DTOK_LIB -Wall -Wextra -std=gnu99 -Wpointer-arith -Wmissing-prototypes -lm -L. -O3 ./bfilter.c -o test --static `pkg-config --libs --cflags libfnv` -Wl,-rpath,/home/wes/bfilter; |
$(CC) -g -Wall -Wextra -std=gnu99 -Wpointer-arith -Wmissing-prototypes -lm -L. -O3 ./bfilter.c -o test --static `pkg-config --libs --cflags libfnv` -Wl,-rpath,/home/wes/bfilter; |
||||
|
|
||||
unsafe: bfilter.c bfilter.h |
lib: bfilter.c bfilter.h |
||||
$(CC) -DNDEBUG -DTOK_LIB -Wall -std=gnu99 -Wextra -Wpointer-arith -Wmissing-prototypes -lm -L. -O3 ./bfilter.c -o bfilter -Wl,-rpath,/home/wes/bfilter; |
$(CC) -g -DLIB -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -lm -L. -O3 ./bfilter.c --static `pkg-config --libs --cflags libfnv` -Wl,-rpath,/home/wes/bfilter; |
||||
|
$(CC) -shared -o bfilter.so bfilter.o; |
||||
|
Binary file not shown.
@ -0,0 +1,63 @@ |
|||||
|
#! /usr/bin/env python3 |
||||
|
|
||||
|
from cffi import FFI |
||||
|
from sys import stdout |
||||
|
|
||||
|
ffi = FFI() |
||||
|
|
||||
|
lib = ffi.dlopen("./bfilter.so") |
||||
|
|
||||
|
ffi.cdef(""" |
||||
|
typedef |
||||
|
struct { |
||||
|
size_t num_elems; |
||||
|
size_t num_ints; |
||||
|
uint32_t *arr; |
||||
|
} |
||||
|
bit_array_t; |
||||
|
|
||||
|
typedef |
||||
|
struct { |
||||
|
uint32_t hash_1; |
||||
|
uint32_t hash_2; |
||||
|
} |
||||
|
fnv_hashes_t; |
||||
|
|
||||
|
typedef uint32_t* hashes_t; |
||||
|
|
||||
|
int printbits(uint32_t, size_t); |
||||
|
|
||||
|
int print_barray(bit_array_t*); |
||||
|
|
||||
|
bit_array_t* empty_bfilter(int); |
||||
|
|
||||
|
fnv_hashes_t hash_fnv(const char*); |
||||
|
|
||||
|
uint32_t kth_hash(fnv_hashes_t, uint32_t, size_t); |
||||
|
|
||||
|
hashes_t hash(const char *, uint32_t, size_t); |
||||
|
|
||||
|
int setbit(bit_array_t*, int); |
||||
|
int unsetbit(bit_array_t*, int); |
||||
|
|
||||
|
int bfilter_set(bit_array_t *, const char*, int); |
||||
|
int bfilter_get(bit_array_t *, const char*, int); |
||||
|
|
||||
|
int getbit(bit_array_t *, int); |
||||
|
""") |
||||
|
|
||||
|
bfilter = lib.empty_bfilter(190) |
||||
|
|
||||
|
k = 10 |
||||
|
|
||||
|
with open("./roadnottaken") as rnt: |
||||
|
words = rnt.read().split(" ") |
||||
|
for word in words: |
||||
|
lib.bfilter_set(bfilter, word.encode("UTF-8"), k) |
||||
|
|
||||
|
for word in words: |
||||
|
print(lib.bfilter_get(bfilter, word.encode("UTF-8"), k)) |
||||
|
|
||||
|
print(lib.bfilter_get(bfilter, b"wes", k)) |
||||
|
|
||||
|
# lib.print_barray(bfilter) |
Binary file not shown.
Loading…
Reference in new issue