[PATCH 2/4] Rename hash nelem to bucket_count.
"Kevin J. McCarthy" <[email protected]> Mon, 20 Jul 2026 13:00:38 +0800
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <[email protected]> |
The nelem attribute name is a bit vague.
When I add a counter for the "total entries" in the next commit, it
will be easy to get confused. So rename it to bucket_count, which I
hope is clear.
---
hash.c | 30 +++++++++++++++---------------
hash.h | 2 +-
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/hash.c b/hash.c
index e48b0777..be51a38f 100644
--- a/hash.c
+++ b/hash.c
@@ -77,19 +77,19 @@ static int cmp_int_key(union hash_key a, union hash_key b)
return 1;
}
-static HASH *new_hash(int nelem)
+static HASH *new_hash(int bucket_count)
{
HASH *table = safe_calloc(1, sizeof(HASH));
- if (nelem == 0)
- nelem = 2;
- table->nelem = nelem;
- table->table = safe_calloc(nelem, sizeof(struct hash_elem *));
+ if (bucket_count == 0)
+ bucket_count = 2;
+ table->bucket_count = bucket_count;
+ table->table = safe_calloc(bucket_count, sizeof(struct hash_elem *));
return table;
}
-HASH *hash_create(int nelem, int flags)
+HASH *hash_create(int bucket_count, int flags)
{
- HASH *table = new_hash(nelem);
+ HASH *table = new_hash(bucket_count);
if (flags & MUTT_HASH_STRCASECMP)
{
table->gen_hash = gen_case_string_hash;
@@ -107,9 +107,9 @@ HASH *hash_create(int nelem, int flags)
return table;
}
-HASH *int_hash_create(int nelem, int flags)
+HASH *int_hash_create(int bucket_count, int flags)
{
- HASH *table = new_hash(nelem);
+ HASH *table = new_hash(bucket_count);
table->gen_hash = gen_int_hash;
table->cmp_key = cmp_int_key;
if (flags & MUTT_HASH_ALLOW_DUPS)
@@ -128,7 +128,7 @@ static int union_hash_insert(HASH * table, union hash_key key, void *data)
unsigned int h;
ptr = (struct hash_elem *) safe_malloc(sizeof(struct hash_elem));
- h = table->gen_hash(key, table->nelem);
+ h = table->gen_hash(key, table->bucket_count);
ptr->key = key;
ptr->data = data;
@@ -184,7 +184,7 @@ static struct hash_elem *union_hash_find_elem(const HASH *table, union hash_key
if (!table)
return NULL;
- hash = table->gen_hash(key, table->nelem);
+ hash = table->gen_hash(key, table->bucket_count);
ptr = table->table[hash];
for (; ptr; ptr = ptr->next)
{
@@ -233,7 +233,7 @@ struct hash_elem *hash_find_bucket(const HASH *table, const char *strkey)
return NULL;
key.strkey = strkey;
- hash = table->gen_hash(key, table->nelem);
+ hash = table->gen_hash(key, table->bucket_count);
return table->table[hash];
}
@@ -246,7 +246,7 @@ static void union_hash_delete(HASH *table, union hash_key key, const void *data,
if (!table)
return;
- hash = table->gen_hash(key, table->nelem);
+ hash = table->gen_hash(key, table->bucket_count);
ptr = table->table[hash];
last = &table->table[hash];
@@ -301,7 +301,7 @@ void hash_destroy(HASH **ptr, void (*destroy)(void *))
return;
pptr = *ptr;
- for (i = 0 ; i < pptr->nelem; i++)
+ for (i = 0 ; i < pptr->bucket_count; i++)
{
for (elem = pptr->table[i]; elem; )
{
@@ -329,7 +329,7 @@ struct hash_elem *hash_walk(const HASH *table, struct hash_walk_state *state)
if (state->last)
state->index++;
- while (state->index < table->nelem)
+ while (state->index < table->bucket_count)
{
if (table->table[state->index])
{
diff --git a/hash.h b/hash.h
index e74f447f..fe3264af 100644
--- a/hash.h
+++ b/hash.h
@@ -34,7 +34,7 @@ struct hash_elem
typedef struct
{
- int nelem;
+ int bucket_count; /* size of hash->table array */
unsigned int strdup_keys : 1; /* if set, the key->strkey is strdup'ed */
unsigned int allow_dups : 1; /* if set, duplicate keys are allowed */
struct hash_elem **table;
--
2.55.0