Main Page | Modules | Data Structures | File List | Globals | Examples

/net/hp45/pmw/mware/cmrpc/tclHash.h

00001 /*
00002  * tclHash.h --
00003  *
00004  *  This header file was brutally hacked to allow tclHash.c to be 
00005  *  compiled and used outside of tcl.  Derived from tcl.h and tclInt.h 
00006  *  in the tcl 7.4 release.
00007  *  
00008  * Original copyright notices below.
00009  *
00010  * Copyright (c) 1987-1994 The Regents of the University of California.
00011  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
00012  *
00013  * See the file "license.terms" for information on usage and redistribution
00014  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00015  *
00016  * @(#) tcl.h 1.153 95/06/27 15:42:31
00017  */
00018 
00019 #ifndef _TCL_HASN
00020 #define _TCL_HASH
00021 
00022 #ifndef BUFSIZ
00023 #include <stdio.h>
00024 #endif
00025 
00026 #define TCL_VERSION "7.4"
00027 #define TCL_MAJOR_VERSION 7
00028 #define TCL_MINOR_VERSION 4
00029 
00030 /*
00031  * Definitions that allow this header file to be used either with or
00032  * without ANSI C features like function prototypes.
00033  */
00034 
00035 #undef _ANSI_ARGS_
00036 #undef CONST
00037 #if ((defined(__STDC__) || defined(SABER)) && !defined(NO_PROTOTYPE)) || defined(__cplusplus)
00038 #   define _USING_PROTOTYPES_ 1
00039 #   define _ANSI_ARGS_(x)       x
00040 #   define CONST const
00041 #   ifdef __cplusplus
00042 #       define VARARGS(first) (first, ...)
00043 #   else
00044 #       define VARARGS(first) ()
00045 #   endif
00046 #else
00047 #   define _ANSI_ARGS_(x)       ()
00048 #   define CONST
00049 #endif
00050 
00051 #ifdef __cplusplus
00052 #   define EXTERN extern "C"
00053 #else
00054 #   define EXTERN extern
00055 #endif
00056 
00057 /*
00058  * Macro to use instead of "void" for arguments that must have
00059  * type "void *" in ANSI C;  maps them to type "char *" in
00060  * non-ANSI systems.
00061  */
00062 
00063 #ifndef VOID
00064 #   ifdef __STDC__
00065 #       define VOID void
00066 #   else
00067 #       define VOID char
00068 #   endif
00069 #endif
00070 
00071 /*
00072  * Miscellaneous declarations (to allow Tcl to be used stand-alone,
00073  * without the rest of Sprite).
00074  */
00075 
00076 #ifndef NULL
00077 #define NULL 0
00078 #endif
00079 
00080 #ifndef _CLIENTDATA
00081 #   if defined(__STDC__) || defined(__cplusplus)
00082     typedef void *ClientData;
00083 #   else
00084     typedef int *ClientData;
00085 #   endif /* __STDC__ */
00086 #define _CLIENTDATA
00087 #endif
00088 
00089 
00090 /*
00091  * Forward declaration of Tcl_HashTable.  Needed by some C++ compilers
00092  * to prevent errors when the forward reference to Tcl_HashTable is
00093  * encountered in the Tcl_HashEntry structure.
00094  */
00095 
00096 #ifdef __cplusplus
00097 struct Tcl_HashTable;
00098 #endif
00099 
00100 /*
00101  * Structure definition for an entry in a hash table.  No-one outside
00102  * Tcl should access any of these fields directly;  use the macros
00103  * defined below.
00104  */
00105 
00106 typedef struct Tcl_HashEntry {
00107     struct Tcl_HashEntry *nextPtr;      /* Pointer to next entry in this
00108                                          * hash bucket, or NULL for end of
00109                                          * chain. */
00110     struct Tcl_HashTable *tablePtr;     /* Pointer to table containing entry. */
00111     struct Tcl_HashEntry **bucketPtr;   /* Pointer to bucket that points to
00112                                          * first entry in this entry's chain:
00113                                          * used for deleting the entry. */
00114     ClientData clientData;              /* Application stores something here
00115                                          * with Tcl_SetHashValue. */
00116     union {                             /* Key has one of these forms: */
00117         char *oneWordValue;             /* One-word value for key. */
00118         int words[1];                   /* Multiple integer words for key.
00119                                          * The actual size will be as large
00120                                          * as necessary for this table's
00121                                          * keys. */
00122         char string[4];                 /* String for key.  The actual size
00123                                          * will be as large as needed to hold
00124                                          * the key. */
00125     } key;                              /* MUST BE LAST FIELD IN RECORD!! */
00126 } Tcl_HashEntry;
00127 
00128 /*
00129  * Structure definition for a hash table.  Must be in tcl.h so clients
00130  * can allocate space for these structures, but clients should never
00131  * access any fields in this structure.
00132  */
00133 
00134 #define TCL_SMALL_HASH_TABLE 4
00135 typedef struct Tcl_HashTable {
00136     Tcl_HashEntry **buckets;            /* Pointer to bucket array.  Each
00137                                          * element points to first entry in
00138                                          * bucket's hash chain, or NULL. */
00139     Tcl_HashEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
00140                                         /* Bucket array used for small tables
00141                                          * (to avoid mallocs and frees). */
00142     int numBuckets;                     /* Total number of buckets allocated
00143                                          * at **bucketPtr. */
00144     int numEntries;                     /* Total number of entries present
00145                                          * in table. */
00146     int rebuildSize;                    /* Enlarge table when numEntries gets
00147                                          * to be this large. */
00148     int downShift;                      /* Shift count used in hashing
00149                                          * function.  Designed to use high-
00150                                          * order bits of randomized keys. */
00151     int mask;                           /* Mask value used in hashing
00152                                          * function. */
00153     int keyType;                        /* Type of keys used in this table. 
00154                                          * It's either TCL_STRING_KEYS,
00155                                          * TCL_ONE_WORD_KEYS, or an integer
00156                                          * giving the number of ints in a
00157                                          */
00158     Tcl_HashEntry *(*findProc) _ANSI_ARGS_((struct Tcl_HashTable *tablePtr,
00159             char *key));
00160     Tcl_HashEntry *(*createProc) _ANSI_ARGS_((struct Tcl_HashTable *tablePtr,
00161             char *key, int *newPtr));
00162 } Tcl_HashTable;
00163 
00164 /*
00165  * Structure definition for information used to keep track of searches
00166  * through hash tables:
00167  */
00168 
00169 typedef struct Tcl_HashSearch {
00170     Tcl_HashTable *tablePtr;            /* Table being searched. */
00171     int nextIndex;                      /* Index of next bucket to be
00172                                          * enumerated after present one. */
00173     Tcl_HashEntry *nextEntryPtr;        /* Next entry to be enumerated in the
00174                                          * the current bucket. */
00175 } Tcl_HashSearch;
00176 
00177 /*
00178  * Acceptable key types for hash tables:
00179  */
00180 
00181 #define TCL_STRING_KEYS         0
00182 #define TCL_ONE_WORD_KEYS       1
00183 
00184 /*
00185  * Macros for clients to use to access fields of hash entries:
00186  */
00187 
00188 #define Tcl_GetHashValue(h) ((h)->clientData)
00189 #define Tcl_SetHashValue(h, value) ((h)->clientData = (ClientData) (value))
00190 #define Tcl_GetHashKey(tablePtr, h) \
00191     ((char *) (((tablePtr)->keyType == TCL_ONE_WORD_KEYS) ? (h)->key.oneWordValue \
00192                                                 : (h)->key.string))
00193 /*
00194  * Macros to use for clients to use to invoke find and create procedures
00195  * for hash tables:
00196  */
00197 
00198 #define Tcl_FindHashEntry(tablePtr, key) \
00199         (*((tablePtr)->findProc))(tablePtr, key)
00200 #define Tcl_CreateHashEntry(tablePtr, key, newPtr) \
00201         (*((tablePtr)->createProc))(tablePtr, key, newPtr)
00202 
00203 
00204 EXTERN void             Tcl_DeleteHashEntry _ANSI_ARGS_((
00205                             Tcl_HashEntry *entryPtr));
00206 EXTERN void             Tcl_DeleteHashTable _ANSI_ARGS_((
00207                             Tcl_HashTable *tablePtr));
00208 EXTERN Tcl_HashEntry *  Tcl_FirstHashEntry _ANSI_ARGS_((
00209                             Tcl_HashTable *tablePtr,
00210                             Tcl_HashSearch *searchPtr));
00211 EXTERN char *           Tcl_HashStats _ANSI_ARGS_((Tcl_HashTable *tablePtr));
00212 EXTERN void             Tcl_InitHashTable _ANSI_ARGS_((Tcl_HashTable *tablePtr,
00213                             int keyType));
00214 EXTERN Tcl_HashEntry *  Tcl_NextHashEntry _ANSI_ARGS_((
00215                             Tcl_HashSearch *searchPtr));
00216 #endif /* _TCL_HASH */

Generated on Thu Oct 14 18:34:49 2004 for CMrpc by  doxygen 1.3.9.1