From abebb03c3af215d7542f5e6b71d78823b15220d5 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Sat, 15 Aug 2020 19:46:33 +0200 Subject: gas/hash.c: add new functions The first of a patch series deleting the gas/hash.c hash table implementation and instead using libiberty/hashtab.c hash tables in gas. * as.h: Include hashtab.h. * hash.c (htab_insert): New. (htab_print_statistics): Likewise. * hash.h (htab_insert): Likewise. (htab_print_statistics): Likewise. --- gas/hash.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gas/hash.c') diff --git a/gas/hash.c b/gas/hash.c index c484588..e6b4ef5 100644 --- a/gas/hash.c +++ b/gas/hash.c @@ -407,6 +407,30 @@ hash_print_statistics (FILE *f ATTRIBUTE_UNUSED, fprintf (f, "\t%lu empty slots\n", empty); #endif } + +/* 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); + if (slot != NULL && htab->del_f) + (*htab->del_f) (*slot); + + *slot = element; +} + +/* Print statistics about a hash table. */ + +void +htab_print_statistics (FILE *f, const char *name, htab_t table) +{ + fprintf (f, "%s hash statistics:\n", name); + fprintf (f, "\t%u searches\n", table->searches); + fprintf (f, "\t%u collisions\n", table->collisions); + fprintf (f, "\t%lu elements\n", (unsigned long) htab_elements (table)); + fprintf (f, "\t%lu table size\n", (unsigned long) htab_size (table)); +} #ifdef TEST -- cgit v1.1