Home | History | Annotate | Download | only in lib
      1 /* Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
      2    Written by Ulrich Drepper <drepper (at) redhat.com>, 2000.
      3 
      4    This program is Open Source software; you can redistribute it and/or
      5    modify it under the terms of the Open Software License version 1.0 as
      6    published by the Open Source Initiative.
      7 
      8    You should have received a copy of the Open Software License along
      9    with this program; if not, you may obtain a copy of the Open Software
     10    License version 1.0 from http://www.opensource.org/licenses/osl.php or
     11    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
     12    3001 King Ranch Road, Ukiah, CA 95482.   */
     13 
     14 #include <stddef.h>
     15 
     16 /* Before including this file the following macros must be defined:
     17 
     18    NAME      name of the hash table structure.
     19    TYPE      data type of the hash table entries
     20 
     21    The following macros if present select features:
     22 
     23    ITERATE   iterating over the table entries is possible
     24  */
     25 
     26 
     27 /* Optionally include an entry pointing to the first used entry.  */
     28 #ifdef ITERATE
     29 # define FIRST(name)	name##_ent *first;
     30 # define NEXT(name)	struct name##_ent *next;
     31 #else
     32 # define FIRST(name)
     33 # define NEXT(name)
     34 #endif
     35 
     36 
     37 /* Defined separately.  */
     38 extern size_t next_prime (size_t seed);
     39 
     40 
     41 /* Table entry type.  */
     42 #define _DYNHASHENTTYPE(name) \
     43   typedef struct name##_ent						      \
     44   {									      \
     45     unsigned long int hashval;						      \
     46     TYPE data;								      \
     47     NEXT (name)								      \
     48   } name##_ent
     49 #define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name)
     50 DYNHASHENTTYPE (NAME);
     51 
     52 
     53 /* Type of the dynamic hash table data structure.  */
     54 #define _DYNHASHTYPE(name) \
     55 typedef struct								      \
     56 {									      \
     57   unsigned long int size;						      \
     58   unsigned long int filled;						      \
     59   name##_ent *table;							      \
     60   FIRST	(name)								      \
     61 } name
     62 #define DYNHASHTYPE(name) _DYNHASHTYPE (name)
     63 DYNHASHTYPE (NAME);
     64 
     65 
     66 
     67 #define _FUNCTIONS(name) \
     68 /* Initialize the hash table.  */					      \
     69 extern int name##_init (name *htab, unsigned long int init_size);	      \
     70 									      \
     71 /* Free resources allocated for hash table.  */				      \
     72 extern int name##_free (name *htab);					      \
     73 									      \
     74 /* Insert new entry.  */						      \
     75 extern int name##_insert (name *htab, unsigned long int hval, TYPE data);     \
     76 									      \
     77 /* Insert new entry, possibly overwrite old entry.  */			      \
     78 extern int name##_overwrite (name *htab, unsigned long int hval, TYPE data);  \
     79 									      \
     80 /* Find entry in hash table.  */					      \
     81 extern TYPE name##_find (name *htab, unsigned long int hval, TYPE val);
     82 #define FUNCTIONS(name) _FUNCTIONS (name)
     83 FUNCTIONS (NAME)
     84 
     85 
     86 #ifdef ITERATE
     87 # define _XFUNCTIONS(name) \
     88 /* Get next element in table.  */					      \
     89 extern TYPE name##_iterate (name *htab, void **ptr);
     90 # define XFUNCTIONS(name) _XFUNCTIONS (name)
     91 XFUNCTIONS (NAME)
     92 #endif
     93 
     94 #ifndef NO_UNDEF
     95 # undef DYNHASHENTTYPE
     96 # undef DYNHASHTYPE
     97 # undef FUNCTIONS
     98 # undef _FUNCTIONS
     99 # undef XFUNCTIONS
    100 # undef _XFUNCTIONS
    101 # undef NAME
    102 # undef TYPE
    103 # undef ITERATE
    104 # undef COMPARE
    105 # undef FIRST
    106 # undef NEXT
    107 #endif
    108