]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Changes to hash_first, hash_next. The **Current idea has bugs, so now
authorwessels <>
Sun, 24 May 1998 09:41:06 +0000 (09:41 +0000)
committerwessels <>
Sun, 24 May 1998 09:41:06 +0000 (09:41 +0000)
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))

src/access_log.cc
src/cache_diff.cc
src/cbdata.cc
src/client_db.cc
src/fqdncache.cc
src/ipcache.cc
src/net_db.cc
src/protos.h
src/stat.cc
src/structs.h
src/test_cache_digest.cc

index 5d774d992568d44c02c86c972719ee675bbdcf6c..45c00fe1b942f79b9700729e7415ed8c26b96328 100644 (file)
@@ -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);
     }
index 8238eeb37ac32cc1d0682d230e9530ba9224caae..c4a3b96d9556532de240893153df32514d0dc2f2 100644 (file)
@@ -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++;
index cb49ce78716915816e5777f3fbcf896a95f1ebee..02fbe4e0e70c50715e44c4bc3983a3a062fd6258 100644 (file)
@@ -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",
index 8fd7cf7b66affbd5ff9ba89f44caf386d399456f..b0578a7fd146589245db3311708639f70d6a0533 100644 (file)
@@ -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;
index e7ee81e903791839d555aafa8e04866684edadaf..7af4322c8dc69618f1491abd68cf742722e31a8f 100644 (file)
@@ -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;
index d29816dd88a4a2f771539ba05488f07c225cf336..a1d7373650531d28e5f8a8820ed07422ff08b430 100644 (file)
@@ -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)
index 66db2b2b5da52f515415c04fdc8836844f05edd2..c0c0ea5984cb5d8cfc5f81b8f18d495277f0a8d5 100644 (file)
@@ -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 */
index 61b42ac64af70d07366eb14e6d5969221ade5882..6cc254215a3d72be7aadc9f893d926801d5c4422 100644 (file)
@@ -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 *);
index b5ce6a3d66d8477688de3e01181ddb97758b0e19..948678bdac7ec3b03accd2d6b442b4c49e513cdf 100644 (file)
@@ -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)
index de56dfff81f5073d28deafccaa62f3ae7c06656f..3060996a3a211609aceb6573940cc6678f165d3a 100644 (file)
@@ -466,7 +466,7 @@ struct _hash_table {
     HASHHASH *hash;
     unsigned int size;
     unsigned int current_slot;
-    hash_link **Current;
+    hash_link *next;
     int count;
 };
 
index 206c1a10d04f3e1665e668f0e866079334b64f75..1334c6fd072ac08911765d172582d0ba1ff11754 100644 (file)
@@ -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);