/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/cdt/cdt.h

Go to the documentation of this file.
00001 /* $Id: cdt.h,v 1.5 2007/05/11 17:06:35 erg Exp $ $Revision: 1.5 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 #ifndef _CDT_H
00018 #define _CDT_H          1
00019 
00020 /*      Public interface for the dictionary library
00021 **
00022 **      Written by Kiem-Phong Vo (05/25/96)
00023 */
00024 
00025 #define CDT_VERSION     19991101L
00026 
00027 #define Void_t          void
00028 #define _ARG_(x)        x
00029 #ifndef NIL
00030 #define NIL(type) ((type)0)
00031 #endif
00032 
00033 #include <string.h>
00034 
00035 #if _PACKAGE_ast
00036 #  include      <ast_std.h>
00037 #elif _BLD_cdt
00038 #  include      "ast_common.h"
00039 #endif
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045     typedef struct _dtlink_s Dtlink_t;
00046     typedef struct _dthold_s Dthold_t;
00047     typedef struct _dtdisc_s Dtdisc_t;
00048     typedef struct _dtmethod_s Dtmethod_t;
00049     typedef struct _dtdata_s Dtdata_t;
00050     typedef struct _dt_s Dt_t;
00051     typedef struct _dt_s Dict_t;        /* for libdict compatibility */
00052     typedef struct _dtstat_s Dtstat_t;
00053     typedef Void_t *(*Dtsearch_f) _ARG_((Dt_t *, Void_t *, int));
00054     typedef Void_t *(*Dtmake_f) _ARG_((Dt_t *, Void_t *, Dtdisc_t *));
00055     typedef void (*Dtfree_f) _ARG_((Dt_t *, Void_t *, Dtdisc_t *));
00056     typedef int (*Dtcompar_f)
00057         _ARG_((Dt_t *, Void_t *, Void_t *, Dtdisc_t *));
00058     typedef unsigned int (*Dthash_f) _ARG_((Dt_t *, Void_t *, Dtdisc_t *));
00059     typedef Void_t *(*Dtmemory_f)
00060         _ARG_((Dt_t *, Void_t *, size_t, Dtdisc_t *));
00061     typedef int (*Dtevent_f) _ARG_((Dt_t *, int, Void_t *, Dtdisc_t *));
00062 
00063     struct _dtlink_s {
00064         Dtlink_t *right;        /* right child          */
00065         union {
00066             unsigned int _hash; /* hash value           */
00067             Dtlink_t *_left;    /* left child           */
00068         } hl;
00069     };
00070 
00071 /* private structure to hold an object */
00072     struct _dthold_s {
00073         Dtlink_t hdr;           /* header               */
00074         Void_t *obj;            /* user object          */
00075     };
00076 
00077 /* method to manipulate dictionary structure */
00078     struct _dtmethod_s {
00079         Dtsearch_f searchf;     /* search function     */
00080         int type;               /* type of operation    */
00081     };
00082 
00083 /* stuff that may be in shared memory */
00084     struct _dtdata_s {
00085         int type;               /* type of dictionary                   */
00086         Dtlink_t *here;         /* finger to last search element        */
00087         union {
00088             Dtlink_t **_htab;   /* hash table                           */
00089             Dtlink_t *_head;    /* linked list                          */
00090         } hh;
00091         int ntab;               /* number of hash slots                 */
00092         int size;               /* number of objects                    */
00093         int loop;               /* number of nested loops               */
00094     };
00095 
00096 /* structure to hold methods that manipulate an object */
00097     struct _dtdisc_s {
00098         int key;                /* where the key begins in an object    */
00099         int size;               /* key size and type                    */
00100         int link;               /* offset to Dtlink_t field             */
00101         Dtmake_f makef;         /* object constructor                   */
00102         Dtfree_f freef;         /* object destructor                    */
00103         Dtcompar_f comparf;     /* to compare two objects               */
00104         Dthash_f hashf;         /* to compute hash value of an object   */
00105         Dtmemory_f memoryf;     /* to allocate/free memory              */
00106         Dtevent_f eventf;       /* to process events                    */
00107     };
00108 
00109 /* the dictionary structure itself */
00110     struct _dt_s {
00111         Dtsearch_f searchf;     /* search function                      */
00112         Dtdisc_t *disc;         /* method to manipulate objs            */
00113         Dtdata_t *data;         /* sharable data                        */
00114         Dtmemory_f memoryf;     /* function to alloc/free memory        */
00115         Dtmethod_t *meth;       /* dictionary method                    */
00116         int type;               /* type information                     */
00117         int nview;              /* number of parent view dictionaries   */
00118         Dt_t *view;             /* next on viewpath                     */
00119         Dt_t *walk;             /* dictionary being walked              */
00120     };
00121 
00122 /* structure to get status of a dictionary */
00123     struct _dtstat_s {
00124         int dt_meth;            /* method type                          */
00125         int dt_size;            /* number of elements                   */
00126         int dt_n;               /* number of chains or levels           */
00127         int dt_max;             /* max size of a chain or a level       */
00128         int *dt_count;          /* counts of chains or levels by size   */
00129     };
00130 
00131 /* supported storage methods */
00132 #define DT_SET          0000001 /* set with unique elements             */
00133 #define DT_BAG          0000002 /* multiset                             */
00134 #define DT_OSET         0000004 /* ordered set (self-adjusting tree)    */
00135 #define DT_OBAG         0000010 /* ordered multiset                     */
00136 #define DT_LIST         0000020 /* linked list                          */
00137 #define DT_STACK        0000040 /* stack                                */
00138 #define DT_QUEUE        0000100 /* queue                                */
00139 #define DT_METHODS      0000177 /* all currently supported methods      */
00140 
00141 /* asserts to dtdisc() */
00142 #define DT_SAMECMP      0000001 /* compare methods equivalent           */
00143 #define DT_SAMEHASH     0000002 /* hash methods equivalent              */
00144 
00145 /* types of search */
00146 #define DT_INSERT       0000001 /* insert object if not found           */
00147 #define DT_DELETE       0000002 /* delete object if found               */
00148 #define DT_SEARCH       0000004 /* look for an object                   */
00149 #define DT_NEXT         0000010 /* look for next element                */
00150 #define DT_PREV         0000020 /* find previous element                */
00151 #define DT_RENEW        0000040 /* renewing an object                   */
00152 #define DT_CLEAR        0000100 /* clearing all objects                 */
00153 #define DT_FIRST        0000200 /* get first object                     */
00154 #define DT_LAST         0000400 /* get last object                      */
00155 #define DT_MATCH        0001000 /* find object matching key             */
00156 #define DT_VSEARCH      0002000 /* search using internal representation */
00157 #define DT_ATTACH       0004000 /* attach an object to the dictionary   */
00158 #define DT_DETACH       0010000 /* attach an object to the dictionary   */
00159 
00160 /* events */
00161 #define DT_OPEN         1       /* a dictionary is being opened         */
00162 #define DT_CLOSE        2       /* a dictionary is being closed         */
00163 #define DT_DISC         3       /* discipline is about to be changed    */
00164 #define DT_METH         4       /* method is about to be changed        */
00165 
00166 #if _BLD_cdt && defined(__EXPORT__)
00167 #define extern  __EXPORT__
00168 #endif
00169 #if !_BLD_cdt && defined(GVDLL)
00170 #define extern  __declspec(dllimport)
00171 #endif
00172 #if !_BLD_cdt && defined(__IMPORT__)
00173 #define extern  __IMPORT__
00174 #endif
00175      extern Dtmethod_t *Dtset;
00176     extern Dtmethod_t *Dtbag;
00177     extern Dtmethod_t *Dtoset;
00178     extern Dtmethod_t *Dtobag;
00179     extern Dtmethod_t *Dtlist;
00180     extern Dtmethod_t *Dtstack;
00181     extern Dtmethod_t *Dtqueue;
00182 
00183 /* compatibility stuff; will go away */
00184 #ifndef KPVDEL
00185     extern Dtmethod_t *Dtorder;
00186     extern Dtmethod_t *Dttree;
00187     extern Dtmethod_t *Dthash;
00188     extern Dtmethod_t _Dttree;
00189     extern Dtmethod_t _Dthash;
00190     extern Dtmethod_t _Dtlist;
00191     extern Dtmethod_t _Dtqueue;
00192     extern Dtmethod_t _Dtstack;
00193 #endif
00194 
00195 #undef extern
00196 #if _BLD_cdt && defined(__EXPORT__)
00197 #define extern  __EXPORT__
00198 #endif
00199 #if !_BLD_cdt && defined(__IMPORT__) && defined(__EXPORT__)
00200 #define extern  __IMPORT__
00201 #endif
00202      extern Dt_t *dtopen _ARG_((Dtdisc_t *, Dtmethod_t *));
00203     extern int dtclose _ARG_((Dt_t *));
00204     extern Dt_t *dtview _ARG_((Dt_t *, Dt_t *));
00205     extern Dtdisc_t *dtdisc _ARG_((Dt_t * dt, Dtdisc_t *, int));
00206     extern Dtmethod_t *dtmethod _ARG_((Dt_t *, Dtmethod_t *));
00207 
00208     extern Dtlink_t *dtflatten _ARG_((Dt_t *));
00209     extern Dtlink_t *dtextract _ARG_((Dt_t *));
00210     extern int dtrestore _ARG_((Dt_t *, Dtlink_t *));
00211 
00212     extern int dtwalk
00213         _ARG_((Dt_t *, int (*)(Dt_t *, Void_t *, Void_t *), Void_t *));
00214 
00215     extern Void_t *dtrenew _ARG_((Dt_t *, Void_t *));
00216 
00217     extern int dtsize _ARG_((Dt_t *));
00218     extern int dtstat _ARG_((Dt_t *, Dtstat_t *, int));
00219     extern unsigned int dtstrhash _ARG_((unsigned int, Void_t *, int));
00220 
00221 #undef extern
00222 
00223 #define _DT_(d)         ((Dt_t*)(d))
00224 #define dtvnext(d)      (_DT_(d)->view)
00225 #define dtvcount(d)     (_DT_(d)->nview)
00226 #define dtvhere(d)      (_DT_(d)->walk)
00227 #define dtlink(d,e)     (((Dtlink_t*)(e))->right)
00228 #define dtobj(d,e)      ((_DT_(d)->disc->link < 0) ? (((Dthold_t*)(e))->obj) : \
00229                                 (Void_t*)((char*)(e) - _DT_(d)->disc->link) )
00230 #define dtfinger(d)     (_DT_(d)->data->here ? dtobj((d),_DT_(d)->data->here) : \
00231                                 (Void_t*)(0) )
00232 #define dtfirst(d)      (*(_DT_(d)->searchf))((d),(Void_t*)(0),DT_FIRST)
00233 #define dtnext(d,o)     (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_NEXT)
00234 #define dtlast(d)       (*(_DT_(d)->searchf))((d),(Void_t*)(0),DT_LAST)
00235 #define dtprev(d,o)     (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_PREV)
00236 #define dtsearch(d,o)   (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_SEARCH)
00237 #define dtmatch(d,o)    (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_MATCH)
00238 #define dtinsert(d,o)   (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_INSERT)
00239 #define dtdelete(d,o)   (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_DELETE)
00240 #define dtattach(d,o)   (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_ATTACH)
00241 #define dtdetach(d,o)   (*(_DT_(d)->searchf))((d),(Void_t*)(o),DT_DETACH)
00242 #define dtclear(d)      (*(_DT_(d)->searchf))((d),(Void_t*)(0),DT_CLEAR)
00243 /* A linear congruential hash: h*17 + c + 97531 */
00244 #define dtcharhash(h,c) ((((unsigned int)(h))<<4) + ((unsigned int)(h)) + \
00245                          ((unsigned char)(c)) + 97531 )
00246 #ifdef __cplusplus
00247 }
00248 #endif
00249 #endif                          /* _CDT_H */

Generated on Mon Mar 31 19:03:23 2008 for Graphviz by  doxygen 1.5.1