Clean up C type and allocation casts
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "system.h"
|
||||
|
||||
#define CACHE_SIZE 512
|
||||
#define PIVOT_SIZE 486
|
||||
|
||||
struct set {
|
||||
size_t cnt;
|
||||
@@ -27,7 +26,7 @@ struct set {
|
||||
}* symbols_v;
|
||||
};
|
||||
|
||||
struct set* set_new() {
|
||||
struct set* set_new(void) {
|
||||
struct set* set = xmalloc(sizeof *set);
|
||||
set->cnt = 0;
|
||||
set->symbols_cap = 0;
|
||||
@@ -202,23 +201,9 @@ static int encode_set_size(int cnt, int bpp) {
|
||||
* how multiple escapes are avoided.
|
||||
*/
|
||||
|
||||
static char* bits_to_char(int c, char* base62) {
|
||||
assert(c >= 0 && c <= 61);
|
||||
|
||||
if (c < 10) {
|
||||
*base62++ = c + '0';
|
||||
} else if (c < 36) {
|
||||
*base62++ = c - 10 + 'a';
|
||||
} else if (c < 62) {
|
||||
*base62++ = c - 36 + 'A';
|
||||
}
|
||||
|
||||
return base62;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static inline char encode_bpp(int bpp) { return bpp - 7 + 'a'; }
|
||||
static inline char encode_bpp(int bpp) { return (char)(bpp - 7 + 'a'); }
|
||||
|
||||
struct encode_writer {
|
||||
uint64_t bits;
|
||||
@@ -340,7 +325,7 @@ const char* set_fini(struct set* set, int bpp) {
|
||||
}
|
||||
|
||||
unsigned unique_hash[set->cnt];
|
||||
size_t unique_cnt = 0;
|
||||
int unique_cnt = 0;
|
||||
|
||||
// delete duplicates
|
||||
for (size_t i = 0; i < set->cnt; ++i) {
|
||||
@@ -408,7 +393,7 @@ static int set_meta_fini(struct set_meta* meta) {
|
||||
return 0;
|
||||
}
|
||||
// UCHAR_MAX == 255
|
||||
static const unsigned char char_to_num[255 + 1] = {[0] = 0xff, /* конец строки */
|
||||
__extension__ static const unsigned char char_to_num[255 + 1] = {[0] = 0xff, /* конец строки */
|
||||
|
||||
[1 ...('0' - 1)] = 0xee,
|
||||
|
||||
@@ -483,26 +468,6 @@ static const unsigned char char_to_num[255 + 1] = {[0] = 0xff, /* конец с
|
||||
|
||||
[('z' + 1)... 255] = 0xee};
|
||||
|
||||
static char* put6bits(int c, char* bit_pt) {
|
||||
*bit_pt++ = (c >> 0) & 1;
|
||||
*bit_pt++ = (c >> 1) & 1;
|
||||
*bit_pt++ = (c >> 2) & 1;
|
||||
*bit_pt++ = (c >> 3) & 1;
|
||||
*bit_pt++ = (c >> 4) & 1;
|
||||
*bit_pt++ = (c >> 5) & 1;
|
||||
|
||||
return bit_pt;
|
||||
}
|
||||
|
||||
static char* put4bits(int c, char* bit_pt) {
|
||||
*bit_pt++ = (c >> 0) & 1;
|
||||
*bit_pt++ = (c >> 1) & 1;
|
||||
*bit_pt++ = (c >> 2) & 1;
|
||||
*bit_pt++ = (c >> 3) & 1;
|
||||
|
||||
return bit_pt;
|
||||
}
|
||||
|
||||
// Decode base62 and Golomb-Rice in one pass. Base62 is LSB-first; a Z escape contributes 10 stream
|
||||
// bits.
|
||||
static inline int decode_chunk(const unsigned char** input, uint64_t* chunk, unsigned* width) {
|
||||
@@ -652,7 +617,8 @@ static int cache_decode_set(struct set_meta* meta, int target_bpp, const unsigne
|
||||
|
||||
int len = (int)meta->len;
|
||||
int capacity = meta->value_capacity;
|
||||
struct cache_ent* ent = xmalloc(sizeof(*ent) + (size_t)(capacity) * sizeof(unsigned) + len + 1);
|
||||
struct cache_ent* ent =
|
||||
xmalloc(sizeof(*ent) + (size_t)capacity * sizeof(unsigned) + (size_t)len + 1);
|
||||
ent->hash_arr = (unsigned*)(ent + 1);
|
||||
ent->str = (char*)(ent->hash_arr + capacity);
|
||||
|
||||
@@ -781,7 +747,7 @@ static int downsample_set(int cnt, const unsigned* hash_pt, unsigned* ds_pt, int
|
||||
while (v1 < v1_end) *ds_pt++ = *v1++;
|
||||
while (v2 < v2_end) *ds_pt++ = *v2++ & mask;
|
||||
|
||||
return ds_pt - ds_start;
|
||||
return (int)(ds_pt - ds_start);
|
||||
}
|
||||
|
||||
static const unsigned* step_lower_bound(const unsigned* first, const unsigned* last, unsigned value,
|
||||
@@ -922,11 +888,11 @@ int main(void) {
|
||||
|
||||
set1 = set_free(set1);
|
||||
set2 = set_free(set2);
|
||||
str10 = _free(str10);
|
||||
str11 = _free(str11);
|
||||
str20 = _free(str20);
|
||||
str21 = _free(str21);
|
||||
str22 = _free(str22);
|
||||
str10 = _free((void*)str10);
|
||||
str11 = _free((void*)str11);
|
||||
str20 = _free((void*)str20);
|
||||
str21 = _free((void*)str21);
|
||||
str22 = _free((void*)str22);
|
||||
|
||||
fprintf(stderr, "%s: api test OK\n", __FILE__);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user