You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by "Ian Holsman (x8608)" <ia...@cnet.com> on 2001/07/18 00:47:09 UTC

[Patch/Contrib] apr_hash_overlay (#2)

Ok..
the revised patch.(and test prog)

Index: include/apr_hash.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_hash.h,v
retrieving revision 1.25
diff -u -b -r1.25 apr_hash.h
--- include/apr_hash.h  2001/05/16 05:30:51 1.25
+++ include/apr_hash.h  2001/07/17 22:39:15
@@ -181,6 +181,18 @@
   */
  APR_DECLARE(int) apr_hash_count(apr_hash_t *ht);

+/**
+ * Merge two hash tables into one new hash table. The values of the 
'base' tabl
e
+ * override the values of the overlay if both have the same key.
+ * @param p The pool to use for the new hash table
+ * @param overlay The first table to put in the new hash table
+ * @param base The table to add at the end of the new hash table
+ * @return A new hash table containing all of the data from the two 
passed in
+ * @deffunc apr_hash_t *apr_hash_overlay(apr_pool_t *p, const 
apr_table_t *over
+lay, const apr_table_t *base);
+ */
+APR_DECLARE(apr_hash_t *) apr_hash_overlay(apr_pool_t *p,
+                       const apr_hash_t *overlay, const apr_hash_t *base);

  #ifdef __cplusplus
  }
Index: tables/apr_hash.c
===================================================================
RCS file: /home/cvspublic/apr/tables/apr_hash.c,v
retrieving revision 1.19
diff -u -b -r1.19 apr_hash.c
--- tables/apr_hash.c 2001/05/16 05:30:52 1.19
+++ tables/apr_hash.c 2001/07/17 22:39:18
@@ -325,3 +325,54 @@
  {
      return ht->count;
  }
+
+APR_DECLARE(apr_hash_t*) apr_hash_overlay(apr_pool_t*p, const 
apr_hash_t *overlay, const apr_hash_t*base)
+{
+    apr_hash_t *res;
+    apr_hash_index_t *hi;
+    apr_hash_entry_t *new_vals;
+    int i,j;
+
+#ifdef POOL_DEBUG
+    /* we don't copy keys and values, so it's necessary that
+     * overlay->a.pool and base->a.pool have a life span at least
+     * as long as p
+     */
+    if (!apr_pool_is_ancestor(overlay->a.pool, p)) {
+      fprintf(stderr,    "apr_hash_overlay: overlay's pool is not an 
ancestor of p\n");
+      abort();
+    }
+    if (!apr_pool_is_ancestor(base->a.pool, p)) {
+      fprintf(stderr,    "apr_hash_overlay: base's pool is not an 
ancestor of p\n");
+      abort();
+    }
+#endif
+
+
+    res = apr_palloc(p, sizeof(apr_hash_t));
+    res->pool = p;
+    res->count=base->count;
+    res->max=  (overlay->max > base->max)? overlay->max: base->max;
+    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(base); hi; hi = apr_hash_next(hi)) {
+        i = hi->this->hash & res->max;
+
+        new_vals[j].klen = hi->this->klen;
+        new_vals[j].key = hi->this->key;
+        new_vals[j].val = hi->this->val;
+        new_vals[j].hash = hi->this->hash;
+        new_vals[j].next = res->array[i];
+        res->array[i] = &new_vals[j];
+        j++;
+    }
+    /* 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(overlay); hi; hi = apr_hash_next(hi)) {
+        apr_hash_set(res,hi->this->key,hi->this->klen, hi->this->val);
+    }
+    return res;
+}

Index: test/Makefile.in
===================================================================
RCS file: /home/cvspublic/apr/test/Makefile.in,v
retrieving revision 1.59
diff -u -b -r1.59 Makefile.in
--- test/Makefile.in  2001/07/07 13:03:46 1.59
+++ test/Makefile.in  2001/07/17 22:39:18
@@ -24,6 +24,7 @@
          testmd5@EXEEXT@ \
          testpoll@EXEEXT@ \
          testmem@EXEEXT@ \
+        testhash@EXEEXT@ \
   occhild@EXEEXT@ \
          teststr@EXEEXT@

@@ -122,6 +123,9 @@

  testmem@EXEEXT@: testmem.lo $(LOCAL_LIBS)
   $(LINK) testmem.lo $(LOCAL_LIBS) $(ALL_LIBS)
+
+testhash@EXEEXT@: testhash.lo $(LOCAL_LIBS)
+ $(LINK) testhash.lo $(LOCAL_LIBS) $(ALL_LIBS)

  teststr@EXEEXT@: teststr.lo $(LOCAL_LIBS)
   $(LINK) teststr.lo $(LOCAL_LIBS) $(ALL_LIBS)

+
+

Re: [Patch/Contrib] apr_hash_overlay (#2)

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Wed, Jul 18, 2001 at 07:38:27PM -0700, Ian Holsman wrote:
> Cool..
> 
> all we need now is some one with commit access to
> look at it and give it their blessing
> NUDGE NUDGE ...

Committed.  Thanks.

One note that would make my life slightly easier is to make sure your 
code follows the APR coding style.

Also, your mailer wrapped the long lines in the patch.  So, you 
probably want to attach patches in the future.  Maybe do both - 
attach a pristine version and inline a screwed-up version - we can
review the inline version and can patch with the attachment.  I 
dunno.  

Took me a while to apply the patch and then a bit more to cleanup 
the style.  NBD.  =)  I wasn't doing much else tonight...  -- justin


Re: [Patch/Contrib] apr_hash_overlay (#2)

Posted by Ian Holsman <ia...@cnet.com>.
Brian Pane wrote:

> Ian Holsman (x8608) wrote:
>
>> Ok..
>> the revised patch.(and test prog)
>>
>> Index: include/apr_hash.h
>> ===================================================================
>> RCS file: /home/cvspublic/apr/include/apr_hash.h,v
>> retrieving revision 1.25
>> diff -u -b -r1.25 apr_hash.h 
>
>
> [...]
>
> With these latest fixes, the patch looks good
> --Brian
>
Cool..

all we need now is some one with commit access to
look at it and give it their blessing
NUDGE NUDGE ...


..Ian


Re: [Patch/Contrib] apr_hash_overlay (#2)

Posted by Brian Pane <bp...@pacbell.net>.
Ian Holsman (x8608) wrote:

> Ok..
> the revised patch.(and test prog)
>
> Index: include/apr_hash.h
> ===================================================================
> RCS file: /home/cvspublic/apr/include/apr_hash.h,v
> retrieving revision 1.25
> diff -u -b -r1.25 apr_hash.h 

[...]

With these latest fixes, the patch looks good
--Brian