125b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Copyright (C) 2000-2010 Red Hat, Inc.
203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is part of elfutils.
325b3c049e70834cf33790a28643ab058b507b35cBen Cheng   Written by Ulrich Drepper <drepper@redhat.com>, 2000.
425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is free software; you can redistribute it and/or modify
603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   it under the terms of either
725b3c049e70834cf33790a28643ab058b507b35cBen Cheng
803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes     * the GNU Lesser General Public License as published by the Free
903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       Software Foundation; either version 3 of the License, or (at
1003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       your option) any later version
1103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   or
1303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes     * the GNU General Public License as published by the Free
1503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       Software Foundation; either version 2 of the License, or (at
1603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       your option) any later version
1703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   or both in parallel, as here.
1903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   elfutils is distributed in the hope that it will be useful, but
2125b3c049e70834cf33790a28643ab058b507b35cBen Cheng   WITHOUT ANY WARRANTY; without even the implied warranty of
2225b3c049e70834cf33790a28643ab058b507b35cBen Cheng   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2325b3c049e70834cf33790a28643ab058b507b35cBen Cheng   General Public License for more details.
2425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
2503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   You should have received copies of the GNU General Public License and
2603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   the GNU Lesser General Public License along with this program.  If
2703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   not, see <http://www.gnu.org/licenses/>.  */
2825b3c049e70834cf33790a28643ab058b507b35cBen Cheng
2925b3c049e70834cf33790a28643ab058b507b35cBen Cheng#include <stddef.h>
3025b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3125b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Before including this file the following macros must be defined:
3225b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3325b3c049e70834cf33790a28643ab058b507b35cBen Cheng   NAME      name of the hash table structure.
3425b3c049e70834cf33790a28643ab058b507b35cBen Cheng   TYPE      data type of the hash table entries
3525b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3625b3c049e70834cf33790a28643ab058b507b35cBen Cheng   The following macros if present select features:
3725b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3825b3c049e70834cf33790a28643ab058b507b35cBen Cheng   ITERATE   iterating over the table entries is possible
3925b3c049e70834cf33790a28643ab058b507b35cBen Cheng   HASHTYPE  integer type for hash values, default unsigned long int
4025b3c049e70834cf33790a28643ab058b507b35cBen Cheng */
4125b3c049e70834cf33790a28643ab058b507b35cBen Cheng
4225b3c049e70834cf33790a28643ab058b507b35cBen Cheng
4325b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Optionally include an entry pointing to the first used entry.  */
4425b3c049e70834cf33790a28643ab058b507b35cBen Cheng#ifdef ITERATE
4525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define FIRST(name)	name##_ent *first;
4625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define NEXT(name)	struct name##_ent *next;
4725b3c049e70834cf33790a28643ab058b507b35cBen Cheng#else
4825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define FIRST(name)
4925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define NEXT(name)
5025b3c049e70834cf33790a28643ab058b507b35cBen Cheng#endif
5125b3c049e70834cf33790a28643ab058b507b35cBen Cheng
5225b3c049e70834cf33790a28643ab058b507b35cBen Cheng#ifndef HASHTYPE
5325b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define HASHTYPE unsigned long int
5425b3c049e70834cf33790a28643ab058b507b35cBen Cheng#endif
5525b3c049e70834cf33790a28643ab058b507b35cBen Cheng
5625b3c049e70834cf33790a28643ab058b507b35cBen Cheng
5725b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Defined separately.  */
5825b3c049e70834cf33790a28643ab058b507b35cBen Chengextern size_t next_prime (size_t seed);
5925b3c049e70834cf33790a28643ab058b507b35cBen Cheng
6025b3c049e70834cf33790a28643ab058b507b35cBen Cheng
6125b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Table entry type.  */
6225b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define _DYNHASHENTTYPE(name) \
6325b3c049e70834cf33790a28643ab058b507b35cBen Cheng  typedef struct name##_ent						      \
6425b3c049e70834cf33790a28643ab058b507b35cBen Cheng  {									      \
6525b3c049e70834cf33790a28643ab058b507b35cBen Cheng    HASHTYPE hashval;							      \
6625b3c049e70834cf33790a28643ab058b507b35cBen Cheng    TYPE data;								      \
6725b3c049e70834cf33790a28643ab058b507b35cBen Cheng    NEXT (name)								      \
6825b3c049e70834cf33790a28643ab058b507b35cBen Cheng  } name##_ent
6925b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name)
7025b3c049e70834cf33790a28643ab058b507b35cBen ChengDYNHASHENTTYPE (NAME);
7125b3c049e70834cf33790a28643ab058b507b35cBen Cheng
7225b3c049e70834cf33790a28643ab058b507b35cBen Cheng
7325b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Type of the dynamic hash table data structure.  */
7425b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define _DYNHASHTYPE(name) \
7525b3c049e70834cf33790a28643ab058b507b35cBen Chengtypedef struct								      \
7625b3c049e70834cf33790a28643ab058b507b35cBen Cheng{									      \
7725b3c049e70834cf33790a28643ab058b507b35cBen Cheng  size_t size;								      \
7825b3c049e70834cf33790a28643ab058b507b35cBen Cheng  size_t filled;							      \
7925b3c049e70834cf33790a28643ab058b507b35cBen Cheng  name##_ent *table;							      \
8025b3c049e70834cf33790a28643ab058b507b35cBen Cheng  FIRST	(name)								      \
8125b3c049e70834cf33790a28643ab058b507b35cBen Cheng} name
8225b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define DYNHASHTYPE(name) _DYNHASHTYPE (name)
8325b3c049e70834cf33790a28643ab058b507b35cBen ChengDYNHASHTYPE (NAME);
8425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
8525b3c049e70834cf33790a28643ab058b507b35cBen Cheng
8625b3c049e70834cf33790a28643ab058b507b35cBen Cheng
8725b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define _FUNCTIONS(name) \
8825b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Initialize the hash table.  */					      \
8925b3c049e70834cf33790a28643ab058b507b35cBen Chengextern int name##_init (name *htab, size_t init_size);			      \
9025b3c049e70834cf33790a28643ab058b507b35cBen Cheng									      \
9125b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Free resources allocated for hash table.  */				      \
9225b3c049e70834cf33790a28643ab058b507b35cBen Chengextern int name##_free (name *htab);					      \
9325b3c049e70834cf33790a28643ab058b507b35cBen Cheng									      \
9425b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Insert new entry.  */						      \
9525b3c049e70834cf33790a28643ab058b507b35cBen Chengextern int name##_insert (name *htab, HASHTYPE hval, TYPE data);	      \
9625b3c049e70834cf33790a28643ab058b507b35cBen Cheng									      \
9725b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Insert new entry, possibly overwrite old entry.  */			      \
9825b3c049e70834cf33790a28643ab058b507b35cBen Chengextern int name##_overwrite (name *htab, HASHTYPE hval, TYPE data);	      \
9925b3c049e70834cf33790a28643ab058b507b35cBen Cheng									      \
10025b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Find entry in hash table.  */					      \
10125b3c049e70834cf33790a28643ab058b507b35cBen Chengextern TYPE name##_find (name *htab, HASHTYPE hval, TYPE val);
10225b3c049e70834cf33790a28643ab058b507b35cBen Cheng#define FUNCTIONS(name) _FUNCTIONS (name)
10325b3c049e70834cf33790a28643ab058b507b35cBen ChengFUNCTIONS (NAME)
10425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
10525b3c049e70834cf33790a28643ab058b507b35cBen Cheng
10625b3c049e70834cf33790a28643ab058b507b35cBen Cheng#ifdef ITERATE
10725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define _XFUNCTIONS(name) \
10825b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Get next element in table.  */					      \
10925b3c049e70834cf33790a28643ab058b507b35cBen Chengextern TYPE name##_iterate (name *htab, void **ptr);
11025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# define XFUNCTIONS(name) _XFUNCTIONS (name)
11125b3c049e70834cf33790a28643ab058b507b35cBen ChengXFUNCTIONS (NAME)
11225b3c049e70834cf33790a28643ab058b507b35cBen Cheng#endif
11325b3c049e70834cf33790a28643ab058b507b35cBen Cheng
11425b3c049e70834cf33790a28643ab058b507b35cBen Cheng#ifndef NO_UNDEF
11525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef DYNHASHENTTYPE
11625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef DYNHASHTYPE
11725b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef FUNCTIONS
11825b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef _FUNCTIONS
11925b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef XFUNCTIONS
12025b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef _XFUNCTIONS
12125b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef NAME
12225b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef TYPE
12325b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef ITERATE
12425b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef COMPARE
12525b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef FIRST
12625b3c049e70834cf33790a28643ab058b507b35cBen Cheng# undef NEXT
12725b3c049e70834cf33790a28643ab058b507b35cBen Cheng#endif
128