Home | History | Annotate | Download | only in lib
      1 /* Copyright (C) 2000-2010 Red Hat, Inc.
      2    This file is part of elfutils.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2000.
      4 
      5    This file is free software; you can redistribute it and/or modify
      6    it under the terms of either
      7 
      8      * the GNU Lesser General Public License as published by the Free
      9        Software Foundation; either version 3 of the License, or (at
     10        your option) any later version
     11 
     12    or
     13 
     14      * the GNU General Public License as published by the Free
     15        Software Foundation; either version 2 of the License, or (at
     16        your option) any later version
     17 
     18    or both in parallel, as here.
     19 
     20    elfutils is distributed in the hope that it will be useful, but
     21    WITHOUT ANY WARRANTY; without even the implied warranty of
     22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     23    General Public License for more details.
     24 
     25    You should have received copies of the GNU General Public License and
     26    the GNU Lesser General Public License along with this program.  If
     27    not, see <http://www.gnu.org/licenses/>.  */
     28 
     29 #include <stddef.h>
     30 
     31 /* Before including this file the following macros must be defined:
     32 
     33    NAME      name of the hash table structure.
     34    TYPE      data type of the hash table entries
     35 
     36    The following macros if present select features:
     37 
     38    ITERATE   iterating over the table entries is possible
     39    HASHTYPE  integer type for hash values, default unsigned long int
     40  */
     41 
     42 
     43 /* Optionally include an entry pointing to the first used entry.  */
     44 #ifdef ITERATE
     45 # define FIRST(name)	name##_ent *first;
     46 # define NEXT(name)	struct name##_ent *next;
     47 #else
     48 # define FIRST(name)
     49 # define NEXT(name)
     50 #endif
     51 
     52 #ifndef HASHTYPE
     53 # define HASHTYPE unsigned long int
     54 #endif
     55 
     56 
     57 /* Defined separately.  */
     58 extern size_t next_prime (size_t seed);
     59 
     60 
     61 /* Table entry type.  */
     62 #define _DYNHASHENTTYPE(name) \
     63   typedef struct name##_ent						      \
     64   {									      \
     65     HASHTYPE hashval;							      \
     66     TYPE data;								      \
     67     NEXT (name)								      \
     68   } name##_ent
     69 #define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name)
     70 DYNHASHENTTYPE (NAME);
     71 
     72 
     73 /* Type of the dynamic hash table data structure.  */
     74 #define _DYNHASHTYPE(name) \
     75 typedef struct								      \
     76 {									      \
     77   size_t size;								      \
     78   size_t filled;							      \
     79   name##_ent *table;							      \
     80   FIRST	(name)								      \
     81 } name
     82 #define DYNHASHTYPE(name) _DYNHASHTYPE (name)
     83 DYNHASHTYPE (NAME);
     84 
     85 
     86 
     87 #define _FUNCTIONS(name) \
     88 /* Initialize the hash table.  */					      \
     89 extern int name##_init (name *htab, size_t init_size);			      \
     90 									      \
     91 /* Free resources allocated for hash table.  */				      \
     92 extern int name##_free (name *htab);					      \
     93 									      \
     94 /* Insert new entry.  */						      \
     95 extern int name##_insert (name *htab, HASHTYPE hval, TYPE data);	      \
     96 									      \
     97 /* Insert new entry, possibly overwrite old entry.  */			      \
     98 extern int name##_overwrite (name *htab, HASHTYPE hval, TYPE data);	      \
     99 									      \
    100 /* Find entry in hash table.  */					      \
    101 extern TYPE name##_find (name *htab, HASHTYPE hval, TYPE val);
    102 #define FUNCTIONS(name) _FUNCTIONS (name)
    103 FUNCTIONS (NAME)
    104 
    105 
    106 #ifdef ITERATE
    107 # define _XFUNCTIONS(name) \
    108 /* Get next element in table.  */					      \
    109 extern TYPE name##_iterate (name *htab, void **ptr);
    110 # define XFUNCTIONS(name) _XFUNCTIONS (name)
    111 XFUNCTIONS (NAME)
    112 #endif
    113 
    114 #ifndef NO_UNDEF
    115 # undef DYNHASHENTTYPE
    116 # undef DYNHASHTYPE
    117 # undef FUNCTIONS
    118 # undef _FUNCTIONS
    119 # undef XFUNCTIONS
    120 # undef _XFUNCTIONS
    121 # undef NAME
    122 # undef TYPE
    123 # undef ITERATE
    124 # undef COMPARE
    125 # undef FIRST
    126 # undef NEXT
    127 #endif
    128