Automatic date update in version.in
[binutils-gdb.git] / gas / hash.c
blob5ddd88ea0b23a93b4ce0d6cfd89fe4d53f65c7ff
1 /* hash.c -- gas hash table code
2 Copyright (C) 1987-2022 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #include "as.h"
23 /* Insert ELEMENT into HTAB. If REPLACE is non-zero existing elements
24 are overwritten. If ELEMENT already exists, a pointer to the slot
25 is returned. Otherwise NULL is returned. */
27 void **
28 htab_insert (htab_t htab, void *element, int replace)
30 void **slot = htab_find_slot (htab, element, INSERT);
31 if (*slot != NULL)
33 if (replace)
35 if (htab->del_f)
36 (*htab->del_f) (*slot);
37 *slot = element;
39 return slot;
41 *slot = element;
42 return NULL;
45 /* Print statistics about a hash table. */
47 void
48 htab_print_statistics (FILE *f, const char *name, htab_t table)
50 fprintf (f, "%s hash statistics:\n", name);
51 fprintf (f, "\t%u searches\n", table->searches);
52 fprintf (f, "\t%u collisions\n", table->collisions);
53 fprintf (f, "\t%lu elements\n", (unsigned long) htab_elements (table));
54 fprintf (f, "\t%lu table size\n", (unsigned long) htab_size (table));