dynamicsizehash.h revision 25b3c049e70834cf33790a28643ab058b507b35c
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Copyright (C) 2000-2010 Red Hat, Inc. 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) This file is part of Red Hat elfutils. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Written by Ulrich Drepper <drepper@redhat.com>, 2000. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Red Hat elfutils is free software; you can redistribute it and/or modify 6e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) it under the terms of the GNU General Public License as published by the 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Free Software Foundation; version 2 of the License. 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Red Hat elfutils is distributed in the hope that it will be useful, but 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) WITHOUT ANY WARRANTY; without even the implied warranty of 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) General Public License for more details. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) You should have received a copy of the GNU General Public License along 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) with Red Hat elfutils; if not, write to the Free Software Foundation, 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) In addition, as a special exception, Red Hat, Inc. gives You the 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) additional right to link the code of Red Hat elfutils with code licensed 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) under any Open Source Initiative certified open source license 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) (http://www.opensource.org/licenses/index.php) which requires the 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) distribution of source code with any binary distribution and to 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) distribute linked combinations of the two. Non-GPL Code permitted under 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) this exception must only link to the code of Red Hat elfutils through 2506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) those well defined interfaces identified in the file named EXCEPTION 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) found in the source code files (the "Approved Interfaces"). The files 27197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch of Non-GPL Code may instantiate templates or use macros or inline 287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci functions from the Approved Interfaces without causing the resulting 291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) work to be covered by the GNU General Public License. Only Red Hat, 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Inc. may make changes or additions to the list of Approved Interfaces. 31c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) Red Hat's grant of this exception is conditioned upon your not adding 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) any new exceptions. If you wish to add a new Approved Interface or 33926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) exception, please contact Red Hat. You must obey the GNU General Public 34e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) License in all respects for all of the Red Hat elfutils code and other 35e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) code used in conjunction with Red Hat elfutils except the Non-GPL Code 36e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) covered by this exception. If you modify this file, you may extend this 37e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) exception to your version of the file, but you are not obligated to do 38926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) so. If you do not wish to provide this exception without modification, 39926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) you must delete this exception statement from your version and license 40926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) this file solely under the GPL without exception. 41926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 42926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) Red Hat elfutils is an included package of the Open Invention Network. 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) An included package of the Open Invention Network is a package for which 44e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) Open Invention Network licensees cross-license their patents. No patent 45e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) license is granted, either expressly or impliedly, by designation as an 46e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) included package. Should you wish to participate in the Open Invention 47e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) Network licensing program, please visit www.openinventionnetwork.com 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) <http://www.openinventionnetwork.com>. */ 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <stddef.h> 51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/* Before including this file the following macros must be defined: 53c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 54e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) NAME name of the hash table structure. 55e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) TYPE data type of the hash table entries 56e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 57926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) The following macros if present select features: 58926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 59926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ITERATE iterating over the table entries is possible 60926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) HASHTYPE integer type for hash values, default unsigned long int 61926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) */ 6207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 63c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci/* Optionally include an entry pointing to the first used entry. */ 657242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#ifdef ITERATE 667242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci# define FIRST(name) name##_ent *first; 67c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)# define NEXT(name) struct name##_ent *next; 68c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#else 69c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)# define FIRST(name) 70c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)# define NEXT(name) 71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#endif 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef HASHTYPE 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# define HASHTYPE unsigned long int 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Defined separately. */ 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern size_t next_prime (size_t seed); 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Table entry type. */ 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define _DYNHASHENTTYPE(name) \ 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) typedef struct name##_ent \ 851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) { \ 861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) HASHTYPE hashval; \ 871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) TYPE data; \ 881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) NEXT (name) \ 891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) } name##_ent 90d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name) 91d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)DYNHASHENTTYPE (NAME); 92d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 93d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 94d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)/* Type of the dynamic hash table data structure. */ 95926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define _DYNHASHTYPE(name) \ 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef struct \ 97926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ \ 985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) size_t size; \ 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) size_t filled; \ 1005d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) name##_ent *table; \ 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) FIRST (name) \ 1025d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)} name 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define DYNHASHTYPE(name) _DYNHASHTYPE (name) 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)DYNHASHTYPE (NAME); 10507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define _FUNCTIONS(name) \ 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Initialize the hash table. */ \ 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern int name##_init (name *htab, size_t init_size); \ 111926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) \ 112c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)/* Free resources allocated for hash table. */ \ 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern int name##_free (name *htab); \ 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) \ 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Insert new entry. */ \ 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern int name##_insert (name *htab, HASHTYPE hval, TYPE data); \ 1171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) \ 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Insert new entry, possibly overwrite old entry. */ \ 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern int name##_overwrite (name *htab, HASHTYPE hval, TYPE data); \ 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) \ 1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Find entry in hash table. */ \ 122926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)extern TYPE name##_find (name *htab, HASHTYPE hval, TYPE val); 1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define FUNCTIONS(name) _FUNCTIONS (name) 1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)FUNCTIONS (NAME) 1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 126c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 127#ifdef ITERATE 128# define _XFUNCTIONS(name) \ 129/* Get next element in table. */ \ 130extern TYPE name##_iterate (name *htab, void **ptr); 131# define XFUNCTIONS(name) _XFUNCTIONS (name) 132XFUNCTIONS (NAME) 133#endif 134 135#ifndef NO_UNDEF 136# undef DYNHASHENTTYPE 137# undef DYNHASHTYPE 138# undef FUNCTIONS 139# undef _FUNCTIONS 140# undef XFUNCTIONS 141# undef _XFUNCTIONS 142# undef NAME 143# undef TYPE 144# undef ITERATE 145# undef COMPARE 146# undef FIRST 147# undef NEXT 148#endif 149