From: wessels <> Date: Sun, 24 May 1998 09:41:06 +0000 (+0000) Subject: Changes to hash_first, hash_next. The **Current idea has bugs, so now X-Git-Tag: SQUID_3_0_PRE1~3266 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f6bebacb4b48b211926ad2c62ea17cc10dfdb21;p=thirdparty%2Fsquid.git Changes to hash_first, hash_next. The **Current idea has bugs, so now we keep state with a ->next pointer. This simplifies the hash.c code somewhat, but requires an interface change so that hash_first() only initializes ->next and does not return a value. Now we always use while (foo = hash_next(bar)) --- diff --git a/src/access_log.cc b/src/access_log.cc index 5d774d9925..45c00fe1b9 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -1,7 +1,7 @@ /* - * $Id: access_log.cc,v 1.28 1998/04/09 21:32:08 wessels Exp $ + * $Id: access_log.cc,v 1.29 1998/05/24 03:41:06 wessels Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -401,7 +401,8 @@ fvdbDumpTable(StoreEntry * e, hash_table * hash) fvdb_entry *fv; if (hash == NULL) return; - for (h = hash_first(hash); h != NULL; h = hash_next(hash)) { + hash_first(hash); + while (h = hash_next(hash)) { fv = (fvdb_entry *) h; storeAppendPrintf(e, "%9d %s\n", fv->n, fv->key); } diff --git a/src/cache_diff.cc b/src/cache_diff.cc index 8238eeb37a..c4a3b96d95 100644 --- a/src/cache_diff.cc +++ b/src/cache_diff.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_diff.cc,v 1.7 1998/03/31 05:37:35 wessels Exp $ + * $Id: cache_diff.cc,v 1.8 1998/05/24 03:41:06 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -108,7 +108,8 @@ cacheIndexDestroy(CacheIndex * idx) hash_link *hashr = NULL; if (idx) { /* destroy hash list contents */ - for (hashr = hash_first(idx->hash); hashr; hashr = hash_next(idx->hash)) { + hash_first(idx->hash); + while (hashr = hash_next(idx->hash)) { hash_remove_link(idx->hash, hashr); cacheEntryDestroy((CacheEntry *) hashr); } @@ -219,7 +220,8 @@ cacheIndexCmp(CacheIndex * idx1, CacheIndex * idx2) large_idx = idx1; } /* find shared_count */ - for (hashr = hash_first(small_idx->hash); hashr; hashr = hash_next(small_idx->hash)) { + hash_first(small_idx->hash); + for (hashr = hash_next(small_idx->hash)) { hashed_count++; if (hash_lookup(large_idx->hash, hashr->key)) shared_count++; diff --git a/src/cbdata.cc b/src/cbdata.cc index cb49ce7871..02fbe4e0e7 100644 --- a/src/cbdata.cc +++ b/src/cbdata.cc @@ -1,6 +1,6 @@ /* - * $Id: cbdata.cc,v 1.20 1998/05/12 20:16:32 wessels Exp $ + * $Id: cbdata.cc,v 1.21 1998/05/24 03:41:07 wessels Exp $ * * DEBUG: section 45 Callback Data Registry * AUTHOR: Duane Wessels @@ -211,7 +211,8 @@ cbdataDump(StoreEntry * sentry) hash_link *hptr; cbdata *c; storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount); - for (hptr = hash_first(htable); hptr; hptr = hash_next(htable)) { + hash_first(htable); + while ((hptr = hash_next(htable))) { c = (cbdata *) hptr; #if CBDATA_DEBUG storeAppendPrintf(sentry, "%20p %10s %d locks %s:%d\n", diff --git a/src/client_db.cc b/src/client_db.cc index 8fd7cf7b66..b0578a7fd1 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -1,6 +1,6 @@ /* - * $Id: client_db.cc,v 1.31 1998/04/24 05:44:08 wessels Exp $ + * $Id: client_db.cc,v 1.32 1998/05/24 03:41:08 wessels Exp $ * * DEBUG: section 0 Client Database * AUTHOR: Duane Wessels @@ -138,8 +138,8 @@ clientdbDump(StoreEntry * sentry) int http_total = 0; int http_hits = 0; storeAppendPrintf(sentry, "Cache Clients:\n"); - c = (ClientInfo *) hash_first(client_table); - while (c) { + hash_first(client_table); + while ((c = (ClientInfo *) hash_next(client_table))) { storeAppendPrintf(sentry, "Address: %s\n", c->key); storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(c->addr)); storeAppendPrintf(sentry, " ICP Requests %d\n", @@ -171,7 +171,6 @@ clientdbDump(StoreEntry * sentry) percent(c->Http.result_hist[l], c->Http.n_requests)); } storeAppendPrintf(sentry, "\n"); - c = (ClientInfo *) hash_next(client_table); } storeAppendPrintf(sentry, "TOTALS\n"); storeAppendPrintf(sentry, "ICP : %d Queries, %d Hits (%3d%%)\n", @@ -201,9 +200,10 @@ meshCtblGetRowFn(oid * New, oid * Oid) ClientInfo *c = NULL; static char key[15]; - if (!Oid[0] && !Oid[1] && !Oid[2] && !Oid[3]) - c = (ClientInfo *) hash_first(client_table); - else { + if (!Oid[0] && !Oid[1] && !Oid[2] && !Oid[3]) { + hash_first(client_table); + c = (ClientInfo *) hash_next(client_table); + } else { snprintf(key, 15, "%d.%d.%d.%d", Oid[0], Oid[1], Oid[2], Oid[3]); c = (ClientInfo *) hash_lookup(client_table, key); if (NULL != c) @@ -224,9 +224,6 @@ snmp_meshCtblFn(variable_list * Var, snint * ErrP) ClientInfo *c = NULL; int aggr = 0; log_type l; -#if 0 - int cnt; -#endif Answer = snmp_var_new(Var->name, Var->name_length); *ErrP = SNMP_ERR_NOERROR; @@ -235,13 +232,6 @@ snmp_meshCtblFn(variable_list * Var, snint * ErrP) Var->name[13], Var->name[14]); debug(49, 5) ("snmp_meshCtblFn: [%s] requested!\n", key); c = (ClientInfo *) hash_lookup(client_table, key); -#if 0 - c = (ClientInfo *) hash_first(client_table); - cnt = Var->name[11]; - debug(49, 5) ("snmp_meshCtblFn: we want .x.%d\n", Var->name[10]); - while (--cnt) - if (!(c = (ClientInfo *) hash_next(client_table))); -#endif if (c == NULL) { debug(49, 5) ("snmp_meshCtblFn: not found.\n"); *ErrP = SNMP_ERR_NOSUCHNAME; diff --git a/src/fqdncache.cc b/src/fqdncache.cc index e7ee81e903..7af4322c8d 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -1,7 +1,7 @@ /* - * $Id: fqdncache.cc,v 1.103 1998/05/22 23:44:05 wessels Exp $ + * $Id: fqdncache.cc,v 1.104 1998/05/24 03:41:08 wessels Exp $ * * DEBUG: section 35 FQDN Cache * AUTHOR: Harvest Derived @@ -681,7 +681,6 @@ void fqdnStats(StoreEntry * sentry) { fqdncache_entry *f = NULL; - fqdncache_entry *next = NULL; int k; int ttl; if (fqdn_table == NULL) @@ -703,9 +702,8 @@ fqdnStats(StoreEntry * sentry) FqdncacheStats.ghba_calls); storeAppendPrintf(sentry, "FQDN Cache Contents:\n\n"); - next = (fqdncache_entry *) hash_first(fqdn_table); - while ((f = next) != NULL) { - next = (fqdncache_entry *) hash_next(fqdn_table); + hash_first(fqdn_table); + while ((f = (fqdncache_entry *) hash_next(fqdn_table))) { if (f->status == FQDN_PENDING || f->status == FQDN_DISPATCHED) ttl = 0; else @@ -831,13 +829,11 @@ void fqdncache_restart(void) { fqdncache_entry *this; - fqdncache_entry *next; if (fqdn_table == 0) fatal_dump("fqdncache_restart: fqdn_table == 0\n"); while (fqdncacheDequeue()); - next = (fqdncache_entry *) hash_first(fqdn_table); - while ((this = next) != NULL) { - next = (fqdncache_entry *) hash_next(fqdn_table); + hash_first(fqdn_table); + while ((this = (fqdncache_entry *) hash_next(fqdn_table))) { if (this->status == FQDN_CACHED) continue; if (this->status == FQDN_NEGATIVE_CACHED) @@ -863,12 +859,9 @@ fqdn_getMax() int i = 0; fqdncache_entry *fq = NULL; - fq = (fqdncache_entry *) hash_first(fqdn_table); - if (fq != NULL) { - i = 1; - while ((fq = (fqdncache_entry *) hash_next(fqdn_table))) - i++; - } + hash_first(fqdn_table); + while ((fq = (fqdncache_entry *) hash_next(fqdn_table))) + i++; return i; } @@ -884,9 +877,12 @@ snmp_fqdncacheFn(variable_list * Var, snint * ErrP) cnt = Var->name[12]; - fq = (fqdncache_entry *) hash_first(fqdn_table); - while (fq && --cnt) + hash_first(fqdn_table); + while (cnt--) { fq = (fqdncache_entry *) hash_next(fqdn_table); + if (NULL == fq) + break; + } if (fq == NULL || cnt != 0) { *ErrP = SNMP_ERR_NOSUCHNAME; return NULL; diff --git a/src/ipcache.cc b/src/ipcache.cc index d29816dd88..a1d7373650 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,6 +1,6 @@ /* - * $Id: ipcache.cc,v 1.187 1998/05/15 15:16:23 wessels Exp $ + * $Id: ipcache.cc,v 1.188 1998/05/24 03:41:10 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -1003,12 +1003,10 @@ void ipcache_restart(void) { ipcache_entry *this; - ipcache_entry *next; assert(ip_table != NULL); while (ipcacheDequeue()); - next = (ipcache_entry *) hash_first(ip_table); - while ((this = next) != NULL) { - next = (ipcache_entry *) hash_next(ip_table); + hash_first(ip_table); + while ((this = (ipcache_entry *) hash_next(ip_table))) { if (this->status == IP_CACHED) continue; if (this->status == IP_NEGATIVE_CACHED) diff --git a/src/net_db.cc b/src/net_db.cc index 66db2b2b5d..c0c0ea5984 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -1,6 +1,6 @@ /* - * $Id: net_db.cc,v 1.106 1998/05/22 23:44:19 wessels Exp $ + * $Id: net_db.cc,v 1.107 1998/05/24 03:41:11 wessels Exp $ * * DEBUG: section 37 Network Measurement Database * AUTHOR: Duane Wessels @@ -174,12 +174,11 @@ netdbPurgeLRU(void) int list_count = 0; int removed = 0; list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *)); - n = (netdbEntry *) hash_first(addr_table); - while (n != NULL) { + hash_first(addr_table); + while ((n = (netdbEntry *) hash_next(addr_table))) { assert(list_count < memInUse(MEM_NETDBENTRY)); *(list + list_count) = n; list_count++; - n = (netdbEntry *) hash_next(addr_table); } qsort((char *) list, list_count, @@ -365,7 +364,6 @@ netdbSaveState(void *foo) LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN); FILE *fp; netdbEntry *n; - netdbEntry *next; net_db_name *x; struct timeval start = current_time; int count = 0; @@ -375,9 +373,8 @@ netdbSaveState(void *foo) debug(50, 1) ("netdbSaveState: %s: %s\n", path, xstrerror()); return; } - next = (netdbEntry *) hash_first(addr_table); - while ((n = next) != NULL) { - next = (netdbEntry *) hash_next(addr_table); + hash_first(addr_table); + while ((n = (netdbEntry *) hash_next(addr_table))) { if (n->pings_recv == 0) continue; fprintf(fp, "%s %d %d %10.5f %10.5f %d %d", @@ -721,11 +718,9 @@ netdbDump(StoreEntry * sentry) "Hostnames"); list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *)); i = 0; - n = (netdbEntry *) hash_first(addr_table); - while (n != NULL) { + hash_first(addr_table); + while ((n = (netdbEntry *) hash_next(addr_table))) *(list + i++) = n; - n = (netdbEntry *) hash_next(addr_table); - } if (i != memInUse(MEM_NETDBENTRY)) debug(37, 0) ("WARNING: netdb_addrs count off, found %d, expected %d\n", i, memInUse(MEM_NETDBENTRY)); @@ -974,7 +969,6 @@ netdbBinaryExchange(StoreEntry * s) http_reply *reply = s->mem_obj->reply; #if USE_ICMP netdbEntry *n; - netdbEntry *next; int i; int j; int rec_sz; @@ -991,10 +985,8 @@ netdbBinaryExchange(StoreEntry * s) rec_sz += 1 + sizeof(int); buf = memAllocate(MEM_4K_BUF); i = 0; - next = (netdbEntry *) hash_first(addr_table); - while (next != NULL) { - n = next; - next = (netdbEntry *) hash_next(addr_table); + hash_first(addr_table); + while ((n = (netdbEntry *) hash_next(addr_table))) { if (0.0 == n->rtt) continue; if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */ diff --git a/src/protos.h b/src/protos.h index 61b42ac64a..6cc254215a 100644 --- a/src/protos.h +++ b/src/protos.h @@ -216,7 +216,7 @@ extern void hash_join(hash_table *, hash_link *); extern void hash_remove_link(hash_table *, hash_link *); extern int hashPrime(int n); extern void *hash_lookup(hash_table *, const void *); -extern void *hash_first(hash_table *); +extern void hash_first(hash_table *); extern void *hash_next(hash_table *); extern hash_link *hash_get_bucket(hash_table *, unsigned int); extern void hashFreeMemory(hash_table *); diff --git a/src/stat.cc b/src/stat.cc index b5ce6a3d66..948678bdac 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.253 1998/05/22 23:44:26 wessels Exp $ + * $Id: stat.cc,v 1.254 1998/05/24 03:41:13 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -359,11 +359,9 @@ static void statObjects(StoreEntry * sentry, int vm_or_not) { StoreEntry *entry = NULL; - StoreEntry *next = NULL; int N = 0; - next = (StoreEntry *) hash_first(store_table); - while ((entry = next) != NULL) { - next = (StoreEntry *) hash_next(store_table); + hash_first(store_table); + while ((entry = (StoreEntry *) hash_next(store_table))) { if (vm_or_not && entry->mem_obj == NULL) continue; if ((++N & 0xFF) == 0) { @@ -390,10 +388,8 @@ static void statOpenfdObj(StoreEntry * sentry) { StoreEntry *entry = NULL; - StoreEntry *next = NULL; - next = (StoreEntry *) hash_first(store_table); - while ((entry = next) != NULL) { - next = (StoreEntry *) hash_next(store_table); + hash_first(store_table); + while ((entry = (StoreEntry *) hash_next(store_table))) { if (entry->mem_obj == NULL) continue; if (entry->mem_obj->swapout.fd < 0) diff --git a/src/structs.h b/src/structs.h index de56dfff81..3060996a3a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -466,7 +466,7 @@ struct _hash_table { HASHHASH *hash; unsigned int size; unsigned int current_slot; - hash_link **Current; + hash_link *next; int count; }; diff --git a/src/test_cache_digest.cc b/src/test_cache_digest.cc index 206c1a10d0..1334c6fd07 100644 --- a/src/test_cache_digest.cc +++ b/src/test_cache_digest.cc @@ -1,6 +1,6 @@ /* - * $Id: test_cache_digest.cc,v 1.19 1998/04/24 07:09:49 wessels Exp $ + * $Id: test_cache_digest.cc,v 1.20 1998/05/24 03:41:15 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -248,7 +248,8 @@ cacheDestroy(Cache * cache) assert(cache); hash = cache->hash; /* destroy hash table contents */ - for (e = hash_first(hash); e; e = hash_next(hash)) { + hash_first(hash); + while (e = hash_next(hash)) { hash_remove_link(hash, (hash_link *) e); cacheEntryDestroy(e); } @@ -276,7 +277,8 @@ cacheResetDigest(Cache * cache) if (!cache->count) return; gettimeofday(&t_start, NULL); - for (e = hash_first(hash); e; e = hash_next(hash)) { + hash_first(hash); + while (e = hash_next(hash)) { cacheDigestAdd(cache->digest, e->key); } gettimeofday(&t_end, NULL);