From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 002153857C47 for ; Mon, 17 Aug 2020 14:06:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 002153857C47 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 200DAAB71; Mon, 17 Aug 2020 14:06:46 +0000 (UTC) Subject: Re: [PATCH] libibery/hashtab: add new functions From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: gcc-patches@gcc.gnu.org References: <8f299d81-414f-a150-b226-1b977d3efe0e@suse.cz> Cc: Ian Lance Taylor , Alan Modra Message-ID: <3a3bf5d4-e125-a6a3-42d4-07e85487973b@suse.cz> Date: Mon, 17 Aug 2020 16:06:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <8f299d81-414f-a150-b226-1b977d3efe0e@suse.cz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Aug 2020 14:06:23 -0000 Adding libiberty maintainer to CC. On 8/17/20 4:03 PM, Martin Liška wrote: > Hey. > > I'm working on bintuils where I would like to port a hash table > implementation in gas/hash.[ch] to libiberty one. > > But it would be handy for me to add 2 new functions. > > Thoughts? > Thanks, > Martin > > include/ChangeLog: > >     * hashtab.h (htab_insert): New function. >     (htab_print_statistics): Likewise. > > libiberty/ChangeLog: > >     * hashtab.c (htab_insert): New function. >     (htab_print_statistics): Likewise. > --- >  include/hashtab.h   |  6 ++++++ >  libiberty/hashtab.c | 23 +++++++++++++++++++++++ >  2 files changed, 29 insertions(+) > > diff --git a/include/hashtab.h b/include/hashtab.h > index 6cca342b989..bcaee909bcf 100644 > --- a/include/hashtab.h > +++ b/include/hashtab.h > @@ -37,6 +37,7 @@ extern "C" { >  #endif /* __cplusplus */ > >  #include "ansidecl.h" > +#include > >  /* The type for a hash code.  */ >  typedef unsigned int hashval_t; > @@ -172,6 +173,7 @@ extern void **    htab_find_slot (htab_t, const void *, enum insert_option); >  extern void *    htab_find_with_hash (htab_t, const void *, hashval_t); >  extern void **    htab_find_slot_with_hash (htab_t, const void *, >                        hashval_t, enum insert_option); > +extern void    htab_insert (htab_t, void *); >  extern void    htab_clear_slot    (htab_t, void **); >  extern void    htab_remove_elt    (htab_t, const void *); >  extern void    htab_remove_elt_with_hash (htab_t, const void *, hashval_t); > @@ -183,6 +185,10 @@ extern size_t    htab_size (htab_t); >  extern size_t    htab_elements (htab_t); >  extern double    htab_collisions    (htab_t); > > +extern void    htab_print_statistics (FILE *f, htab_t table, > +                       const char *name, > +                       const char *prefix); > + >  /* A hash function for pointers.  */ >  extern htab_hash htab_hash_pointer; > > diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c > index 225e9e540a7..fb3152ec9c6 100644 > --- a/libiberty/hashtab.c > +++ b/libiberty/hashtab.c > @@ -704,6 +704,15 @@ htab_find_slot (htab_t htab, const PTR element, enum insert_option insert) >                     insert); >  } > > +/* Insert ELEMENT into HTAB.  If the element exists, it is overwritten.  */ > + > +void > +htab_insert (htab_t htab, PTR element) > +{ > +  void **slot = htab_find_slot (htab, element, INSERT); > +  *slot = element; > +} > + >  /* This function deletes an element with the given value from hash >     table (the hash is computed from the element).  If there is no matching >     element in the hash table, this function does nothing.  */ > @@ -803,6 +812,20 @@ htab_collisions (htab_t htab) >    return (double) htab->collisions / (double) htab->searches; >  } > > +/* Print statistics about a hash table.  */ > + > +void > +htab_print_statistics (FILE *f, htab_t table, const char *name, > +               const char *prefix) > +{ > +  fprintf (f, "%s hash statistics:\n", name); > +  fprintf (f, "%s%u searches\n", prefix, table->searches); > +  fprintf (f, "%s%lu elements\n", prefix, htab_elements (table)); > +  fprintf (f, "%s%lu table size\n", prefix, htab_size (table)); > +  fprintf (f, "%s%.2f collisions per search\n", > +       prefix, htab_collisions (table)); > +} > + >  /* Hash P as a null-terminated string. > >     Copied from gcc/hashtable.c.  Zack had the following to say with respect