blob: ccd41d0fa467c2066792ebeb13d4b548783b1162 [file] [log] [blame]
Roland McGrath3e0f7d12010-06-15 23:10:35 -07001/* Copyright (C) 2000-2010 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
4
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00007
Mark Wielaardde2ed972012-06-05 17:15:16 +02008 * 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
Ulrich Drepper361df7d2006-04-04 21:38:57 +000021 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
Mark Wielaardde2ed972012-06-05 17:15:16 +020025 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000028
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
Roland McGrath3e0f7d12010-06-15 23:10:35 -070039 HASHTYPE integer type for hash values, default unsigned long int
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040 */
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
Roland McGrath3e0f7d12010-06-15 23:10:35 -070052#ifndef HASHTYPE
53# define HASHTYPE unsigned long int
54#endif
55
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000056
57/* Defined separately. */
58extern size_t next_prime (size_t seed);
59
60
61/* Table entry type. */
62#define _DYNHASHENTTYPE(name) \
63 typedef struct name##_ent \
64 { \
Roland McGrath3e0f7d12010-06-15 23:10:35 -070065 HASHTYPE hashval; \
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000066 TYPE data; \
67 NEXT (name) \
68 } name##_ent
69#define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name)
70DYNHASHENTTYPE (NAME);
71
72
73/* Type of the dynamic hash table data structure. */
74#define _DYNHASHTYPE(name) \
75typedef struct \
76{ \
Roland McGrath3e0f7d12010-06-15 23:10:35 -070077 size_t size; \
78 size_t filled; \
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000079 name##_ent *table; \
80 FIRST (name) \
81} name
82#define DYNHASHTYPE(name) _DYNHASHTYPE (name)
83DYNHASHTYPE (NAME);
84
85
86
87#define _FUNCTIONS(name) \
88/* Initialize the hash table. */ \
Roland McGrath3e0f7d12010-06-15 23:10:35 -070089extern int name##_init (name *htab, size_t init_size); \
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000090 \
91/* Free resources allocated for hash table. */ \
92extern int name##_free (name *htab); \
93 \
94/* Insert new entry. */ \
Roland McGrath3e0f7d12010-06-15 23:10:35 -070095extern int name##_insert (name *htab, HASHTYPE hval, TYPE data); \
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000096 \
97/* Insert new entry, possibly overwrite old entry. */ \
Roland McGrath3e0f7d12010-06-15 23:10:35 -070098extern int name##_overwrite (name *htab, HASHTYPE hval, TYPE data); \
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000099 \
100/* Find entry in hash table. */ \
Roland McGrath3e0f7d12010-06-15 23:10:35 -0700101extern TYPE name##_find (name *htab, HASHTYPE hval, TYPE val);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000102#define FUNCTIONS(name) _FUNCTIONS (name)
103FUNCTIONS (NAME)
104
105
106#ifdef ITERATE
107# define _XFUNCTIONS(name) \
108/* Get next element in table. */ \
109extern TYPE name##_iterate (name *htab, void **ptr);
110# define XFUNCTIONS(name) _XFUNCTIONS (name)
111XFUNCTIONS (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