1da2e3ebdSchin 2da2e3ebdSchin /* : : generated by proto : : */ 3da2e3ebdSchin /*********************************************************************** 4da2e3ebdSchin * * 5da2e3ebdSchin * This software is part of the ast package * 6*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property * 7da2e3ebdSchin * and is licensed under the * 8da2e3ebdSchin * Common Public License, Version 1.0 * 97c2fbfb3SApril Chin * by AT&T Intellectual Property * 10da2e3ebdSchin * * 11da2e3ebdSchin * A copy of the License is available at * 12da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt * 13da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 14da2e3ebdSchin * * 15da2e3ebdSchin * Information and Software Systems Research * 16da2e3ebdSchin * AT&T Research * 17da2e3ebdSchin * Florham Park NJ * 18da2e3ebdSchin * * 19da2e3ebdSchin * Glenn Fowler <gsf@research.att.com> * 20da2e3ebdSchin * David Korn <dgk@research.att.com> * 21da2e3ebdSchin * Phong Vo <kpv@research.att.com> * 22da2e3ebdSchin * * 23da2e3ebdSchin ***********************************************************************/ 24da2e3ebdSchin 25da2e3ebdSchin /* 26da2e3ebdSchin * Glenn Fowler 27da2e3ebdSchin * AT&T Research 28da2e3ebdSchin * 29da2e3ebdSchin * hash table library interface definitions 30da2e3ebdSchin * 31da2e3ebdSchin * NOTE: new code should use the more general <cdt.h> 32da2e3ebdSchin */ 33da2e3ebdSchin 34da2e3ebdSchin #ifndef _HASH_H 35da2e3ebdSchin #if !defined(__PROTO__) 36da2e3ebdSchin #include <prototyped.h> 37da2e3ebdSchin #endif 38da2e3ebdSchin #if !defined(__LINKAGE__) 39da2e3ebdSchin #define __LINKAGE__ /* 2004-08-11 transition */ 40da2e3ebdSchin #endif 41da2e3ebdSchin 42da2e3ebdSchin #define _HASH_H 43da2e3ebdSchin 44da2e3ebdSchin #define HASH_ALLOCATE (1L<<0) /* allocate new key names */ 45da2e3ebdSchin #define HASH_FIXED (1L<<1) /* fixed table size */ 46da2e3ebdSchin #define HASH_HASHED (1L<<6) /* key names already hashed */ 47da2e3ebdSchin #define HASH_RESIZE (1L<<2) /* table has been resized */ 48da2e3ebdSchin #define HASH_SCANNING (1L<<3) /* currently scanning scope */ 49da2e3ebdSchin #define HASH_SCOPE (1L<<4) /* push scope / create in bot */ 50da2e3ebdSchin #define HASH_STATIC (1L<<5) /* static table allocation */ 51da2e3ebdSchin 52da2e3ebdSchin #define HASH_CREATE (1L<<8) /* create bucket if not found */ 53da2e3ebdSchin #define HASH_DELETE (1L<<9) /* delete bucket if found */ 54da2e3ebdSchin #define HASH_LOOKUP 0 /* default op */ 55da2e3ebdSchin #define HASH_RENAME (1L<<7) /* rename bucket if found */ 56da2e3ebdSchin 57da2e3ebdSchin #define HASH_BUCKET (1L<<11) /* name is installed bucket */ 58da2e3ebdSchin #define HASH_INSTALL (1L<<12) /* install allocated bucket */ 59da2e3ebdSchin #define HASH_NOSCOPE (1L<<13) /* top scope only */ 60da2e3ebdSchin #define HASH_OPAQUE (1L<<14) /* opaque bucket */ 61da2e3ebdSchin #define HASH_VALUE (1L<<15) /* value bucket field used */ 62da2e3ebdSchin 63da2e3ebdSchin #define HASH_SIZE(n) (((long)(n))<<16) /* fixed bucket size */ 64da2e3ebdSchin #define HASH_SIZEOF(f) ((((long)(f))>>16)&0xffff) /* extract size */ 65da2e3ebdSchin 66da2e3ebdSchin #define HASH_DELETED ((unsigned long)1<<(8*sizeof(int)-1)) /* deleted placeholder */ 67da2e3ebdSchin #define HASH_KEEP (1L<<(8*sizeof(int)-2)) /* no free on bucket */ 68da2e3ebdSchin #define HASH_HIDDEN (1L<<(8*sizeof(int)-3)) /* hidden by scope */ 69da2e3ebdSchin #define HASH_HIDES (1L<<(8*sizeof(int)-4)) /* hides lower scope */ 70da2e3ebdSchin #define HASH_OPAQUED (1L<<(8*sizeof(int)-5)) /* opaqued placeholder */ 71da2e3ebdSchin #define HASH_FREENAME (1L<<(8*sizeof(int)-6)) /* free bucket name */ 72da2e3ebdSchin 73da2e3ebdSchin #define HASH_RESET (HASH_RESIZE|HASH_SCOPE|HASH_STATIC|HASH_VALUE) 74da2e3ebdSchin #define HASH_INTERNAL (HASH_BUCKET|HASH_RESIZE|HASH_SCANNING|HASH_STATIC) 75da2e3ebdSchin #define HASH_FLAGS (HASH_DELETED|HASH_FREENAME|HASH_HIDDEN|HASH_HIDES|HASH_KEEP|HASH_OPAQUED) 76da2e3ebdSchin 77da2e3ebdSchin #define HASH_alloc 1 78da2e3ebdSchin #define HASH_clear 2 79da2e3ebdSchin #define HASH_compare 3 80da2e3ebdSchin #define HASH_free 4 81da2e3ebdSchin #define HASH_hash 5 82da2e3ebdSchin #define HASH_meanchain 6 83da2e3ebdSchin #define HASH_name 7 84da2e3ebdSchin #define HASH_namesize 8 85da2e3ebdSchin #define HASH_set 9 86da2e3ebdSchin #define HASH_size 10 87da2e3ebdSchin #define HASH_table 11 88da2e3ebdSchin #define HASH_va_list 12 89da2e3ebdSchin 90da2e3ebdSchin #define HASH_bucketsize 13 91da2e3ebdSchin 92da2e3ebdSchin #define HASH_region 14 93da2e3ebdSchin 94da2e3ebdSchin #include <hashpart.h> 95da2e3ebdSchin 96da2e3ebdSchin #define hashclear(t,f) ((t)->flags &= ~((f) & ~HASH_INTERNAL)) 97da2e3ebdSchin #define hashcover(b) (((b)->hash&HASH_HIDES)?(Hash_bucket_t*)((b)->name):(Hash_bucket_t*)0) 98da2e3ebdSchin #define hashdel(t,n) hashlook(t, (char*)(n), HASH_DELETE, (char*)0) 99da2e3ebdSchin #define hashget(t,n) hashlook(t, (char*)(n), HASH_LOOKUP|HASH_VALUE, (char*)0) 100da2e3ebdSchin #define hashgetbucket(s) ((Hash_bucket_t*)((s)-((sizeof(Hash_bucket_t)+sizeof(char*)-1)/sizeof(char*))*sizeof(char*))) 101da2e3ebdSchin #define hashkeep(b) ((b)->hash|=HASH_KEEP) 102da2e3ebdSchin #define hashname(b) ((((b)->hash&HASH_HIDES)?((Hash_bucket_t*)((b)->name)):(b))->name) 103da2e3ebdSchin #define hashput(t,n,v) hashlook(t, (char*)(n), HASH_CREATE|HASH_VALUE, (char*)(v)) 104da2e3ebdSchin #define hashref(t,n) hashlook(t, (char*)(n), HASH_LOOKUP|HASH_INTERNAL|HASH_VALUE, (char*)0) 105da2e3ebdSchin #define hashscope(t) ((t)->scope) 106da2e3ebdSchin #define hashset(t,f) ((t)->flags |= ((f) & ~HASH_INTERNAL)) 107da2e3ebdSchin 108da2e3ebdSchin /* 109da2e3ebdSchin * DEPRECATED renames for compatibility 110da2e3ebdSchin */ 111da2e3ebdSchin 112da2e3ebdSchin #define Hashbin_t Hash_bucket_t 113da2e3ebdSchin #define HASHBUCKET Hash_bucket_t 114da2e3ebdSchin #define Hashhdr_t Hash_header_t 115da2e3ebdSchin #define HASHHEADER Hash_header_t 116da2e3ebdSchin #define Hashpos_t Hash_position_t 117da2e3ebdSchin #define HASHPOSITION Hash_position_t 118da2e3ebdSchin #define Hashtab_t Hash_table_t 119da2e3ebdSchin #define HASHTABLE Hash_table_t 120da2e3ebdSchin 121da2e3ebdSchin #define vhashalloc hashvalloc 122da2e3ebdSchin #define hashvalloc(t,a) hashalloc(t,HASH_va_list,a,0) 123da2e3ebdSchin 124da2e3ebdSchin /* 125da2e3ebdSchin * the #define's avoid union tags 126da2e3ebdSchin */ 127da2e3ebdSchin 128da2e3ebdSchin typedef struct Hash_bucket Hash_bucket_t; 129da2e3ebdSchin typedef struct Hash_root Hash_root_t; 130da2e3ebdSchin typedef struct Hash_table Hash_table_t; 131da2e3ebdSchin 132da2e3ebdSchin #define HASH_HEADER /* common bucket header */ \ 133da2e3ebdSchin Hash_bucket_t* next; /* next in collision chain */ \ 134da2e3ebdSchin unsigned int hash; /* hash flags and value */ \ 135da2e3ebdSchin char* name /* key name */ 136da2e3ebdSchin 137da2e3ebdSchin #define HASH_DEFAULT /* HASH_VALUE bucket elements */ \ 138da2e3ebdSchin char* value /* key value */ 139da2e3ebdSchin 140da2e3ebdSchin typedef struct /* bucket header */ 141da2e3ebdSchin { 142da2e3ebdSchin HASH_HEADER; 143da2e3ebdSchin } Hash_header_t; 144da2e3ebdSchin 145da2e3ebdSchin struct Hash_bucket /* prototype bucket */ 146da2e3ebdSchin { 147da2e3ebdSchin HASH_HEADER; 148da2e3ebdSchin HASH_DEFAULT; 149da2e3ebdSchin }; 150da2e3ebdSchin 151da2e3ebdSchin typedef struct /* hash scan bucket position */ 152da2e3ebdSchin { 153da2e3ebdSchin Hash_bucket_t* bucket; /* bucket */ 154da2e3ebdSchin #ifdef _HASH_POSITION_PRIVATE_ 155da2e3ebdSchin _HASH_POSITION_PRIVATE_ 156da2e3ebdSchin #endif 157da2e3ebdSchin } Hash_position_t; 158da2e3ebdSchin 159da2e3ebdSchin typedef struct /* last lookup cache */ 160da2e3ebdSchin { 161da2e3ebdSchin Hash_table_t* table; /* last lookup table */ 162da2e3ebdSchin Hash_bucket_t* bucket; /* last lookup bucket */ 163da2e3ebdSchin #ifdef _HASH_LAST_PRIVATE_ 164da2e3ebdSchin _HASH_LAST_PRIVATE_ 165da2e3ebdSchin #endif 166da2e3ebdSchin } Hash_last_t; 167da2e3ebdSchin 168da2e3ebdSchin struct Hash_root /* root hash table information */ 169da2e3ebdSchin { 170da2e3ebdSchin int accesses; /* number of accesses */ 171da2e3ebdSchin int collisions; /* number of collisions */ 172da2e3ebdSchin int flags; /* flags: see HASH_[A-Z]* */ 173da2e3ebdSchin Hash_last_t last; /* last lookup cache */ 174da2e3ebdSchin __V_* context; /* user defined context */ 175da2e3ebdSchin #ifdef _HASH_ROOT_PRIVATE_ 176da2e3ebdSchin _HASH_ROOT_PRIVATE_ 177da2e3ebdSchin #endif 178da2e3ebdSchin }; 179da2e3ebdSchin 180da2e3ebdSchin struct Hash_table /* hash table information */ 181da2e3ebdSchin { 182da2e3ebdSchin Hash_root_t* root; /* root hash table information */ 183da2e3ebdSchin int size; /* table size */ 184da2e3ebdSchin int buckets; /* active bucket count */ 185da2e3ebdSchin char* name; /* table name */ 186da2e3ebdSchin Hash_table_t* scope; /* scope covered table */ 187da2e3ebdSchin short flags; /* flags: see HASH_[A-Z]* */ 188da2e3ebdSchin #ifdef _HASH_TABLE_PRIVATE_ 189da2e3ebdSchin _HASH_TABLE_PRIVATE_ 190da2e3ebdSchin #endif 191da2e3ebdSchin }; 192da2e3ebdSchin 193da2e3ebdSchin #if _BLD_ast && defined(__EXPORT__) 194da2e3ebdSchin #undef __MANGLE__ 195da2e3ebdSchin #define __MANGLE__ __LINKAGE__ __EXPORT__ 196da2e3ebdSchin #endif 197da2e3ebdSchin 198da2e3ebdSchin extern __MANGLE__ Hash_table_t* hashalloc __PROTO__((Hash_table_t*, ...)); 199da2e3ebdSchin extern __MANGLE__ void hashdone __PROTO__((Hash_position_t*)); 200da2e3ebdSchin extern __MANGLE__ void hashdump __PROTO__((Hash_table_t*, int)); 201da2e3ebdSchin extern __MANGLE__ Hash_table_t* hashfree __PROTO__((Hash_table_t*)); 202da2e3ebdSchin extern __MANGLE__ Hash_bucket_t* hashlast __PROTO__((Hash_table_t*)); 203da2e3ebdSchin extern __MANGLE__ char* hashlook __PROTO__((Hash_table_t*, const char*, long, const char*)); 204da2e3ebdSchin extern __MANGLE__ Hash_bucket_t* hashnext __PROTO__((Hash_position_t*)); 205da2e3ebdSchin extern __MANGLE__ Hash_position_t* hashscan __PROTO__((Hash_table_t*, int)); 206da2e3ebdSchin extern __MANGLE__ void hashsize __PROTO__((Hash_table_t*, int)); 207da2e3ebdSchin extern __MANGLE__ Hash_table_t* hashview __PROTO__((Hash_table_t*, Hash_table_t*)); 208da2e3ebdSchin extern __MANGLE__ int hashwalk __PROTO__((Hash_table_t*, int, int (*)(const char*, char*, __V_*), __V_*)); 209da2e3ebdSchin 210da2e3ebdSchin #undef __MANGLE__ 211da2e3ebdSchin #define __MANGLE__ __LINKAGE__ 212da2e3ebdSchin 213da2e3ebdSchin #endif 214