util/hash.[ch]: const hash 'key' for API and internal type

This is mainly to modify the function signature to accept const
data pointers to keys.

Patch required to ease use of const by API consumers.
This commit is contained in:
Darryl L. Miles 2024-10-04 11:19:10 +01:00 committed by Tim Edwards
parent 91da638579
commit efb5d9001c
2 changed files with 7 additions and 7 deletions

View File

@ -282,7 +282,7 @@ hash(table, key)
HashEntry * HashEntry *
HashLookOnly(table, key) HashLookOnly(table, key)
HashTable *table; /* Hash table to search. */ HashTable *table; /* Hash table to search. */
char *key; /* Interpreted according to table->ht_ptrKeys const char *key; /* Interpreted according to table->ht_ptrKeys
* as described in HashInit()'s comments. * as described in HashInit()'s comments.
*/ */
{ {
@ -352,7 +352,7 @@ next:
HashEntry * HashEntry *
HashFind(table, key) HashFind(table, key)
HashTable *table; /* Hash table to search. */ HashTable *table; /* Hash table to search. */
char *key; /* Interpreted according to table->ht_ptrKeys const char *key; /* Interpreted according to table->ht_ptrKeys
* as described in HashInit()'s comments. * as described in HashInit()'s comments.
*/ */
{ {
@ -577,7 +577,7 @@ HashStats(table)
void void
HashRemove(table, key) HashRemove(table, key)
HashTable *table; /* Hash table to search. */ HashTable *table; /* Hash table to search. */
char *key; /* Interpreted according to table->ht_ptrKeys const char *key; /* Interpreted according to table->ht_ptrKeys
* as described in HashInit()'s comments. * as described in HashInit()'s comments.
*/ */
{ {

View File

@ -35,7 +35,7 @@ typedef struct h1
struct h1 *h_next; /* Next element, zero for end. */ struct h1 *h_next; /* Next element, zero for end. */
union union
{ {
char *h_ptr; /* One-word key value to identify entry. */ const char *h_ptr; /* One-word key value to identify entry. */
unsigned h_words[1]; /* N-word key value. Note: the actual unsigned h_words[1]; /* N-word key value. Note: the actual
* size may be longer if necessary to hold * size may be longer if necessary to hold
* the entire key. * the entire key.
@ -113,9 +113,9 @@ typedef struct h2
extern void HashInit(HashTable *, int, int), HashInitClient(), HashStats(), HashKill(), extern void HashInit(HashTable *, int, int), HashInitClient(), HashStats(), HashKill(),
HashFreeKill(); HashFreeKill();
extern HashEntry *HashFind(HashTable *, char *); extern HashEntry *HashFind(HashTable *, const char *);
extern HashEntry *HashLookOnly(HashTable *, char *); extern HashEntry *HashLookOnly(HashTable *, const char *);
extern void HashRemove(HashTable *, char *); extern void HashRemove(HashTable *, const char *);
extern void HashStartSearch(HashSearch *); extern void HashStartSearch(HashSearch *);
extern HashEntry *HashNext(HashTable *, HashSearch *); extern HashEntry *HashNext(HashTable *, HashSearch *);