From efb5d9001c0f8841bd46f105eb4853c2aa0e0161 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Fri, 4 Oct 2024 11:19:10 +0100 Subject: [PATCH] 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. --- utils/hash.c | 6 +++--- utils/hash.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/hash.c b/utils/hash.c index 2460a48f..a52aa3ec 100644 --- a/utils/hash.c +++ b/utils/hash.c @@ -282,7 +282,7 @@ hash(table, key) HashEntry * HashLookOnly(table, key) 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. */ { @@ -352,7 +352,7 @@ next: HashEntry * HashFind(table, key) 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. */ { @@ -577,7 +577,7 @@ HashStats(table) void HashRemove(table, key) 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. */ { diff --git a/utils/hash.h b/utils/hash.h index 12157478..eafce329 100644 --- a/utils/hash.h +++ b/utils/hash.h @@ -35,7 +35,7 @@ typedef struct h1 struct h1 *h_next; /* Next element, zero for end. */ 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 * size may be longer if necessary to hold * the entire key. @@ -113,9 +113,9 @@ typedef struct h2 extern void HashInit(HashTable *, int, int), HashInitClient(), HashStats(), HashKill(), HashFreeKill(); -extern HashEntry *HashFind(HashTable *, char *); -extern HashEntry *HashLookOnly(HashTable *, char *); -extern void HashRemove(HashTable *, char *); +extern HashEntry *HashFind(HashTable *, const char *); +extern HashEntry *HashLookOnly(HashTable *, const char *); +extern void HashRemove(HashTable *, const char *); extern void HashStartSearch(HashSearch *); extern HashEntry *HashNext(HashTable *, HashSearch *);