From 95e30831ddc46caa96b44da76f1dba1f58256eb3 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sun, 6 May 2018 13:16:12 +0100 Subject: [PATCH] refactor: unsigned int -> size_t --- mutt/hash.c | 18 +++++++++--------- mutt/hash.h | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mutt/hash.c b/mutt/hash.c index cdfcde0e8..cccd2b8ad 100644 --- a/mutt/hash.c +++ b/mutt/hash.c @@ -42,9 +42,9 @@ * @param n Number of elements in the Hash table * @retval num Cryptographic hash of the string */ -static unsigned int gen_string_hash(union HashKey key, unsigned int n) +static size_t gen_string_hash(union HashKey key, size_t n) { - unsigned int h = 0; + size_t h = 0; unsigned char *s = (unsigned char *) key.strkey; while (*s) @@ -73,9 +73,9 @@ static int cmp_string_key(union HashKey a, union HashKey b) * @param n Number of elements in the Hash table * @retval num Cryptographic hash of the string */ -static unsigned int gen_case_string_hash(union HashKey key, unsigned int n) +static size_t gen_case_string_hash(union HashKey key, size_t n) { - unsigned int h = 0; + size_t h = 0; unsigned char *s = (unsigned char *) key.strkey; while (*s) @@ -104,7 +104,7 @@ static int cmp_case_string_key(union HashKey a, union HashKey b) * @param n Number of elements in the Hash table * @retval num Cryptographic hash of the integer */ -static unsigned int gen_int_hash(union HashKey key, unsigned int n) +static size_t gen_int_hash(union HashKey key, size_t n) { return key.intkey % n; } @@ -134,7 +134,7 @@ static int cmp_int_key(union HashKey a, union HashKey b) * The Hash table can contain more elements than nelem, but they will be * chained together. */ -static struct Hash *new_hash(int nelem) +static struct Hash *new_hash(size_t nelem) { struct Hash *table = mutt_mem_calloc(1, sizeof(struct Hash)); if (nelem == 0) @@ -274,7 +274,7 @@ static void union_hash_delete(struct Hash *table, union HashKey key, const void * @param flags Flags, e.g. #MUTT_HASH_STRCASECMP * @retval ptr New Hash table */ -struct Hash *mutt_hash_create(int nelem, int flags) +struct Hash *mutt_hash_create(size_t nelem, int flags) { struct Hash *table = new_hash(nelem); if (flags & MUTT_HASH_STRCASECMP) @@ -300,7 +300,7 @@ struct Hash *mutt_hash_create(int nelem, int flags) * @param flags Flags, e.g. #MUTT_HASH_ALLOW_DUPS * @retval ptr New Hash table */ -struct Hash *mutt_hash_int_create(int nelem, int flags) +struct Hash *mutt_hash_int_create(size_t nelem, int flags) { struct Hash *table = new_hash(nelem); table->gen_hash = gen_int_hash; @@ -463,7 +463,7 @@ void mutt_hash_destroy(struct Hash **ptr) return; pptr = *ptr; - for (int i = 0; i < pptr->nelem; i++) + for (size_t i = 0; i < pptr->nelem; i++) { for (elem = pptr->table[i]; elem;) { diff --git a/mutt/hash.h b/mutt/hash.h index efd0d1e84..980ef2926 100644 --- a/mutt/hash.h +++ b/mutt/hash.h @@ -53,11 +53,11 @@ typedef void (*hash_destructor)(int type, void *obj, intptr_t data); */ struct Hash { - int nelem; + size_t nelem; bool strdup_keys : 1; /**< if set, the key->strkey is strdup'ed */ bool allow_dups : 1; /**< if set, duplicate keys are allowed */ struct HashElem **table; - unsigned int (*gen_hash)(union HashKey, unsigned int); + size_t (*gen_hash)(union HashKey, size_t); int (*cmp_key)(union HashKey, union HashKey); hash_destructor destroy; intptr_t dest_data; @@ -68,7 +68,7 @@ struct Hash #define MUTT_HASH_STRDUP_KEYS (1 << 1) /**< make a copy of the keys */ #define MUTT_HASH_ALLOW_DUPS (1 << 2) /**< allow duplicate keys to be inserted */ -struct Hash * mutt_hash_create(int nelem, int flags); +struct Hash * mutt_hash_create(size_t nelem, int flags); void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data); void mutt_hash_destroy(struct Hash **ptr); struct HashElem *mutt_hash_find_bucket(const struct Hash *table, const char *strkey); @@ -77,7 +77,7 @@ struct HashElem *mutt_hash_find_elem(const struct Hash *table, const char *strke struct HashElem *mutt_hash_insert(struct Hash *table, const char *strkey, void *data); void mutt_hash_set_destructor(struct Hash *table, hash_destructor fn, intptr_t fn_data); struct HashElem *mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data); -struct Hash * mutt_hash_int_create(int nelem, int flags); +struct Hash * mutt_hash_int_create(size_t nelem, int flags); void mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *data); void * mutt_hash_int_find(const struct Hash *table, unsigned int intkey); struct HashElem *mutt_hash_int_insert(struct Hash *table, unsigned int intkey, void *data); @@ -87,7 +87,7 @@ struct HashElem *mutt_hash_int_insert(struct Hash *table, unsigned int intkey, v */ struct HashWalkState { - int index; + size_t index; struct HashElem *last; }; -- 2.40.0