Skip to content

Commit

Permalink
eliminating Warnings (#64)
Browse files Browse the repository at this point in the history
* first cut at reducing warnings

binaryfusefilter.h only

issues addressed

1. changed some return value and parameter types of (static) functions
-- PLEASE CHECK THIS IN REVIEW

2. sprinkled 'U' into bitwise operations to silence warnings

3. casting to avoid "standard integer promotion rules" which resulted
in signedness warnings

4. explicitly reducing results to the target type rather than letting
it happen implicitly

tests still passing

* first cut at reducing warnings

binaryfusefilter.h only

issues addressed

1. changed some return value and parameter types of (static) functions
-- PLEASE CHECK THIS IN REVIEW

2. sprinkled 'U' into bitwise operations to silence warnings

3. casting to avoid "standard integer promotion rules" which resulted
in signedness warnings

4. explicitly reducing results to the target type rather than letting
it happen implicitly

5. when and `if` statements ends in break or return, then a following
`else if` can be just a new `if`

tests still passing

* starting work on xofilter.h

* binclude/binaryfusefilter.h apparently clean for first time

* formatting

* first cut on xofilter.h

mostly casting size_t down to uint32_t - maybe some internal struct
types should have been size_t?

also some integer promotion casts

* round2 on xorfilter.h

mostly casting blocklengt to uint32_t to fit into keyindex.index

should keyindex.index be a size_t?

* bench.c and unit.c

very repetitive casting of mainly sizes and doubles.

* all silent now on a clean compile

with -Wconversion and -Wsign-conversion

so putting these in the Makefile, so during "private" development with
the Makefile new warnings will be noticed straight away

but not in CMakeLists.txt, because as this is a header-only INTERFACE
library, it would force these warning levels on the users.

* another sweep from including c++ project

turned up these additional 'U' tweaks

* mistaken cast which broke test

* factoring out the report functionality

all sections were indentical except for the call to *contain()
and *size_in_bytes

some void* and function pointer juggling allowed to make this generic

report code reduced by 2/3rds

* iron out slight inconsistencies between tests

* abstracting away the rest of the test logic

for all but the special "failure rate test"

the large function dispatch table is a litle annoying, but can be
removed as well...TBC

tests all pass

* fixing a memory leak caught by sanitizer

just a missing free()
  • Loading branch information
oschonrock authored Dec 13, 2024
1 parent 5906203 commit 890b31d
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 526 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
all: unit bench

unit : tests/unit.c include/xorfilter.h include/binaryfusefilter.h
cc -std=c99 -O3 -o unit tests/unit.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual
cc -std=c99 -O3 -o unit tests/unit.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual -Wconversion -Wsign-conversion


ab : tests/a.c tests/b.c
cc -std=c99 -o c tests/a.c tests/b.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual
cc -std=c99 -o c tests/a.c tests/b.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual -Wconversion -Wsign-conversion

bench : benchmarks/bench.c include/xorfilter.h include/binaryfusefilter.h
cc -std=c99 -O3 -o bench benchmarks/bench.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual
cc -std=c99 -O3 -o bench benchmarks/bench.c -lm -Iinclude -Wall -Wextra -Wshadow -Wcast-qual -Wconversion -Wsign-conversion

test: unit ab
./unit
Expand Down
36 changes: 18 additions & 18 deletions benchmarks/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ bool testxor8(size_t size) {

xor8_t filter;

xor8_allocate(size, &filter);
xor8_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = xor8_populate(big_set, size, &filter); // warm the cache
bool constructed = xor8_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
xor8_populate(big_set, size, &filter);
xor8_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand All @@ -37,19 +37,19 @@ bool testbufferedxor8(size_t size) {
printf("size = %zu \n", size);

xor8_t filter;
xor8_allocate(size, &filter);
xor8_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = xor8_buffered_populate(big_set, size, &filter); // warm the cache
bool constructed = xor8_buffered_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
xor8_buffered_populate(big_set, size, &filter);
xor8_buffered_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand All @@ -65,19 +65,19 @@ bool testxor16(size_t size) {
printf("size = %zu \n", size);

xor16_t filter;
xor16_allocate(size, &filter);
xor16_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = xor16_populate(big_set, size, &filter); // warm the cache
bool constructed = xor16_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
xor16_populate(big_set, size, &filter);
xor16_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand All @@ -93,19 +93,19 @@ bool testbufferedxor16(size_t size) {
printf("size = %zu \n", size);

xor16_t filter;
xor16_allocate(size, &filter);
xor16_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = xor16_buffered_populate(big_set, size, &filter); // warm the cache
bool constructed = xor16_buffered_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
xor16_buffered_populate(big_set, size, &filter);
xor16_buffered_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand All @@ -122,19 +122,19 @@ bool testbinaryfuse8(size_t size) {

binary_fuse8_t filter;

binary_fuse8_allocate(size, &filter);
binary_fuse8_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = binary_fuse8_populate(big_set, size, &filter); // warm the cache
bool constructed = binary_fuse8_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
binary_fuse8_populate(big_set, size, &filter);
binary_fuse8_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand All @@ -151,19 +151,19 @@ bool testbinaryfuse16(size_t size) {

binary_fuse16_t filter;

binary_fuse16_allocate(size, &filter);
binary_fuse16_allocate((uint32_t)size, &filter);
// we need some set of values
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
for (size_t i = 0; i < size; i++) {
big_set[i] = i; // we use contiguous values
}
// we construct the filter
bool constructed = binary_fuse16_populate(big_set, size, &filter); // warm the cache
bool constructed = binary_fuse16_populate(big_set, (uint32_t)size, &filter); // warm the cache
if(!constructed) { return false; }
for (size_t times = 0; times < 5; times++) {
clock_t t;
t = clock();
binary_fuse16_populate(big_set, size, &filter);
binary_fuse16_populate(big_set, (uint32_t)size, &filter);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
printf("It took %f seconds to build an index over %zu values. \n",
Expand Down
Loading

0 comments on commit 890b31d

Please sign in to comment.