Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding many explicit casts #528

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/roaring/containers/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ void array_container_offset(const array_container_t *c,
static inline bool array_container_contains_range(const array_container_t *arr,
uint32_t range_start, uint32_t range_end) {
const int32_t range_count = range_end - range_start;
const uint16_t rs_included = range_start;
const uint16_t re_included = range_end - 1;
const uint16_t rs_included = (uint16_t)range_start;
const uint16_t re_included = (uint16_t)(range_end - 1);

// Empty range is always included
if (range_count <= 0) {
Expand Down Expand Up @@ -453,7 +453,7 @@ static inline void array_container_add_range_nvals(array_container_t *array,
&(array->array[array->cardinality - nvals_greater]),
nvals_greater * sizeof(uint16_t));
for (uint32_t i = 0; i <= max - min; i++) {
array->array[nvals_less + i] = min + i;
array->array[nvals_less + i] = (uint16_t)(min + i);
}
array->cardinality = union_cardinality;
}
Expand Down
2 changes: 1 addition & 1 deletion include/roaring/containers/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
return false;
}

for (uint16_t i = start + 1; (i < BITSET_CONTAINER_SIZE_IN_WORDS) && (i < end); ++i){
for (uint16_t i = (uint16_t)(start + 1); (i < BITSET_CONTAINER_SIZE_IN_WORDS) && (i < end); ++i){
Fixed Show fixed Hide fixed

if (bitset->words[i] != UINT64_C(0xFFFFFFFFFFFFFFFF)) return false;
}
Expand Down
42 changes: 21 additions & 21 deletions include/roaring/containers/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ static inline container_t* container_xor(

case CONTAINER_PAIR(RUN,RUN):
*result_type =
run_run_container_xor(const_CAST_run(c1),
(uint8_t)run_run_container_xor(const_CAST_run(c1),
const_CAST_run(c2), &result);
return result;

Expand Down Expand Up @@ -1570,13 +1570,13 @@ static inline container_t* container_xor(

case CONTAINER_PAIR(ARRAY,RUN):
*result_type =
array_run_container_xor(const_CAST_array(c1),
(uint8_t)array_run_container_xor(const_CAST_array(c1),
const_CAST_run(c2), &result);
return result;

case CONTAINER_PAIR(RUN,ARRAY):
*result_type =
array_run_container_xor(const_CAST_array(c2),
(uint8_t)array_run_container_xor(const_CAST_array(c2),
const_CAST_run(c1), &result);
return result;

Expand Down Expand Up @@ -1660,7 +1660,7 @@ static inline container_t *container_lazy_xor(
case CONTAINER_PAIR(RUN,RUN):
// nothing special done yet.
*result_type =
run_run_container_xor(const_CAST_run(c1),
(uint8_t)run_run_container_xor(const_CAST_run(c1),
const_CAST_run(c2), &result);
return result;

Expand Down Expand Up @@ -1756,7 +1756,7 @@ static inline container_t *container_ixor(
return result;

case CONTAINER_PAIR(RUN,RUN):
*result_type = run_run_container_ixor(
*result_type = (uint8_t)run_run_container_ixor(
CAST_run(c1), const_CAST_run(c2), &result);
return result;

Expand Down Expand Up @@ -1791,12 +1791,12 @@ static inline container_t *container_ixor(
return result;

case CONTAINER_PAIR(ARRAY,RUN):
*result_type = array_run_container_ixor(
*result_type = (uint8_t)array_run_container_ixor(
CAST_array(c1), const_CAST_run(c2), &result);
return result;

case CONTAINER_PAIR(RUN,ARRAY):
*result_type = run_array_container_ixor(
*result_type = (uint8_t)run_array_container_ixor(
CAST_run(c1), const_CAST_array(c2), &result);
return result;

Expand Down Expand Up @@ -1887,7 +1887,7 @@ static inline container_t *container_andnot(
return result;
}
*result_type =
run_run_container_andnot(const_CAST_run(c1),
(uint8_t)run_run_container_andnot(const_CAST_run(c1),
const_CAST_run(c2), &result);
return result;

Expand Down Expand Up @@ -1942,7 +1942,7 @@ static inline container_t *container_andnot(
return result;

case CONTAINER_PAIR(RUN,ARRAY):
*result_type = run_array_container_andnot(
*result_type = (uint8_t)run_array_container_andnot(
const_CAST_run(c1), const_CAST_array(c2),
&result);
return result;
Expand Down Expand Up @@ -1988,7 +1988,7 @@ static inline container_t *container_iandnot(
return c1;

case CONTAINER_PAIR(RUN,RUN):
*result_type = run_run_container_iandnot(
*result_type = (uint8_t)run_run_container_iandnot(
CAST_run(c1), const_CAST_run(c2), &result);
return result;

Expand Down Expand Up @@ -2029,7 +2029,7 @@ static inline container_t *container_iandnot(
return c1;

case CONTAINER_PAIR(RUN,ARRAY):
*result_type = run_array_container_iandnot(
*result_type = (uint8_t)run_array_container_iandnot(
CAST_run(c1), const_CAST_array(c2), &result);
return result;

Expand Down Expand Up @@ -2117,7 +2117,7 @@ static inline container_t *container_not(
return result;
case RUN_CONTAINER_TYPE:
*result_type =
run_container_negation(const_CAST_run(c), &result);
(uint8_t)run_container_negation(const_CAST_run(c), &result);
return result;

default:
Expand Down Expand Up @@ -2152,7 +2152,7 @@ static inline container_t *container_not_range(
: ARRAY_CONTAINER_TYPE;
return result;
case RUN_CONTAINER_TYPE:
*result_type = run_container_negation_range(
*result_type = (uint8_t)run_container_negation_range(
const_CAST_run(c), range_start, range_end, &result);
return result;

Expand Down Expand Up @@ -2188,7 +2188,7 @@ static inline container_t *container_inot(
return result;
case RUN_CONTAINER_TYPE:
*result_type =
run_container_negation_inplace(CAST_run(c), &result);
(uint8_t)run_container_negation_inplace(CAST_run(c), &result);
return result;

default:
Expand Down Expand Up @@ -2223,7 +2223,7 @@ static inline container_t *container_inot_range(
: ARRAY_CONTAINER_TYPE;
return result;
case RUN_CONTAINER_TYPE:
*result_type = run_container_negation_range_inplace(
*result_type = (uint8_t)run_container_negation_range_inplace(
CAST_run(c), range_start, range_end, &result);
return result;

Expand Down Expand Up @@ -2388,8 +2388,8 @@ static inline container_t *container_add_range(
case ARRAY_CONTAINER_TYPE: {
array_container_t *array = CAST_array(c);

int32_t nvals_greater = count_greater(array->array, array->cardinality, max);
int32_t nvals_less = count_less(array->array, array->cardinality - nvals_greater, min);
int32_t nvals_greater = count_greater(array->array, array->cardinality, (uint16_t)max);
int32_t nvals_less = count_less(array->array, array->cardinality - nvals_greater, (uint16_t)min);
int32_t union_cardinality = nvals_less + (max - min + 1) + nvals_greater;

if (union_cardinality == INT32_C(0x10000)) {
Expand All @@ -2410,8 +2410,8 @@ static inline container_t *container_add_range(
case RUN_CONTAINER_TYPE: {
run_container_t *run = CAST_run(c);

int32_t nruns_greater = rle16_count_greater(run->runs, run->n_runs, max);
int32_t nruns_less = rle16_count_less(run->runs, run->n_runs - nruns_greater, min);
int32_t nruns_greater = rle16_count_greater(run->runs, run->n_runs, (uint16_t)max);
int32_t nruns_less = rle16_count_less(run->runs, run->n_runs - nruns_greater, (uint16_t)min);

int32_t run_size_bytes = (nruns_less + 1 + nruns_greater) * sizeof(rle16_t);
int32_t bitset_size_bytes = BITSET_CONTAINER_SIZE_IN_WORDS * sizeof(uint64_t);
Expand Down Expand Up @@ -2468,8 +2468,8 @@ static inline container_t *container_remove_range(
case ARRAY_CONTAINER_TYPE: {
array_container_t *array = CAST_array(c);

int32_t nvals_greater = count_greater(array->array, array->cardinality, max);
int32_t nvals_less = count_less(array->array, array->cardinality - nvals_greater, min);
int32_t nvals_greater = count_greater(array->array, array->cardinality, (uint16_t)max);
int32_t nvals_less = count_less(array->array, array->cardinality - nvals_greater, (uint16_t)min);
int32_t result_cardinality = nvals_less + nvals_greater;

if (result_cardinality == 0) {
Expand Down
30 changes: 15 additions & 15 deletions include/roaring/containers/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ inline bool run_container_contains(const run_container_t *run, uint16_t pos) {
static inline bool run_container_contains_range(const run_container_t *run,
uint32_t pos_start, uint32_t pos_end) {
uint32_t count = 0;
int32_t index = interleavedBinarySearch(run->runs, run->n_runs, pos_start);
int32_t index = interleavedBinarySearch(run->runs, run->n_runs, (uint16_t)pos_start);
if (index < 0) {
index = -index - 2;
if ((index == -1) || ((pos_start - run->runs[index].value) > run->runs[index].length)){
Expand Down Expand Up @@ -590,18 +590,18 @@ static inline void run_container_add_range_nruns(run_container_t* run,
int32_t nruns_greater) {
int32_t nruns_common = run->n_runs - nruns_less - nruns_greater;
if (nruns_common == 0) {
makeRoomAtIndex(run, nruns_less);
run->runs[nruns_less].value = min;
run->runs[nruns_less].length = max - min;
makeRoomAtIndex(run, (uint16_t)nruns_less);
run->runs[nruns_less].value = (uint16_t)min;
run->runs[nruns_less].length = (uint16_t)(max - min);
} else {
uint32_t common_min = run->runs[nruns_less].value;
uint32_t common_max = run->runs[nruns_less + nruns_common - 1].value +
run->runs[nruns_less + nruns_common - 1].length;
uint32_t result_min = (common_min < min) ? common_min : min;
uint32_t result_max = (common_max > max) ? common_max : max;

run->runs[nruns_less].value = result_min;
run->runs[nruns_less].length = result_max - result_min;
run->runs[nruns_less].value = (uint16_t)result_min;
run->runs[nruns_less].length = (uint16_t)(result_max - result_min);

memmove(&(run->runs[nruns_less + 1]),
&(run->runs[run->n_runs - nruns_greater]),
Expand Down Expand Up @@ -641,28 +641,28 @@ static inline void run_container_shift_tail(run_container_t* run,
* Remove all elements in range [min, max]
*/
static inline void run_container_remove_range(run_container_t *run, uint32_t min, uint32_t max) {
int32_t first = rle16_find_run(run->runs, run->n_runs, min);
int32_t last = rle16_find_run(run->runs, run->n_runs, max);
int32_t first = rle16_find_run(run->runs, run->n_runs, (uint16_t)min);
int32_t last = rle16_find_run(run->runs, run->n_runs, (uint16_t)max);

if (first >= 0 && min > run->runs[first].value &&
max < ((uint32_t)run->runs[first].value + (uint32_t)run->runs[first].length)) {
// split this run into two adjacent runs

// right subinterval
makeRoomAtIndex(run, first+1);
run->runs[first+1].value = max + 1;
run->runs[first+1].length = (run->runs[first].value + run->runs[first].length) - (max + 1);
makeRoomAtIndex(run, (uint16_t)(first+1));
run->runs[first+1].value = (uint16_t)(max + 1);
run->runs[first+1].length = (uint16_t)((run->runs[first].value + run->runs[first].length) - (max + 1));

// left subinterval
run->runs[first].length = (min - 1) - run->runs[first].value;
run->runs[first].length = (uint16_t)((min - 1) - run->runs[first].value);

return;
}

// update left-most partial run
if (first >= 0) {
if (min > run->runs[first].value) {
run->runs[first].length = (min - 1) - run->runs[first].value;
run->runs[first].length = (uint16_t)((min - 1) - run->runs[first].value);
first++;
}
} else {
Expand All @@ -673,8 +673,8 @@ static inline void run_container_remove_range(run_container_t *run, uint32_t min
if (last >= 0) {
uint16_t run_max = run->runs[last].value + run->runs[last].length;
if (run_max > max) {
run->runs[last].value = max + 1;
run->runs[last].length = run_max - (max + 1);
run->runs[last].value = (uint16_t)(max + 1);
run->runs[last].length = (uint16_t)(run_max - (max + 1));
last--;
}
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/array_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ int32_t intersect_uint16(const uint16_t *A, const size_t lenA,
goto SKIP_FIRST_COMPARE;
}
}
return (int32_t)(out - initout); // NOTREACHED
// return (int32_t)(out - initout); // NOTREACHED
}

int32_t intersect_uint16_cardinality(const uint16_t *A, const size_t lenA,
Expand All @@ -1016,7 +1016,7 @@ int32_t intersect_uint16_cardinality(const uint16_t *A, const size_t lenA,
goto SKIP_FIRST_COMPARE;
}
}
return answer; // NOTREACHED
// return answer; // NOTREACHED
}


Expand Down Expand Up @@ -1071,7 +1071,7 @@ size_t intersection_uint32(const uint32_t *A, const size_t lenA,
goto SKIP_FIRST_COMPARE;
}
}
return (out - initout); // NOTREACHED
// return (out - initout); // NOTREACHED
}

size_t intersection_uint32_card(const uint32_t *A, const size_t lenA,
Expand All @@ -1096,7 +1096,7 @@ size_t intersection_uint32_card(const uint32_t *A, const size_t lenA,
goto SKIP_FIRST_COMPARE;
}
}
return card; // NOTREACHED
// return card; // NOTREACHED
}

// can one vectorize the computation of the union? (Update: Yes! See
Expand Down Expand Up @@ -1842,8 +1842,8 @@ uint32_t xor_vector16(const uint16_t *__restrict__ array1, uint32_t length1,
// last value of vecMax,
// we store to "buffer"
int leftoversize = store_unique_xor(laststore, vecMax, buffer);
uint16_t vec7 = _mm_extract_epi16(vecMax, 7);
uint16_t vec6 = _mm_extract_epi16(vecMax, 6);
uint16_t vec7 = (uint16_t)_mm_extract_epi16(vecMax, 7);
uint16_t vec6 = (uint16_t)_mm_extract_epi16(vecMax, 6);
if (vec7 != vec6) buffer[leftoversize++] = vec7;
if (pos1 == len1) {
memcpy(buffer + leftoversize, array1 + 8 * pos1,
Expand Down
14 changes: 7 additions & 7 deletions src/bitset_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,9 @@ size_t bitset_extract_setbits_avx512(const uint64_t *words, size_t length, uint3
uint64_t v = words[i];
__m512i vec = _mm512_maskz_compress_epi8(v, index_table);

uint8_t advance = roaring_hamming(v);
uint8_t advance = (uint8_t)roaring_hamming(v);

__m512i vbase = _mm512_add_epi32(base_v, _mm512_set1_epi32(i * 64));
__m512i vbase = _mm512_add_epi32(base_v, _mm512_set1_epi32((int)(i * 64)));
__m512i r1 = _mm512_cvtepi8_epi32(_mm512_extracti32x4_epi32(vec,0));
__m512i r2 = _mm512_cvtepi8_epi32(_mm512_extracti32x4_epi32(vec,1));
__m512i r3 = _mm512_cvtepi8_epi32(_mm512_extracti32x4_epi32(vec,2));
Expand Down Expand Up @@ -635,9 +635,9 @@ size_t bitset_extract_setbits_avx512_uint16(const uint64_t *array, size_t length
uint64_t v = array[i];
__m512i vec = _mm512_maskz_compress_epi8(v, index_table);

uint8_t advance = roaring_hamming(v);
uint8_t advance = (uint8_t)roaring_hamming(v);

__m512i vbase = _mm512_add_epi16(base_v, _mm512_set1_epi16(i * 64));
__m512i vbase = _mm512_add_epi16(base_v, _mm512_set1_epi16((short)(i * 64)));
__m512i r1 = _mm512_cvtepi8_epi16(_mm512_extracti32x8_epi32(vec,0));
__m512i r2 = _mm512_cvtepi8_epi16(_mm512_extracti32x8_epi32(vec,1));

Expand Down Expand Up @@ -755,7 +755,7 @@ size_t bitset_extract_intersection_setbits_uint16(const uint64_t * __restrict__
while (w != 0) {
uint64_t t = w & (~w + 1);
int r = roaring_trailing_zeroes(w);
out[outpos++] = r + base;
out[outpos++] = (uint16_t)(r + base);
w ^= t;
}
base += 64;
Expand Down Expand Up @@ -819,7 +819,7 @@ size_t bitset_extract_setbits_sse_uint16(const uint64_t *words, size_t length,
while ((w != 0) && (out < safeout)) {
uint64_t t = w & (~w + 1);
int r = roaring_trailing_zeroes(w);
*out = r + base;
*out = (uint16_t)(r + base);
out++;
w ^= t;
}
Expand Down Expand Up @@ -847,7 +847,7 @@ size_t bitset_extract_setbits_uint16(const uint64_t *words, size_t length,
while (w != 0) {
uint64_t t = w & (~w + 1);
int r = roaring_trailing_zeroes(w);
out[outpos++] = r + base;
out[outpos++] = (uint16_t)(r + base);
w ^= t;
}
base += 64;
Expand Down
Loading
Loading