]> granicus.if.org Git - neomutt/commitdiff
refactor: unsigned int -> size_t
authorRichard Russon <rich@flatcap.org>
Sun, 6 May 2018 12:16:12 +0000 (13:16 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 6 May 2018 12:16:12 +0000 (13:16 +0100)
mutt/hash.c
mutt/hash.h

index cdfcde0e8b52b52ad82fff5f4327a5f9448c2b76..cccd2b8ad54f5d056773dcadf29f007408ef7791 100644 (file)
@@ -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;)
     {
index efd0d1e84e2b0ad9f8a2dc314c319b70d8e3ed59..980ef29268f172bb5c05972faf74a7449c8b2382 100644 (file)
@@ -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;
 };