/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Research25*26* hash table library private definitions27*/2829#ifndef _HASHLIB_H30#define _HASHLIB_H3132#include <ast.h>3334#define hash_info _hash_info_3536typedef void* (*Hash_alloc_f)(size_t);37typedef int (*Hash_compare_f)(const char*, const char*, ...);38typedef unsigned int (*Hash_hash_f)(const char*, ...);39typedef void (*Hash_free_f)(void*);40typedef void* (*Hash_region_f)(void*, void*, size_t, int);4142typedef struct /* root local pointers */43{44Hash_hash_f hash; /* name hash routine */45Hash_compare_f compare; /* name comparision routine */46Hash_alloc_f alloc; /* value allocation routine */47Hash_free_f free; /* value free routine */48Hash_region_f region; /* region alloc/free routine */49void* handle; /* region handle arg */50} Hash_local_t;5152#define _HASH_POSITION_PRIVATE_ \53Hash_table_t* tab; /* table pointer */ \54int flags; /* scan flags */ \55Hash_bucket_t** slot; /* table slot */ \56Hash_bucket_t** limit; /* slot limit */5758#define _HASH_LAST_PRIVATE_ \59const char* name; /* last lookup name */ \60unsigned int hash; /* last lookup hash */6162#define _HASH_ROOT_PRIVATE_ \63int namesize; /* fixed name size: 0 => string */ \64int meanchain; /* resize mean chain length */ \65Hash_local_t* local; /* root local pointers */ \66Hash_root_t* next; /* next in list of all roots */ \67Hash_table_t* references; /* referencing table list */6869#define _HASH_TABLE_PRIVATE_ \70unsigned char frozen; /* table freeze nesting */ \71unsigned char bucketsize; /* min bucket size in char*'s */ \72Hash_bucket_t** table; /* hash slot table */ \73Hash_table_t* next; /* root reference list link */7475#include <hash.h>7677#define HASHMINSIZE (1<<4) /* min table slots (power of 2) */78#define HASHMEANCHAIN 2 /* def resize mean chain len */7980#define HASHMOD(t,h) (h &= (t->size - 1))81#define HASHVAL(x) ((x)&~HASH_FLAGS)8283#define HASH(r,n,h) if (r->local->hash) h = r->namesize ? (*r->local->hash)(n, r->namesize) : (*r->local->hash)(n);\84else\85{\86register const char* _hash_s1 = n;\87h = 0;\88if (r->namesize)\89{\90register const char* _hash_s2 = _hash_s1 + r->namesize;\91while (_hash_s1 < _hash_s2) HASHPART(h, *_hash_s1++);\92}\93else while (*_hash_s1) HASHPART(h, *_hash_s1++);\94}9596typedef struct /* library private info */97{98Hash_root_t* list; /* root table list */99} Hash_info_t;100101extern Hash_info_t hash_info;102103#endif104105106