Skip to content

Commit 890b31d

Browse files
authored
eliminating Warnings (#64)
* 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()
1 parent 5906203 commit 890b31d

File tree

5 files changed

+374
-526
lines changed

5 files changed

+374
-526
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
all: unit bench
22

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

66

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

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

1313
test: unit ab
1414
./unit

benchmarks/bench.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ bool testxor8(size_t size) {
99

1010
xor8_t filter;
1111

12-
xor8_allocate(size, &filter);
12+
xor8_allocate((uint32_t)size, &filter);
1313
// we need some set of values
1414
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
1515
for (size_t i = 0; i < size; i++) {
1616
big_set[i] = i; // we use contiguous values
1717
}
1818
// we construct the filter
19-
bool constructed = xor8_populate(big_set, size, &filter); // warm the cache
19+
bool constructed = xor8_populate(big_set, (uint32_t)size, &filter); // warm the cache
2020
if(!constructed) { return false; }
2121
for (size_t times = 0; times < 5; times++) {
2222
clock_t t;
2323
t = clock();
24-
xor8_populate(big_set, size, &filter);
24+
xor8_populate(big_set, (uint32_t)size, &filter);
2525
t = clock() - t;
2626
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
2727
printf("It took %f seconds to build an index over %zu values. \n",
@@ -37,19 +37,19 @@ bool testbufferedxor8(size_t size) {
3737
printf("size = %zu \n", size);
3838

3939
xor8_t filter;
40-
xor8_allocate(size, &filter);
40+
xor8_allocate((uint32_t)size, &filter);
4141
// we need some set of values
4242
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
4343
for (size_t i = 0; i < size; i++) {
4444
big_set[i] = i; // we use contiguous values
4545
}
4646
// we construct the filter
47-
bool constructed = xor8_buffered_populate(big_set, size, &filter); // warm the cache
47+
bool constructed = xor8_buffered_populate(big_set, (uint32_t)size, &filter); // warm the cache
4848
if(!constructed) { return false; }
4949
for (size_t times = 0; times < 5; times++) {
5050
clock_t t;
5151
t = clock();
52-
xor8_buffered_populate(big_set, size, &filter);
52+
xor8_buffered_populate(big_set, (uint32_t)size, &filter);
5353
t = clock() - t;
5454
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
5555
printf("It took %f seconds to build an index over %zu values. \n",
@@ -65,19 +65,19 @@ bool testxor16(size_t size) {
6565
printf("size = %zu \n", size);
6666

6767
xor16_t filter;
68-
xor16_allocate(size, &filter);
68+
xor16_allocate((uint32_t)size, &filter);
6969
// we need some set of values
7070
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
7171
for (size_t i = 0; i < size; i++) {
7272
big_set[i] = i; // we use contiguous values
7373
}
7474
// we construct the filter
75-
bool constructed = xor16_populate(big_set, size, &filter); // warm the cache
75+
bool constructed = xor16_populate(big_set, (uint32_t)size, &filter); // warm the cache
7676
if(!constructed) { return false; }
7777
for (size_t times = 0; times < 5; times++) {
7878
clock_t t;
7979
t = clock();
80-
xor16_populate(big_set, size, &filter);
80+
xor16_populate(big_set, (uint32_t)size, &filter);
8181
t = clock() - t;
8282
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
8383
printf("It took %f seconds to build an index over %zu values. \n",
@@ -93,19 +93,19 @@ bool testbufferedxor16(size_t size) {
9393
printf("size = %zu \n", size);
9494

9595
xor16_t filter;
96-
xor16_allocate(size, &filter);
96+
xor16_allocate((uint32_t)size, &filter);
9797
// we need some set of values
9898
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
9999
for (size_t i = 0; i < size; i++) {
100100
big_set[i] = i; // we use contiguous values
101101
}
102102
// we construct the filter
103-
bool constructed = xor16_buffered_populate(big_set, size, &filter); // warm the cache
103+
bool constructed = xor16_buffered_populate(big_set, (uint32_t)size, &filter); // warm the cache
104104
if(!constructed) { return false; }
105105
for (size_t times = 0; times < 5; times++) {
106106
clock_t t;
107107
t = clock();
108-
xor16_buffered_populate(big_set, size, &filter);
108+
xor16_buffered_populate(big_set, (uint32_t)size, &filter);
109109
t = clock() - t;
110110
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
111111
printf("It took %f seconds to build an index over %zu values. \n",
@@ -122,19 +122,19 @@ bool testbinaryfuse8(size_t size) {
122122

123123
binary_fuse8_t filter;
124124

125-
binary_fuse8_allocate(size, &filter);
125+
binary_fuse8_allocate((uint32_t)size, &filter);
126126
// we need some set of values
127127
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
128128
for (size_t i = 0; i < size; i++) {
129129
big_set[i] = i; // we use contiguous values
130130
}
131131
// we construct the filter
132-
bool constructed = binary_fuse8_populate(big_set, size, &filter); // warm the cache
132+
bool constructed = binary_fuse8_populate(big_set, (uint32_t)size, &filter); // warm the cache
133133
if(!constructed) { return false; }
134134
for (size_t times = 0; times < 5; times++) {
135135
clock_t t;
136136
t = clock();
137-
binary_fuse8_populate(big_set, size, &filter);
137+
binary_fuse8_populate(big_set, (uint32_t)size, &filter);
138138
t = clock() - t;
139139
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
140140
printf("It took %f seconds to build an index over %zu values. \n",
@@ -151,19 +151,19 @@ bool testbinaryfuse16(size_t size) {
151151

152152
binary_fuse16_t filter;
153153

154-
binary_fuse16_allocate(size, &filter);
154+
binary_fuse16_allocate((uint32_t)size, &filter);
155155
// we need some set of values
156156
uint64_t *big_set = (uint64_t *)malloc(sizeof(uint64_t) * size);
157157
for (size_t i = 0; i < size; i++) {
158158
big_set[i] = i; // we use contiguous values
159159
}
160160
// we construct the filter
161-
bool constructed = binary_fuse16_populate(big_set, size, &filter); // warm the cache
161+
bool constructed = binary_fuse16_populate(big_set, (uint32_t)size, &filter); // warm the cache
162162
if(!constructed) { return false; }
163163
for (size_t times = 0; times < 5; times++) {
164164
clock_t t;
165165
t = clock();
166-
binary_fuse16_populate(big_set, size, &filter);
166+
binary_fuse16_populate(big_set, (uint32_t)size, &filter);
167167
t = clock() - t;
168168
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
169169
printf("It took %f seconds to build an index over %zu values. \n",

0 commit comments

Comments
 (0)