Aesthetics in C code and replaced some asserts with NULL returns.
This commit is contained in:
parent
4e4d36d833
commit
24e645febe
|
@ -227,7 +227,7 @@ bdz_config_data_t *bdz_config_new(void)
|
|||
{
|
||||
bdz_config_data_t *bdz;
|
||||
bdz = (bdz_config_data_t *)malloc(sizeof(bdz_config_data_t));
|
||||
assert(bdz);
|
||||
if (!bdz) return NULL;
|
||||
memset(bdz, 0, sizeof(bdz_config_data_t));
|
||||
bdz->hashfunc = CMPH_HASH_JENKINS;
|
||||
bdz->g = NULL;
|
||||
|
|
|
@ -128,4 +128,3 @@ int main(int argc, char** argv) {
|
|||
lsmap_destroy(g_created_mphf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ bmz_config_data_t *bmz_config_new(void)
|
|||
{
|
||||
bmz_config_data_t *bmz = NULL;
|
||||
bmz = (bmz_config_data_t *)malloc(sizeof(bmz_config_data_t));
|
||||
assert(bmz);
|
||||
if (!bmz) return NULL;
|
||||
memset(bmz, 0, sizeof(bmz_config_data_t));
|
||||
bmz->hashfuncs[0] = CMPH_HASH_JENKINS;
|
||||
bmz->hashfuncs[1] = CMPH_HASH_JENKINS;
|
||||
|
|
|
@ -23,7 +23,7 @@ bmz8_config_data_t *bmz8_config_new(void)
|
|||
{
|
||||
bmz8_config_data_t *bmz8;
|
||||
bmz8 = (bmz8_config_data_t *)malloc(sizeof(bmz8_config_data_t));
|
||||
assert(bmz8);
|
||||
if (!bmz8) return NULL;
|
||||
memset(bmz8, 0, sizeof(bmz8_config_data_t));
|
||||
bmz8->hashfuncs[0] = CMPH_HASH_JENKINS;
|
||||
bmz8->hashfuncs[1] = CMPH_HASH_JENKINS;
|
||||
|
|
|
@ -28,6 +28,7 @@ brz_config_data_t *brz_config_new(void)
|
|||
{
|
||||
brz_config_data_t *brz = NULL;
|
||||
brz = (brz_config_data_t *)malloc(sizeof(brz_config_data_t));
|
||||
if (!brz) return NULL;
|
||||
brz->algo = CMPH_FCH;
|
||||
brz->b = 128;
|
||||
brz->hashfuncs[0] = CMPH_HASH_JENKINS;
|
||||
|
@ -982,4 +983,3 @@ cmph_uint32 brz_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke
|
|||
default: assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ struct __buffer_entry_t
|
|||
buffer_entry_t * buffer_entry_new(cmph_uint32 capacity)
|
||||
{
|
||||
buffer_entry_t *buff_entry = (buffer_entry_t *)malloc(sizeof(buffer_entry_t));
|
||||
assert(buff_entry);
|
||||
if (!buff_entry) return NULL;
|
||||
buff_entry->fd = NULL;
|
||||
buff_entry->buff = NULL;
|
||||
buff_entry->capacity = capacity;
|
||||
|
|
|
@ -16,7 +16,7 @@ buffer_manage_t * buffer_manage_new(cmph_uint32 memory_avail, cmph_uint32 nentri
|
|||
{
|
||||
cmph_uint32 memory_avail_entry, i;
|
||||
buffer_manage_t *buff_manage = (buffer_manage_t *)malloc(sizeof(buffer_manage_t));
|
||||
assert(buff_manage);
|
||||
if (!buff_manage) return NULL;
|
||||
buff_manage->memory_avail = memory_avail;
|
||||
buff_manage->buffer_entries = (buffer_entry_t **)calloc((size_t)nentries, sizeof(buffer_entry_t *));
|
||||
buff_manage->memory_avail_list = (cmph_uint32 *)calloc((size_t)nentries, sizeof(cmph_uint32));
|
||||
|
|
|
@ -16,7 +16,7 @@ buffer_manager_t * buffer_manager_new(cmph_uint32 memory_avail, cmph_uint32 nent
|
|||
{
|
||||
cmph_uint32 memory_avail_entry, i;
|
||||
buffer_manager_t *buff_manager = (buffer_manager_t *)malloc(sizeof(buffer_manager_t));
|
||||
assert(buff_manager);
|
||||
if (!buff_manager) return NULL;
|
||||
buff_manager->memory_avail = memory_avail;
|
||||
buff_manager->buffer_entries = (buffer_entry_t **)calloc((size_t)nentries, sizeof(buffer_entry_t *));
|
||||
buff_manager->memory_avail_list = (cmph_uint32 *)calloc((size_t)nentries, sizeof(cmph_uint32));
|
||||
|
|
|
@ -18,7 +18,7 @@ chd_config_data_t *chd_config_new(cmph_config_t *mph)
|
|||
cmph_io_adapter_t *key_source = mph->key_source;
|
||||
chd_config_data_t *chd;
|
||||
chd = (chd_config_data_t *)malloc(sizeof(chd_config_data_t));
|
||||
assert(chd);
|
||||
if (!chd) return NULL;
|
||||
memset(chd, 0, sizeof(chd_config_data_t));
|
||||
|
||||
chd->chd_ph = cmph_config_new(key_source);
|
||||
|
@ -268,5 +268,3 @@ cmph_uint32 chd_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke
|
|||
register cmph_uint8 * packed_chd_phf = ((cmph_uint8 *) ptr) + packed_cr_size + sizeof(cmph_uint32);
|
||||
return _chd_search(packed_chd_phf, ptr, key, keylen);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ chd_ph_config_data_t *chd_ph_config_new(void)
|
|||
{
|
||||
chd_ph_config_data_t *chd_ph;
|
||||
chd_ph = (chd_ph_config_data_t *)malloc(sizeof(chd_ph_config_data_t));
|
||||
assert(chd_ph);
|
||||
if (!chd_ph) return NULL;
|
||||
memset(chd_ph, 0, sizeof(chd_ph_config_data_t));
|
||||
|
||||
chd_ph->hashfunc = CMPH_HASH_JENKINS;
|
||||
|
@ -983,6 +983,3 @@ cmph_uint32 chd_ph_search_packed(void *packed_mphf, const char *key, cmph_uint32
|
|||
position = (cmph_uint32)((f + ((cmph_uint64 )h)*probe0_num + probe1_num) % n);
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ chm_config_data_t *chm_config_new(void)
|
|||
{
|
||||
chm_config_data_t *chm = NULL;
|
||||
chm = (chm_config_data_t *)malloc(sizeof(chm_config_data_t));
|
||||
assert(chm);
|
||||
if (!chm) return NULL;
|
||||
memset(chm, 0, sizeof(chm_config_data_t));
|
||||
chm->hashfuncs[0] = CMPH_HASH_JENKINS;
|
||||
chm->hashfuncs[1] = CMPH_HASH_JENKINS;
|
||||
|
|
|
@ -65,5 +65,3 @@ cmph_t *__cmph_load(FILE *f)
|
|||
|
||||
return mphf;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
djb2_state_t *djb2_state_new()
|
||||
{
|
||||
djb2_state_t *state = (djb2_state_t *)malloc(sizeof(djb2_state_t));
|
||||
if (!djb2_state) return NULL;
|
||||
state->hashfunc = CMPH_HASH_DJB2;
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ fch_config_data_t *fch_config_new()
|
|||
{
|
||||
fch_config_data_t *fch;
|
||||
fch = (fch_config_data_t *)malloc(sizeof(fch_config_data_t));
|
||||
assert(fch);
|
||||
if (!fch) return NULL;
|
||||
memset(fch, 0, sizeof(fch_config_data_t));
|
||||
fch->hashfuncs[0] = CMPH_HASH_JENKINS;
|
||||
fch->hashfuncs[1] = CMPH_HASH_JENKINS;
|
||||
|
@ -514,4 +514,3 @@ cmph_uint32 fch_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke
|
|||
h1 = mixh10h11h12 (b, p1, p2, h1);
|
||||
return (h2 + g_ptr[h1]) % m;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ fch_buckets_t * fch_buckets_new(cmph_uint32 nbuckets)
|
|||
{
|
||||
cmph_uint32 i;
|
||||
fch_buckets_t *buckets = (fch_buckets_t *)malloc(sizeof(fch_buckets_t));
|
||||
assert(buckets);
|
||||
if (!buckets) return NULL;
|
||||
buckets->values = (fch_bucket_t *)calloc((size_t)nbuckets, sizeof(fch_bucket_t));
|
||||
for (i = 0; i < nbuckets; i++) fch_bucket_new(buckets->values + i);
|
||||
assert(buckets->values);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
fnv_state_t *fnv_state_new()
|
||||
{
|
||||
fnv_state_t *state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
|
||||
if (!state) return NULL;
|
||||
state->hashfunc = CMPH_HASH_FNV;
|
||||
return state;
|
||||
}
|
||||
|
@ -41,6 +42,7 @@ void fnv_state_dump(fnv_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
fnv_state_t * fnv_state_copy(fnv_state_t *src_state)
|
||||
{
|
||||
fnv_state_t *dest_state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
|
||||
if (!dest_state) return NULL;
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
return dest_state;
|
||||
}
|
||||
|
|
|
@ -334,5 +334,3 @@ cmph_uint32 graph_next_neighbor(graph_t *g, graph_iterator_t* it)
|
|||
it->edge = g->next[it->edge];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ acceptable. Do NOT use for cryptographic purposes.
|
|||
jenkins_state_t *jenkins_state_new(cmph_uint32 size) //size of hash table
|
||||
{
|
||||
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||
if (!state) return NULL;
|
||||
DEBUGP("Initializing jenkins hash\n");
|
||||
state->seed = ((cmph_uint32)rand() % size);
|
||||
return state;
|
||||
|
|
|
@ -12,6 +12,7 @@ struct __linear_string_map_t {
|
|||
|
||||
lsmap_t *lsmap_new() {
|
||||
lsmap_t* lsmap = (lsmap_t*)malloc(sizeof(lsmap_t));
|
||||
if (!lsmap) return NULL;
|
||||
lsmap->key = "dummy node";
|
||||
lsmap->next = NULL;
|
||||
return lsmap;
|
||||
|
@ -65,4 +66,3 @@ void lsmap_destroy(lsmap_t *lsmap) {
|
|||
}
|
||||
free(lsmap);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
sdbm_state_t *sdbm_state_new()
|
||||
{
|
||||
sdbm_state_t *state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
|
||||
if (!state) return NULL;
|
||||
state->hashfunc = CMPH_HASH_SDBM;
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ vqueue_t * vqueue_new(cmph_uint32 capacity)
|
|||
{
|
||||
size_t capacity_plus_one = capacity + 1;
|
||||
vqueue_t *q = (vqueue_t *)malloc(sizeof(vqueue_t));
|
||||
assert(q);
|
||||
if (!q) return NULL;
|
||||
q->values = (cmph_uint32 *)calloc(capacity_plus_one, sizeof(cmph_uint32));
|
||||
q->beg = q->end = 0;
|
||||
q->capacity = (cmph_uint32) capacity_plus_one;
|
||||
|
|
|
@ -76,4 +76,3 @@ void vstack_reserve(vstack_t *stack, cmph_uint32 size)
|
|||
DEBUGP("Increased\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue