Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 71607 invoked by uid 500); 2 May 2003 11:11:16 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 71539 invoked from network); 2 May 2003 11:11:15 -0000 Message-ID: <3EB25253.1080508@dbaudio.com> Date: Fri, 02 May 2003 13:11:15 +0200 From: Gunter Coelle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030423 X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@apr.apache.org Subject: Re: [PATCH]: alternative implementation apr_hash_first() References: <001201c30eef$40072ad0$5c00000a@GISDATA.ZG> <3EAF885A.3070706@dbaudio.com> <2147483647.1051692008@[10.0.1.8]> In-Reply-To: <2147483647.1051692008@[10.0.1.8]> X-MIMETrack: Itemize by SMTP Server on notesde/Dbaudio(Release 5.0.6a |January 17, 2001) at 05/02/2003 01:11:13 PM, Serialize by Router on notesde/Dbaudio(Release 5.0.6a |January 17, 2001) at 05/02/2003 01:11:16 PM, Serialize complete at 05/02/2003 01:11:16 PM Content-Type: multipart/mixed; boundary="------------070801010406060809040600" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------070801010406060809040600 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; format=flowed Justin Erenkrantz wrote: > --On Wednesday, April 30, 2003 10:24 AM +0200 Gunter Coelle > wrote: > >> You're right, it would also be the better alternative. >> I already did this as a fix in my apps and other hashtable >> implementations are mostly using this technique too. >> But I'm not sure of the apr-'policy'. AFAIK public structs are >> avoided wherever possible in the headers. > > > Yes, they are avoided, but this might be a case where exposure is > warranted. > > Since I'm not exactly clear what was suggested, if you could submit a > patch that does this (and works for you), it'd be appreciated. > -- justin following patch just moves some declaraions from apr_hash.c to apr_hash.h. With this I can add a function (apr_hash_first_hi) in my apps, which takes an address of the iterator as an argument. This function might also go into apr_hash.c. - gunter --------------070801010406060809040600 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="apr.diff" Content-Disposition: inline; filename="apr.diff" Index: apr/include/apr_hash.h =================================================================== RCS file: /home/cvspublic/apr/include/apr_hash.h,v retrieving revision 1.40 diff -u -r1.40 apr_hash.h --- apr/include/apr_hash.h 5 Mar 2003 21:22:26 -0000 1.40 +++ apr/include/apr_hash.h 2 May 2003 11:01:34 -0000 @@ -93,10 +93,26 @@ */ typedef struct apr_hash_t apr_hash_t; +typedef struct apr_hash_entry_t apr_hash_entry_t ; + /** * Abstract type for scanning hash tables. */ typedef struct apr_hash_index_t apr_hash_index_t; + +/* + * 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; + unsigned int index; +}; + /** * Create a hash table. Index: apr/tables/apr_hash.c =================================================================== RCS file: /home/cvspublic/apr/tables/apr_hash.c,v retrieving revision 1.35 diff -u -r1.35 apr_hash.c --- apr/tables/apr_hash.c 13 Jan 2003 18:52:07 -0000 1.35 +++ apr/tables/apr_hash.c 2 May 2003 11:01:34 -0000 @@ -80,7 +80,6 @@ * isn't too bad given that pools have a low allocation overhead. */ -typedef struct apr_hash_entry_t apr_hash_entry_t; struct apr_hash_entry_t { apr_hash_entry_t *next; @@ -90,18 +89,6 @@ const void *val; }; -/* - * 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; - unsigned int index; -}; /* * The size of the array is always a power of two. We use the maximum --------------070801010406060809040600 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="apr_hash_first_hi" Content-Disposition: inline; filename="apr_hash_first_hi" apr_hash_index_t* apr_hash_first_hi (apr_hash_index_t* hi, apr_hash_t *ht) { hi->ht = ht; hi->index = 0; hi->this = NULL; hi->next = NULL; return apr_hash_next(hi); } --------------070801010406060809040600--