From cvs-return-1808-apmail-apr-cvs-archive=apr.apache.org@apr.apache.org Thu Aug 02 00:11:30 2001 Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 30123 invoked by uid 500); 2 Aug 2001 00:11:30 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 30109 invoked from network); 2 Aug 2001 00:11:30 -0000 Date: 2 Aug 2001 00:11:17 -0000 Message-ID: <20010802001117.75268.qmail@icarus.apache.org> From: wrowe@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/tables apr_hash.c X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N wrowe 01/08/01 17:11:17 Modified: tables apr_hash.c Log: Provide every hash a private, internal iterator for internal reconstruction and merging operations. Revision Changes Path 1.23 +21 -17 apr/tables/apr_hash.c Index: apr_hash.c =================================================================== RCS file: /home/cvs/apr/tables/apr_hash.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- apr_hash.c 2001/08/02 00:03:44 1.22 +++ apr_hash.c 2001/08/02 00:11:17 1.23 @@ -91,6 +91,19 @@ }; /* + * Data structure for iterating through a hash table. + * + * We keep a pointer to the next hash entry here to allow the current + * hash entry to be freed or otherwise mangled between calls to + * apr_hash_next(). + */ +struct apr_hash_index_t { + apr_hash_t *ht; + apr_hash_entry_t *this, *next; + int index; +}; + +/* * The size of the array is always a power of two. We use the maximum * index rather than the size so that we can use bitwise-AND for * modular arithmetic. @@ -100,23 +113,11 @@ struct apr_hash_t { apr_pool_t *pool; apr_hash_entry_t **array; + apr_hash_index_t iterator; /* For apr_hash_first(NULL, ...) */ int count, max; }; #define INITIAL_MAX 15 /* tunable == 2^n - 1 */ -/* - * Data structure for iterating through a hash table. - * - * We keep a pointer to the next hash entry here to allow the current - * hash entry to be freed or otherwise mangled between calls to - * apr_hash_next(). - */ -struct apr_hash_index_t { - apr_hash_t *ht; - apr_hash_entry_t *this, *next; - int index; -}; - /* * Hash creation functions. @@ -158,7 +159,10 @@ APR_DECLARE(apr_hash_index_t *) apr_hash_first(apr_pool_t *p, apr_hash_t *ht) { apr_hash_index_t *hi; - hi = apr_palloc(p, sizeof(*hi)); + if (p) + hi = apr_palloc(p, sizeof(*hi)); + else + hi = &ht->iterator; hi->ht = ht; hi->index = 0; hi->this = NULL; @@ -190,7 +194,7 @@ new_max = ht->max * 2 + 1; new_array = alloc_array(ht, new_max); - for (hi = apr_hash_first(ht); hi; hi = apr_hash_next(hi)) { + for (hi = apr_hash_first(NULL, ht); hi; hi = apr_hash_next(hi)) { i = hi->this->hash & new_max; hi->this->next = new_array[i]; new_array[i] = hi->this; @@ -359,7 +363,7 @@ res->array = alloc_array(res, res->max); new_vals = apr_palloc(p, sizeof(apr_hash_entry_t) * res->count); j = 0; - for (hi = apr_hash_first((apr_hash_t*)base); hi; hi = apr_hash_next(hi)) { + for (hi = apr_hash_first(NULL, (apr_hash_t*)base); hi; hi = apr_hash_next(hi)) { i = hi->this->hash & res->max; new_vals[j].klen = hi->this->klen; @@ -374,7 +378,7 @@ /* can't simply copy the stuff over, need to set each one so as to * increment the counts/array properly */ - for (hi = apr_hash_first((apr_hash_t*)overlay); hi; + for (hi = apr_hash_first(NULL, (apr_hash_t*)overlay); hi; hi = apr_hash_next(hi)) { apr_hash_set(res, hi->this->key, hi->this->klen, hi->this->val); }