13 #define CDT_VERSION 20050420L
20 # define CDT_API __declspec(dllexport)
22 # define CDT_API __declspec(dllimport)
25 # define CDT_API extern
37 typedef void* (*Dtsearch_f)(Dt_t*,
void*,
int);
38 typedef void* (*Dtmake_f)(Dt_t*,
void*,
Dtdisc_t*);
92 #define DTDISC(dc,ky,sz,lk,mkf,frf,cmpf,hshf,memf,evf) \
93 ( (dc)->key = (ky), (dc)->size = (sz), (dc)->link = (lk), \
94 (dc)->makef = (mkf), (dc)->freef = (frf), \
95 (dc)->comparf = (cmpf), (dc)->hashf = (hshf), \
96 (dc)->memoryf = (memf), (dc)->eventf = (evf) )
122 #define DT_FOUND 0100000
125 #define DT_SET 0000001
126 #define DT_BAG 0000002
127 #define DT_OSET 0000004
128 #define DT_OBAG 0000010
129 #define DT_LIST 0000020
130 #define DT_STACK 0000040
131 #define DT_QUEUE 0000100
132 #define DT_DEQUE 0000200
133 #define DT_METHODS 0000377
136 #define DT_SAMECMP 0000001
137 #define DT_SAMEHASH 0000002
140 #define DT_INSERT 0000001
141 #define DT_DELETE 0000002
142 #define DT_SEARCH 0000004
143 #define DT_NEXT 0000010
144 #define DT_PREV 0000020
145 #define DT_RENEW 0000040
146 #define DT_CLEAR 0000100
147 #define DT_FIRST 0000200
148 #define DT_LAST 0000400
149 #define DT_MATCH 0001000
150 #define DT_VSEARCH 0002000
151 #define DT_ATTACH 0004000
152 #define DT_DETACH 0010000
153 #define DT_APPEND 0020000
161 #define DT_ENDCLOSE 6
162 #define DT_HASHSIZE 7
204 #define _DT(dt) ((Dt_t*)(dt))
205 #define _DTDSC(dc,ky,sz,lk,cmpf) \
206 (ky = dc->key, sz = dc->size, lk = dc->link, cmpf = dc->comparf)
207 #define _DTLNK(o,lk) ((Dtlink_t*)((char*)(o) + lk) )
208 #define _DTOBJ(e,lk) (lk < 0 ? ((Dthold_t*)(e))->obj : (void*)((char*)(e) - lk) )
209 #define _DTKEY(o,ky,sz) (void*)(sz < 0 ? *((char**)((char*)(o)+ky)) : ((char*)(o)+ky))
211 #define _DTCMP(dt,k1,k2,dc,cmpf,sz) \
212 (cmpf ? (*cmpf)(dt,k1,k2,dc) : \
213 (sz <= 0 ? strcmp(k1,k2) : memcmp(k1,k2,sz)) )
214 #define _DTHSH(dt,ky,dc,sz) (dc->hashf ? (*dc->hashf)(dt,ky,dc) : dtstrhash(0,ky,sz) )
217 #define _DTMTCH(dt,key,action) \
218 do { Dtlink_t* _e; void *_o, *_k, *_key; Dtdisc_t* _dc; \
219 int _ky, _sz, _lk, _cmp; Dtcompar_f _cmpf; \
220 _dc = (dt)->disc; _DTDSC(_dc, _ky, _sz, _lk, _cmpf); \
222 for(_e = (dt)->data->here; _e; _e = _cmp < 0 ? _e->hl._left : _e->right) \
223 { _o = _DTOBJ(_e, _lk); _k = _DTKEY(_o, _ky, _sz); \
224 if((_cmp = _DTCMP((dt), _key, _k, _dc, _cmpf, _sz)) == 0) \
227 action (_e ? _o : (void*)0); \
230 #define _DTSRCH(dt,obj,action) \
231 do { Dtlink_t* _e; void *_o, *_k, *_key; Dtdisc_t* _dc; \
232 int _ky, _sz, _lk, _cmp; Dtcompar_f _cmpf; \
233 _dc = (dt)->disc; _DTDSC(_dc, _ky, _sz, _lk, _cmpf); \
234 _key = _DTKEY(obj, _ky, _sz); \
235 for(_e = (dt)->data->here; _e; _e = _cmp < 0 ? _e->hl._left : _e->right) \
236 { _o = _DTOBJ(_e, _lk); _k = _DTKEY(_o, _ky, _sz); \
237 if((_cmp = _DTCMP((dt), _key, _k, _dc, _cmpf, _sz)) == 0) \
240 action (_e ? _o : (void*)0); \
243 #define DTTREEMATCH(dt,key,action) _DTMTCH(_DT(dt),(void*)(key),action)
244 #define DTTREESEARCH(dt,obj,action) _DTSRCH(_DT(dt),(void*)(obj),action)
246 #define dtvnext(d) (_DT(d)->view)
247 #define dtvcount(d) (_DT(d)->nview)
248 #define dtvhere(d) (_DT(d)->walk)
250 #define dtlink(d,e) (((Dtlink_t*)(e))->right)
251 #define dtobj(d,e) _DTOBJ((e), _DT(d)->disc->link)
252 #define dtfinger(d) (_DT(d)->data->here ? dtobj((d),_DT(d)->data->here):(void*)(0))
254 #define dtfirst(d) (*(_DT(d)->searchf))((d),(void*)(0),DT_FIRST)
255 #define dtnext(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_NEXT)
256 #define dtleast(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_SEARCH|DT_NEXT)
257 #define dtlast(d) (*(_DT(d)->searchf))((d),(void*)(0),DT_LAST)
258 #define dtprev(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_PREV)
259 #define dtmost(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_SEARCH|DT_PREV)
260 #define dtsearch(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_SEARCH)
261 #define dtmatch(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_MATCH)
262 #define dtinsert(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_INSERT)
263 #define dtappend(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_INSERT|DT_APPEND)
264 #define dtdelete(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_DELETE)
265 #define dtattach(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_ATTACH)
266 #define dtdetach(d,o) (*(_DT(d)->searchf))((d),(void*)(o),DT_DETACH)
267 #define dtclear(d) (*(_DT(d)->searchf))((d),(void*)(0),DT_CLEAR)
268 #define dtfound(d) (_DT(d)->type & DT_FOUND)
270 #define DT_PRIME 17109811
271 #define dtcharhash(h,c) (((unsigned int)(h) + (unsigned int)(c)) * DT_PRIME )
int(* Dtcompar_f)(Dt_t *, void *, void *, Dtdisc_t *)
unsigned int(* Dthash_f)(Dt_t *, void *, Dtdisc_t *)
CDT_API int dtclose(Dt_t *)
void *(* Dtmake_f)(Dt_t *, void *, Dtdisc_t *)
CDT_API Dtlink_t * dtextract(Dt_t *)
CDT_API Dtlink_t * dtflatten(Dt_t *)
CDT_API Dtmethod_t * Dtoset
CDT_API unsigned int dtstrhash(unsigned int, void *, int)
CDT_API Dtmethod_t * Dtbag
CDT_API Dt_t * dtview(Dt_t *, Dt_t *)
CDT_API Dtmethod_t _Dtqueue
CDT_API Dtmethod_t * Dtstack
CDT_API Dtdisc_t * dtdisc(Dt_t *dt, Dtdisc_t *, int)
CDT_API Dtmethod_t _Dtstack
CDT_API void * dtrenew(Dt_t *, void *)
CDT_API Dtmethod_t _Dtlist
CDT_API Dtmethod_t * Dtdeque
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
CDT_API Dtmethod_t * Dtqueue
CDT_API Dtmethod_t * Dtorder
CDT_API Dtmethod_t _Dthash
CDT_API Dtmethod_t * Dtset
void *(* Dtmemory_f)(Dt_t *, void *, size_t, Dtdisc_t *)
CDT_API Dtmethod_t * dtmethod(Dt_t *, Dtmethod_t *)
CDT_API int dtsize(Dt_t *)
void *(* Dtsearch_f)(Dt_t *, void *, int)
CDT_API Dtmethod_t _Dttree
CDT_API Dtmethod_t * Dttree
CDT_API int dtrestore(Dt_t *, Dtlink_t *)
CDT_API int dtwalk(Dt_t *, int(*)(Dt_t *, void *, void *), void *)
CDT_API Dtmethod_t * Dthash
CDT_API Dtmethod_t * Dtlist
int(* Dtevent_f)(Dt_t *, int, void *, Dtdisc_t *)
void(* Dtfree_f)(Dt_t *, void *, Dtdisc_t *)
CDT_API int dtstat(Dt_t *, Dtstat_t *, int)
CDT_API Dtmethod_t * Dtobag