From 5fdc52be55c3bbf2f61e2ba0c8a64db6f14e40f8 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Thu, 30 Nov 2023 18:16:50 -0500 Subject: [PATCH] Adding many explicit casts (#528) * Adding many explicit casts * casting to 32-bit integer instead --------- Co-authored-by: Daniel Lemire --- include/roaring/containers/array.h | 6 +- include/roaring/containers/bitset.h | 2 +- include/roaring/containers/containers.h | 42 ++-- include/roaring/containers/run.h | 30 +-- src/array_util.c | 12 +- src/bitset_util.c | 14 +- src/roaring.c | 318 ++++++++++++------------ src/roaring_array.c | 2 +- src/roaring_priority_queue.c | 24 +- 9 files changed, 225 insertions(+), 225 deletions(-) diff --git a/include/roaring/containers/array.h b/include/roaring/containers/array.h index 3070d6e33..d04a74433 100644 --- a/include/roaring/containers/array.h +++ b/include/roaring/containers/array.h @@ -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) { @@ -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; } diff --git a/include/roaring/containers/bitset.h b/include/roaring/containers/bitset.h index a27e715ae..04dd20be9 100644 --- a/include/roaring/containers/bitset.h +++ b/include/roaring/containers/bitset.h @@ -208,7 +208,7 @@ static inline bool bitset_container_get_range(const bitset_container_t *bitset, return false; } - for (uint16_t i = start + 1; (i < BITSET_CONTAINER_SIZE_IN_WORDS) && (i < end); ++i){ + for (uint32_t i = start + 1; (i < BITSET_CONTAINER_SIZE_IN_WORDS) && (i < end); ++i){ if (bitset->words[i] != UINT64_C(0xFFFFFFFFFFFFFFFF)) return false; } diff --git a/include/roaring/containers/containers.h b/include/roaring/containers/containers.h index d011cc02e..7f69d0c2e 100644 --- a/include/roaring/containers/containers.h +++ b/include/roaring/containers/containers.h @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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: @@ -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; @@ -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: @@ -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; @@ -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)) { @@ -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); @@ -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) { diff --git a/include/roaring/containers/run.h b/include/roaring/containers/run.h index f24a579a3..7d24cd45c 100644 --- a/include/roaring/containers/run.h +++ b/include/roaring/containers/run.h @@ -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)){ @@ -590,9 +590,9 @@ 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 + @@ -600,8 +600,8 @@ static inline void run_container_add_range_nruns(run_container_t* run, 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]), @@ -641,20 +641,20 @@ 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; } @@ -662,7 +662,7 @@ static inline void run_container_remove_range(run_container_t *run, uint32_t min // 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 { @@ -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 { diff --git a/src/array_util.c b/src/array_util.c index eb7dcbc49..cddd27fb2 100644 --- a/src/array_util.c +++ b/src/array_util.c @@ -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, @@ -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 } @@ -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, @@ -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 @@ -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, diff --git a/src/bitset_util.c b/src/bitset_util.c index 7096b27b1..3a22e6c03 100644 --- a/src/bitset_util.c +++ b/src/bitset_util.c @@ -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)); @@ -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)); @@ -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; @@ -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; } @@ -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; diff --git a/src/roaring.c b/src/roaring.c index c863aa531..5bab37810 100644 --- a/src/roaring.c +++ b/src/roaring.c @@ -49,8 +49,8 @@ static inline container_t *containerptr_roaring_bitmap_add( uint16_t hb = val >> 16; const int i = ra_get_index(ra, hb); if (i >= 0) { - ra_unshare_container_at_index(ra, i); - container_t *c = ra_get_container_at_index(ra, i, type); + ra_unshare_container_at_index(ra, (uint16_t)i); + container_t *c = ra_get_container_at_index(ra, (uint16_t)i, type); uint8_t new_type = *type; container_t *c2 = container_add(c, val & 0xFFFF, *type, &new_type); *index = i; @@ -165,10 +165,10 @@ bool roaring_bitmap_contains_bulk(const roaring_bitmap_t *r, return false; } uint8_t typecode; - context->container = ra_get_container_at_index(&r->high_low_container, idx, &typecode); + context->container = ra_get_container_at_index(&r->high_low_container, (uint16_t)idx, &typecode); context->typecode = typecode; context->idx = idx; - context->key = ra_get_key_at_index(&r->high_low_container, idx); + context->key = ra_get_key_at_index(&r->high_low_container, (uint16_t)idx); // ra_advance_until finds the next key >= the target, we found a later container. if (context->key != key) { return false; @@ -229,7 +229,7 @@ roaring_bitmap_t *roaring_bitmap_from_range(uint64_t min, uint64_t max, uint8_t type; container_t *container = container_from_range(&type, container_min, container_max, (uint16_t)step); - ra_append(&answer->high_low_container, key, container, type); + ra_append(&answer->high_low_container, (uint16_t)key, container, type); uint32_t gap = container_max - container_min + step - 1; min_tmp += gap - (gap % step); } while (min_tmp < max); @@ -248,9 +248,9 @@ void roaring_bitmap_add_range_closed(roaring_bitmap_t *r, uint32_t min, uint32_t uint32_t max_key = max >> 16; int32_t num_required_containers = max_key - min_key + 1; - int32_t suffix_length = count_greater(ra->keys, ra->size, max_key); + int32_t suffix_length = count_greater(ra->keys, ra->size, (uint16_t)max_key); int32_t prefix_length = count_less(ra->keys, ra->size - suffix_length, - min_key); + (uint16_t)min_key); int32_t common_length = ra->size - prefix_length - suffix_length; if (num_required_containers > common_length) { @@ -267,7 +267,7 @@ void roaring_bitmap_add_range_closed(roaring_bitmap_t *r, uint32_t min, uint32_t uint8_t new_type; if (src >= 0 && ra->keys[src] == key) { - ra_unshare_container_at_index(ra, src); + ra_unshare_container_at_index(ra, (uint16_t)src); new_container = container_add_range(ra->containers[src], ra->typecodes[src], container_min, container_max, @@ -281,7 +281,7 @@ void roaring_bitmap_add_range_closed(roaring_bitmap_t *r, uint32_t min, uint32_t new_container = container_from_range(&new_type, container_min, container_max+1, 1); } - ra_replace_key_and_container_at_index(ra, dst, key, new_container, + ra_replace_key_and_container_at_index(ra, dst, (uint16_t)key, new_container, new_type); dst--; } @@ -297,12 +297,12 @@ void roaring_bitmap_remove_range_closed(roaring_bitmap_t *r, uint32_t min, uint3 uint32_t min_key = min >> 16; uint32_t max_key = max >> 16; - int32_t src = count_less(ra->keys, ra->size, min_key); + int32_t src = count_less(ra->keys, ra->size, (uint16_t)min_key); int32_t dst = src; while (src < ra->size && ra->keys[src] <= max_key) { uint32_t container_min = (min_key == ra->keys[src]) ? (min & 0xffff) : 0; uint32_t container_max = (max_key == ra->keys[src]) ? (max & 0xffff) : 0xffff; - ra_unshare_container_at_index(ra, src); + ra_unshare_container_at_index(ra, (uint16_t)src); container_t *new_container; uint8_t new_type; new_container = container_remove_range(ra->containers[src], @@ -543,9 +543,9 @@ void roaring_bitmap_add(roaring_bitmap_t *r, uint32_t val) { const int i = ra_get_index(ra, hb); uint8_t typecode; if (i >= 0) { - ra_unshare_container_at_index(ra, i); + ra_unshare_container_at_index(ra, (uint16_t)i); container_t *container = - ra_get_container_at_index(ra, i, &typecode); + ra_get_container_at_index(ra, (uint16_t)i, &typecode); uint8_t newtypecode = typecode; container_t *container2 = container_add(container, val & 0xFFFF, typecode, &newtypecode); @@ -570,9 +570,9 @@ bool roaring_bitmap_add_checked(roaring_bitmap_t *r, uint32_t val) { uint8_t typecode; bool result = false; if (i >= 0) { - ra_unshare_container_at_index(&r->high_low_container, i); + ra_unshare_container_at_index(&r->high_low_container, (uint16_t)i); container_t *container = - ra_get_container_at_index(&r->high_low_container, i, &typecode); + ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &typecode); const int oldCardinality = container_get_cardinality(container, typecode); @@ -609,9 +609,9 @@ void roaring_bitmap_remove(roaring_bitmap_t *r, uint32_t val) { const int i = ra_get_index(&r->high_low_container, hb); uint8_t typecode; if (i >= 0) { - ra_unshare_container_at_index(&r->high_low_container, i); + ra_unshare_container_at_index(&r->high_low_container, (uint16_t)i); container_t *container = - ra_get_container_at_index(&r->high_low_container, i, &typecode); + ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &typecode); uint8_t newtypecode = typecode; container_t *container2 = container_remove(container, val & 0xFFFF, typecode, &newtypecode); @@ -635,9 +635,9 @@ bool roaring_bitmap_remove_checked(roaring_bitmap_t *r, uint32_t val) { uint8_t typecode; bool result = false; if (i >= 0) { - ra_unshare_container_at_index(&r->high_low_container, i); + ra_unshare_container_at_index(&r->high_low_container, (uint16_t)i); container_t *container = - ra_get_container_at_index(&r->high_low_container, i, &typecode); + ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &typecode); const int oldCardinality = container_get_cardinality(container, typecode); @@ -713,15 +713,15 @@ roaring_bitmap_t *roaring_bitmap_and(const roaring_bitmap_t *x1, int pos1 = 0, pos2 = 0; while (pos1 < length1 && pos2 < length2) { - const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); if (s1 == s2) { uint8_t type1, type2; container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_and(c1, type1, c2, type2, &result_type); if (container_nonzero_cardinality(c, result_type)) { @@ -790,15 +790,15 @@ void roaring_bitmap_and_inplace(roaring_bitmap_t *x1, // any skipped-over or newly emptied containers in x1 // have to be freed. while (pos1 < length1 && pos2 < length2) { - const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); if (s1 == s2) { uint8_t type1, type2, result_type; container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // We do the computation "in place" only when c1 is not a shared container. // Rationale: using a shared container safely with in place computation would @@ -859,14 +859,14 @@ roaring_bitmap_t *roaring_bitmap_or(const roaring_bitmap_t *x1, roaring_bitmap_set_copy_on_write(answer, is_cow(x1) || is_cow(x2)); int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_or(c1, type1, c2, type2, &result_type); // since we assume that the initial containers are non-empty, the @@ -877,12 +877,12 @@ roaring_bitmap_t *roaring_bitmap_or(const roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); // c1 = container_clone(c1, type1); c1 = get_copy_of_container(c1, &type1, is_cow(x1)); if (is_cow(x1)) { @@ -892,11 +892,11 @@ roaring_bitmap_t *roaring_bitmap_or(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s1, c1, type1); pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // c2 = container_clone(c2, type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { @@ -906,7 +906,7 @@ roaring_bitmap_t *roaring_bitmap_or(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s2, c2, type2); pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -936,15 +936,15 @@ void roaring_bitmap_or_inplace(roaring_bitmap_t *x1, } int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); if (!container_is_full(c1, type1)) { container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = (type1 == SHARED_CONTAINER_TYPE) ? container_or(c1, type1, c2, type2, &result_type) @@ -961,17 +961,17 @@ void roaring_bitmap_or_inplace(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index(&x2->high_low_container, - pos2, &type2); + (uint16_t)pos2, &type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { ra_set_container_at_index(&x2->high_low_container, pos2, c2, @@ -985,7 +985,7 @@ void roaring_bitmap_or_inplace(roaring_bitmap_t *x1, length1++; pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -1010,14 +1010,14 @@ roaring_bitmap_t *roaring_bitmap_xor(const roaring_bitmap_t *x1, roaring_bitmap_set_copy_on_write(answer, is_cow(x1) || is_cow(x2)); int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_xor(c1, type1, c2, type2, &result_type); if (container_nonzero_cardinality(c, result_type)) { @@ -1029,12 +1029,12 @@ roaring_bitmap_t *roaring_bitmap_xor(const roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); c1 = get_copy_of_container(c1, &type1, is_cow(x1)); if (is_cow(x1)) { ra_set_container_at_index(&x1->high_low_container, pos1, c1, @@ -1043,11 +1043,11 @@ roaring_bitmap_t *roaring_bitmap_xor(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s1, c1, type1); pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { ra_set_container_at_index(&x2->high_low_container, pos2, c2, @@ -1056,7 +1056,7 @@ roaring_bitmap_t *roaring_bitmap_xor(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s2, c2, type2); pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -1092,14 +1092,14 @@ void roaring_bitmap_xor_inplace(roaring_bitmap_t *x1, int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // We do the computation "in place" only when c1 is not a shared container. // Rationale: using a shared container safely with in place computation would @@ -1129,17 +1129,17 @@ void roaring_bitmap_xor_inplace(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { ra_set_container_at_index(&x2->high_low_container, pos2, c2, @@ -1152,7 +1152,7 @@ void roaring_bitmap_xor_inplace(roaring_bitmap_t *x1, length1++; pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -1182,14 +1182,14 @@ roaring_bitmap_t *roaring_bitmap_andnot(const roaring_bitmap_t *x1, uint16_t s1 = 0; uint16_t s2 = 0; while (true) { - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_andnot(c1, type1, c2, type2, &result_type); @@ -1245,14 +1245,14 @@ void roaring_bitmap_andnot_inplace(roaring_bitmap_t *x1, int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // We do the computation "in place" only when c1 is not a shared container. // Rationale: using a shared container safely with in place computation would @@ -1281,13 +1281,13 @@ void roaring_bitmap_andnot_inplace(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 if (pos1 != intersection_size) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); ra_replace_key_and_container_at_index(&x1->high_low_container, intersection_size, s1, c1, @@ -1296,12 +1296,12 @@ void roaring_bitmap_andnot_inplace(roaring_bitmap_t *x1, intersection_size++; pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 pos2 = ra_advance_until(&x2->high_low_container, s1, pos2); if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } @@ -1346,8 +1346,8 @@ uint64_t roaring_bitmap_range_cardinality(const roaring_bitmap_t *r, range_end--; // make range_end inclusive // now we have: 0 <= range_start <= range_end <= UINT32_MAX - uint16_t minhb = range_start >> 16; - uint16_t maxhb = range_end >> 16; + uint16_t minhb = (uint16_t)(range_start >> 16); + uint16_t maxhb = (uint16_t)(range_end >> 16); uint64_t card = 0; @@ -1411,8 +1411,8 @@ bool roaring_bitmap_run_optimize(roaring_bitmap_t *r) { for (int i = 0; i < r->high_low_container.size; i++) { uint8_t type_original, type_after; ra_unshare_container_at_index( - &r->high_low_container, i); // TODO: this introduces extra cloning! - container_t *c = ra_get_container_at_index(&r->high_low_container, i, + &r->high_low_container, (uint16_t)i); // TODO: this introduces extra cloning! + container_t *c = ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &type_original); container_t *c1 = convert_run_optimize(c, type_original, &type_after); if (type_after == RUN_CONTAINER_TYPE) { @@ -1427,7 +1427,7 @@ size_t roaring_bitmap_shrink_to_fit(roaring_bitmap_t *r) { size_t answer = 0; for (int i = 0; i < r->high_low_container.size; i++) { uint8_t type_original; - container_t *c = ra_get_container_at_index(&r->high_low_container, i, + container_t *c = ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &type_original); answer += container_shrink_to_fit(c, type_original); } @@ -1443,7 +1443,7 @@ bool roaring_bitmap_remove_run_compression(roaring_bitmap_t *r) { bool answer = false; for (int i = 0; i < r->high_low_container.size; i++) { uint8_t type_original, type_after; - container_t *c = ra_get_container_at_index(&r->high_low_container, i, + container_t *c = ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &type_original); if (get_container_type(c, type_original) == RUN_CONTAINER_TYPE) { answer = true; @@ -2090,13 +2090,13 @@ bool roaring_bitmap_is_subset(const roaring_bitmap_t *r1, int pos1 = 0, pos2 = 0; while (pos1 < length1 && pos2 < length2) { - const uint16_t s1 = ra_get_key_at_index(ra1, pos1); - const uint16_t s2 = ra_get_key_at_index(ra2, pos2); + const uint16_t s1 = ra_get_key_at_index(ra1, (uint16_t)pos1); + const uint16_t s2 = ra_get_key_at_index(ra2, (uint16_t)pos2); if (s1 == s2) { uint8_t type1, type2; - container_t *c1 = ra_get_container_at_index(ra1, pos1, &type1); - container_t *c2 = ra_get_container_at_index(ra2, pos2, &type2); + container_t *c1 = ra_get_container_at_index(ra1, (uint16_t)pos1, &type1); + container_t *c2 = ra_get_container_at_index(ra2, (uint16_t)pos2, &type2); if (!container_is_subset(c1, type1, c2, type2)) return false; ++pos1; @@ -2122,7 +2122,7 @@ static void insert_flipped_container(roaring_array_t *ans_arr, container_t *flipped_container = NULL; if (i >= 0) { container_t *container_to_flip = - ra_get_container_at_index(x1_arr, i, &ctype_in); + ra_get_container_at_index(x1_arr, (uint16_t)i, &ctype_in); flipped_container = container_not_range(container_to_flip, ctype_in, (uint32_t)lb_start, (uint32_t)(lb_end + 1), &ctype_out); @@ -2148,7 +2148,7 @@ static void inplace_flip_container(roaring_array_t *x1_arr, uint16_t hb, container_t *flipped_container = NULL; if (i >= 0) { container_t *container_to_flip = - ra_get_container_at_index(x1_arr, i, &ctype_in); + ra_get_container_at_index(x1_arr, (uint16_t)i, &ctype_in); flipped_container = container_inot_range( container_to_flip, ctype_in, (uint32_t)lb_start, (uint32_t)(lb_end + 1), &ctype_out); @@ -2177,7 +2177,7 @@ static void insert_fully_flipped_container(roaring_array_t *ans_arr, container_t *flipped_container = NULL; if (i >= 0) { container_t *container_to_flip = - ra_get_container_at_index(x1_arr, i, &ctype_in); + ra_get_container_at_index(x1_arr, (uint16_t)i, &ctype_in); flipped_container = container_not(container_to_flip, ctype_in, &ctype_out); if (container_get_cardinality(flipped_container, ctype_out)) @@ -2199,7 +2199,7 @@ static void inplace_fully_flip_container(roaring_array_t *x1_arr, uint16_t hb) { container_t *flipped_container = NULL; if (i >= 0) { container_t *container_to_flip = - ra_get_container_at_index(x1_arr, i, &ctype_in); + ra_get_container_at_index(x1_arr, (uint16_t)i, &ctype_in); flipped_container = container_inot(container_to_flip, ctype_in, &ctype_out); @@ -2255,7 +2255,7 @@ roaring_bitmap_t *roaring_bitmap_flip(const roaring_bitmap_t *x1, for (uint32_t hb = hb_start; hb <= hb_end; ++hb) { insert_fully_flipped_container(&ans->high_low_container, - &x1->high_low_container, hb); + &x1->high_low_container, (uint16_t)hb); } // handle a partial final container @@ -2300,7 +2300,7 @@ void roaring_bitmap_flip_inplace(roaring_bitmap_t *x1, uint64_t range_start, if (lb_end != 0xFFFF) --hb_end; for (uint32_t hb = hb_start; hb <= hb_end; ++hb) { - inplace_fully_flip_container(&x1->high_low_container, hb); + inplace_fully_flip_container(&x1->high_low_container, (uint16_t)hb); } // handle a partial final container if (lb_end != 0xFFFF) { @@ -2313,9 +2313,9 @@ void roaring_bitmap_flip_inplace(roaring_bitmap_t *x1, uint64_t range_start, static void offset_append_with_merge(roaring_array_t *ra, int k, container_t *c, uint8_t t) { int size = ra_get_size(ra); - if (size == 0 || ra_get_key_at_index(ra, size-1) != k) { + if (size == 0 || ra_get_key_at_index(ra, (uint16_t)(size-1)) != k) { // No merge. - ra_append(ra, k, c, t); + ra_append(ra, (uint16_t)k, c, t); return; } @@ -2325,7 +2325,7 @@ static void offset_append_with_merge(roaring_array_t *ra, int k, container_t *c, // NOTE: we don't need to unwrap here, since we added last_c ourselves // we have the certainty it's not a shared container. // The same applies to c, as it's the result of calling container_offset. - last_c = ra_get_container_at_index(ra, size-1, &last_t); + last_c = ra_get_container_at_index(ra, (uint16_t)(size-1), &last_t); new_c = container_ior(last_c, last_t, c, t, &new_t); ra_set_container_at_index(ra, size-1, new_c, new_t); @@ -2369,15 +2369,15 @@ roaring_bitmap_t *roaring_bitmap_add_offset(const roaring_bitmap_t *bm, ans_ra = &answer->high_low_container; for (int i = 0, j = 0; i < length; ++i) { - int64_t key = ra_get_key_at_index(bm_ra, i); + int64_t key = ra_get_key_at_index(bm_ra, (uint16_t)i); key += container_offset; if (key < 0 || key >= (1 << 16)) { continue; } - ra_append_copy(ans_ra, bm_ra, i, false); - ans_ra->keys[j++] = key; + ra_append_copy(ans_ra, bm_ra, (uint16_t)i, false); + ans_ra->keys[j++] = (uint16_t)key; } return answer; @@ -2392,7 +2392,7 @@ roaring_bitmap_t *roaring_bitmap_add_offset(const roaring_bitmap_t *bm, lo = hi = NULL; lo_ptr = hi_ptr = NULL; - k = ra_get_key_at_index(bm_ra, i)+container_offset; + k = ra_get_key_at_index(bm_ra, (uint16_t)i)+container_offset; if (k >= 0 && k < (1 << 16)) { lo_ptr = &lo; } @@ -2403,15 +2403,15 @@ roaring_bitmap_t *roaring_bitmap_add_offset(const roaring_bitmap_t *bm, continue; } - c = ra_get_container_at_index(bm_ra, i, &t); + c = ra_get_container_at_index(bm_ra, (uint16_t)i, &t); c = container_unwrap_shared(c, &t); container_add_offset(c, t, lo_ptr, hi_ptr, in_offset); if (lo != NULL) { - offset_append_with_merge(ans_ra, k, lo, t); + offset_append_with_merge(ans_ra, (int)k, lo, t); } if (hi != NULL) { - ra_append(ans_ra, k+1, hi, t); + ra_append(ans_ra, (uint16_t)(k+1), hi, t); } } @@ -2435,14 +2435,14 @@ roaring_bitmap_t *roaring_bitmap_lazy_or(const roaring_bitmap_t *x1, roaring_bitmap_set_copy_on_write(answer, is_cow(x1) || is_cow(x2)); int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c; if (bitsetconversion && (get_container_type(c1, type1) != BITSET_CONTAINER_TYPE) && @@ -2469,12 +2469,12 @@ roaring_bitmap_t *roaring_bitmap_lazy_or(const roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); c1 = get_copy_of_container(c1, &type1, is_cow(x1)); if (is_cow(x1)) { ra_set_container_at_index(&x1->high_low_container, pos1, c1, @@ -2483,11 +2483,11 @@ roaring_bitmap_t *roaring_bitmap_lazy_or(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s1, c1, type1); pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { ra_set_container_at_index(&x2->high_low_container, pos2, c2, @@ -2496,7 +2496,7 @@ roaring_bitmap_t *roaring_bitmap_lazy_or(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s2, c2, type2); pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -2526,12 +2526,12 @@ void roaring_bitmap_lazy_or_inplace(roaring_bitmap_t *x1, } int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); if (!container_is_full(c1, type1)) { if ((bitsetconversion == false) || (get_container_type(c1, type1) == BITSET_CONTAINER_TYPE) @@ -2548,7 +2548,7 @@ void roaring_bitmap_lazy_or_inplace(roaring_bitmap_t *x1, } container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_lazy_ior(c1, type1, c2, type2, &result_type); @@ -2564,17 +2564,17 @@ void roaring_bitmap_lazy_or_inplace(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // container_t *c2_clone = container_clone(c2, type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { @@ -2587,7 +2587,7 @@ void roaring_bitmap_lazy_or_inplace(roaring_bitmap_t *x1, length1++; pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -2612,14 +2612,14 @@ roaring_bitmap_t *roaring_bitmap_lazy_xor(const roaring_bitmap_t *x1, roaring_bitmap_set_copy_on_write(answer, is_cow(x1) || is_cow(x2)); int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); container_t *c = container_lazy_xor( c1, type1, c2, type2, &result_type); @@ -2633,12 +2633,12 @@ roaring_bitmap_t *roaring_bitmap_lazy_xor(const roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); c1 = get_copy_of_container(c1, &type1, is_cow(x1)); if (is_cow(x1)) { ra_set_container_at_index(&x1->high_low_container, pos1, c1, @@ -2647,11 +2647,11 @@ roaring_bitmap_t *roaring_bitmap_lazy_xor(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s1, c1, type1); pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { ra_set_container_at_index(&x2->high_low_container, pos2, c2, @@ -2660,7 +2660,7 @@ roaring_bitmap_t *roaring_bitmap_lazy_xor(const roaring_bitmap_t *x1, ra_append(&answer->high_low_container, s2, c2, type2); pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -2690,14 +2690,14 @@ void roaring_bitmap_lazy_xor_inplace(roaring_bitmap_t *x1, } int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // We do the computation "in place" only when c1 is not a shared container. // Rationale: using a shared container safely with in place computation would @@ -2726,17 +2726,17 @@ void roaring_bitmap_lazy_xor_inplace(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); // container_t *c2_clone = container_clone(c2, type2); c2 = get_copy_of_container(c2, &type2, is_cow(x2)); if (is_cow(x2)) { @@ -2749,7 +2749,7 @@ void roaring_bitmap_lazy_xor_inplace(roaring_bitmap_t *x1, length1++; pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) { @@ -2890,15 +2890,15 @@ bool roaring_bitmap_intersect(const roaring_bitmap_t *x1, int pos1 = 0, pos2 = 0; while (pos1 < length1 && pos2 < length2) { - const uint16_t s1 = ra_get_key_at_index(& x1->high_low_container, pos1); - const uint16_t s2 = ra_get_key_at_index(& x2->high_low_container, pos2); + const uint16_t s1 = ra_get_key_at_index(& x1->high_low_container, (uint16_t)pos1); + const uint16_t s2 = ra_get_key_at_index(& x2->high_low_container, (uint16_t)pos2); if (s1 == s2) { uint8_t type1, type2; container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); if (container_intersect(c1, type1, c2, type2)) return true; ++pos1; @@ -2920,7 +2920,7 @@ bool roaring_bitmap_intersect_with_range(const roaring_bitmap_t *bm, } roaring_uint32_iterator_t it; roaring_init_iterator(bm, &it); - if (!roaring_move_uint32_iterator_equalorlarger(&it, x)) { + if (!roaring_move_uint32_iterator_equalorlarger(&it, (uint32_t)x)) { // No values above x. return false; } @@ -2939,15 +2939,15 @@ uint64_t roaring_bitmap_and_cardinality(const roaring_bitmap_t *x1, uint64_t answer = 0; int pos1 = 0, pos2 = 0; while (pos1 < length1 && pos2 < length2) { - const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + const uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + const uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); if (s1 == s2) { uint8_t type1, type2; container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); answer += container_and_cardinality(c1, type1, c2, type2); ++pos1; ++pos2; @@ -3003,7 +3003,7 @@ bool roaring_bitmap_contains(const roaring_bitmap_t *r, uint32_t val) { uint8_t typecode; // next call ought to be cheap container_t *container = - ra_get_container_at_index(&r->high_low_container, i, &typecode); + ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &typecode); // rest might be a tad expensive, possibly involving another round of binary search return container_contains(container, val & 0xFFFF, typecode); } @@ -3033,7 +3033,7 @@ bool roaring_bitmap_contains_range(const roaring_bitmap_t *r, uint64_t range_sta const uint32_t lb_rs = range_start & 0xFFFF; const uint32_t lb_re = ((range_end - 1) & 0xFFFF) + 1; uint8_t type; - container_t *c = ra_get_container_at_index(&r->high_low_container, is, + container_t *c = ra_get_container_at_index(&r->high_low_container, (uint16_t)is, &type); if (hb_rs == hb_re) { return container_contains_range(c, lb_rs, lb_re, type); @@ -3041,12 +3041,12 @@ bool roaring_bitmap_contains_range(const roaring_bitmap_t *r, uint64_t range_sta if (!container_contains_range(c, lb_rs, 1 << 16, type)) { return false; } - c = ra_get_container_at_index(&r->high_low_container, ie, &type); + c = ra_get_container_at_index(&r->high_low_container, (uint16_t)ie, &type); if (!container_contains_range(c, 0, lb_re, type)) { return false; } for (int32_t i = is + 1; i < ie; ++i) { - c = ra_get_container_at_index(&r->high_low_container, i, &type); + c = ra_get_container_at_index(&r->high_low_container, (uint16_t)i, &type); if (!container_is_full(c, type) ) { return false; } @@ -3179,9 +3179,9 @@ void roaring_bitmap_frozen_serialize(const roaring_bitmap_t *rb, char *buf) { BITSET_CONTAINER_SIZE_IN_WORDS * sizeof(uint64_t)); bitset_zone += BITSET_CONTAINER_SIZE_IN_WORDS; if (bc->cardinality != BITSET_UNKNOWN_CARDINALITY) { - count = bc->cardinality - 1; + count = (uint16_t)(bc->cardinality - 1); } else { - count = bitset_container_compute_cardinality(bc) - 1; + count = (uint16_t)(bitset_container_compute_cardinality(bc) - 1); } break; } @@ -3190,7 +3190,7 @@ void roaring_bitmap_frozen_serialize(const roaring_bitmap_t *rb, char *buf) { size_t num_bytes = rc->n_runs * sizeof(rle16_t); memcpy(run_zone, rc->runs, num_bytes); run_zone += rc->n_runs; - count = rc->n_runs; + count = (uint16_t)rc->n_runs; break; } case ARRAY_CONTAINER_TYPE: { @@ -3199,7 +3199,7 @@ void roaring_bitmap_frozen_serialize(const roaring_bitmap_t *rb, char *buf) { size_t num_bytes = ac->cardinality * sizeof(uint16_t); memcpy(array_zone, ac->array, num_bytes); array_zone += ac->cardinality; - count = ac->cardinality - 1; + count = (uint16_t)(ac->cardinality - 1); break; } default: diff --git a/src/roaring_array.c b/src/roaring_array.c index 7924aaeda..631025b49 100644 --- a/src/roaring_array.c +++ b/src/roaring_array.c @@ -238,7 +238,7 @@ void ra_append_copies_until(roaring_array_t *ra, const roaring_array_t *sa, uint16_t stopping_key, bool copy_on_write) { for (int32_t i = 0; i < sa->size; ++i) { if (sa->keys[i] >= stopping_key) break; - ra_append_copy(ra, sa, i, copy_on_write); + ra_append_copy(ra, sa, (uint16_t)i, copy_on_write); } } diff --git a/src/roaring_priority_queue.c b/src/roaring_priority_queue.c index c94d2a123..93668ff13 100644 --- a/src/roaring_priority_queue.c +++ b/src/roaring_priority_queue.c @@ -113,22 +113,22 @@ static roaring_bitmap_t *lazy_or_from_lazy_inputs(roaring_bitmap_t *x1, roaring_bitmap_t *answer = roaring_bitmap_create_with_capacity(neededcap); int pos1 = 0, pos2 = 0; uint8_t type1, type2; - uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + uint16_t s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + uint16_t s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); while (true) { if (s1 == s2) { // todo: unsharing can be inefficient as it may create a clone where // none // is needed, but it has the benefit of being easy to reason about. - ra_unshare_container_at_index(&x1->high_low_container, pos1); + ra_unshare_container_at_index(&x1->high_low_container, (uint16_t)pos1); container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); assert(type1 != SHARED_CONTAINER_TYPE); - ra_unshare_container_at_index(&x2->high_low_container, pos2); + ra_unshare_container_at_index(&x2->high_low_container, (uint16_t)pos2); container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); assert(type2 != SHARED_CONTAINER_TYPE); container_t *c; @@ -156,24 +156,24 @@ static roaring_bitmap_t *lazy_or_from_lazy_inputs(roaring_bitmap_t *x1, ++pos2; if (pos1 == length1) break; if (pos2 == length2) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } else if (s1 < s2) { // s1 < s2 container_t *c1 = ra_get_container_at_index( - &x1->high_low_container, pos1, &type1); + &x1->high_low_container, (uint16_t)pos1, &type1); ra_append(&answer->high_low_container, s1, c1, type1); pos1++; if (pos1 == length1) break; - s1 = ra_get_key_at_index(&x1->high_low_container, pos1); + s1 = ra_get_key_at_index(&x1->high_low_container, (uint16_t)pos1); } else { // s1 > s2 container_t *c2 = ra_get_container_at_index( - &x2->high_low_container, pos2, &type2); + &x2->high_low_container, (uint16_t)pos2, &type2); ra_append(&answer->high_low_container, s2, c2, type2); pos2++; if (pos2 == length2) break; - s2 = ra_get_key_at_index(&x2->high_low_container, pos2); + s2 = ra_get_key_at_index(&x2->high_low_container, (uint16_t)pos2); } } if (pos1 == length1) {