Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

cdt.h

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