1*b30d1939SAndy Fiddaman /***********************************************************************
2*b30d1939SAndy Fiddaman *                                                                      *
3*b30d1939SAndy Fiddaman *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
5*b30d1939SAndy Fiddaman *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
7*b30d1939SAndy Fiddaman *                    by AT&T Intellectual Property                     *
8*b30d1939SAndy Fiddaman *                                                                      *
9*b30d1939SAndy Fiddaman *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*b30d1939SAndy Fiddaman *                                                                      *
13*b30d1939SAndy Fiddaman *              Information and Software Systems Research               *
14*b30d1939SAndy Fiddaman *                            AT&T Research                             *
15*b30d1939SAndy Fiddaman *                           Florham Park NJ                            *
16*b30d1939SAndy Fiddaman *                                                                      *
17*b30d1939SAndy Fiddaman *                 Glenn Fowler <gsf@research.att.com>                  *
18*b30d1939SAndy Fiddaman *                  David Korn <dgk@research.att.com>                   *
19*b30d1939SAndy Fiddaman *                   Phong Vo <kpv@research.att.com>                    *
20*b30d1939SAndy Fiddaman *                                                                      *
21*b30d1939SAndy Fiddaman ***********************************************************************/
22*b30d1939SAndy Fiddaman #ifndef _CDT_H
23*b30d1939SAndy Fiddaman #define _CDT_H		1
24*b30d1939SAndy Fiddaman 
25*b30d1939SAndy Fiddaman /*	Public interface for the dictionary library
26*b30d1939SAndy Fiddaman **
27*b30d1939SAndy Fiddaman **      Written by Kiem-Phong Vo
28*b30d1939SAndy Fiddaman */
29*b30d1939SAndy Fiddaman 
30*b30d1939SAndy Fiddaman #ifndef CDT_VERSION
31*b30d1939SAndy Fiddaman #ifdef _API_ast
32*b30d1939SAndy Fiddaman #define CDT_VERSION		_API_ast
33*b30d1939SAndy Fiddaman #else
34*b30d1939SAndy Fiddaman #define CDT_VERSION		20111111L
35*b30d1939SAndy Fiddaman #endif /*_AST_api*/
36*b30d1939SAndy Fiddaman #endif /*CDT_VERSION*/
37*b30d1939SAndy Fiddaman #ifndef AST_PLUGIN_VERSION
38*b30d1939SAndy Fiddaman #define AST_PLUGIN_VERSION(v)	(v)
39*b30d1939SAndy Fiddaman #endif
40*b30d1939SAndy Fiddaman #define CDT_PLUGIN_VERSION	AST_PLUGIN_VERSION(20111111L)
41*b30d1939SAndy Fiddaman 
42*b30d1939SAndy Fiddaman #if _PACKAGE_ast
43*b30d1939SAndy Fiddaman #include	<ast_std.h>
44*b30d1939SAndy Fiddaman #else
45*b30d1939SAndy Fiddaman #include	<ast_common.h>
46*b30d1939SAndy Fiddaman #include	<string.h>
47*b30d1939SAndy Fiddaman #endif
48*b30d1939SAndy Fiddaman 
49*b30d1939SAndy Fiddaman /* commonly used integers */
50*b30d1939SAndy Fiddaman #define DT_ZERO		((unsigned int)0)  /* all zero bits	*/
51*b30d1939SAndy Fiddaman #define DT_ONES		(~DT_ZERO)	   /* all one bits	*/
52*b30d1939SAndy Fiddaman #define DT_HIBIT	(~(DT_ONES >> 1) ) /* highest 1 bit	*/
53*b30d1939SAndy Fiddaman #define DT_LOBIT	((unsigned int)1)  /* lowest 1 bit	*/
54*b30d1939SAndy Fiddaman #define DT_NBITS	(sizeof(unsigned int)*8) /* #bits	*/
55*b30d1939SAndy Fiddaman 
56*b30d1939SAndy Fiddaman /* type of an integer with the same size as a pointer */
57*b30d1939SAndy Fiddaman #define Dtuint_t	uintptr_t
58*b30d1939SAndy Fiddaman 
59*b30d1939SAndy Fiddaman /* various types used by CDT */
60*b30d1939SAndy Fiddaman typedef struct _dtlink_s	Dtlink_t;
61*b30d1939SAndy Fiddaman typedef struct _dthold_s	Dthold_t;
62*b30d1939SAndy Fiddaman typedef struct _dtdisc_s	Dtdisc_t;
63*b30d1939SAndy Fiddaman typedef struct _dtmethod_s	Dtmethod_t;
64*b30d1939SAndy Fiddaman typedef struct _dtdata_s	Dtdata_t;
65*b30d1939SAndy Fiddaman typedef struct _dtuser_s	Dtuser_t;
66*b30d1939SAndy Fiddaman typedef struct _dt_s		Dt_t;
67*b30d1939SAndy Fiddaman typedef struct _dtstat_s	Dtstat_t;
68*b30d1939SAndy Fiddaman typedef Void_t*			(*Dtsearch_f)_ARG_((Dt_t*,Void_t*,int));
69*b30d1939SAndy Fiddaman typedef Void_t* 		(*Dtmake_f)_ARG_((Dt_t*,Void_t*,Dtdisc_t*));
70*b30d1939SAndy Fiddaman typedef void 			(*Dtfree_f)_ARG_((Dt_t*,Void_t*,Dtdisc_t*));
71*b30d1939SAndy Fiddaman typedef int			(*Dtcompar_f)_ARG_((Dt_t*,Void_t*,Void_t*,Dtdisc_t*));
72*b30d1939SAndy Fiddaman typedef unsigned int		(*Dthash_f)_ARG_((Dt_t*,Void_t*,Dtdisc_t*));
73*b30d1939SAndy Fiddaman typedef Void_t*			(*Dtmemory_f)_ARG_((Dt_t*,Void_t*,size_t,Dtdisc_t*));
74*b30d1939SAndy Fiddaman typedef int			(*Dtevent_f)_ARG_((Dt_t*,int,Void_t*,Dtdisc_t*));
75*b30d1939SAndy Fiddaman typedef int			(*Dttype_f)_ARG_((Dt_t*,int));
76*b30d1939SAndy Fiddaman 
77*b30d1939SAndy Fiddaman struct _dtuser_s /* for application to access and use */
78*b30d1939SAndy Fiddaman {	unsigned int	lock;	/* used by dtapplock	*/
79*b30d1939SAndy Fiddaman 	Void_t*		data;	/* for whatever data	*/
80*b30d1939SAndy Fiddaman };
81*b30d1939SAndy Fiddaman 
82*b30d1939SAndy Fiddaman struct _dtlink_s
83*b30d1939SAndy Fiddaman {
84*b30d1939SAndy Fiddaman #if CDT_VERSION < 20111111L
85*b30d1939SAndy Fiddaman 	Dtlink_t*	right;	/* right child		*/
86*b30d1939SAndy Fiddaman 	union
87*b30d1939SAndy Fiddaman 	{ unsigned int	_hash;	/* hash value		*/
88*b30d1939SAndy Fiddaman 	  Dtlink_t*	_left;	/* left child		*/
89*b30d1939SAndy Fiddaman 	} hl;
90*b30d1939SAndy Fiddaman #else
91*b30d1939SAndy Fiddaman 	union
92*b30d1939SAndy Fiddaman 	{ Dtlink_t*	__rght;	/* right child or next	*/
93*b30d1939SAndy Fiddaman 	  Dtlink_t*	__ptbl;	/* Dtrehash parent tbl	*/
94*b30d1939SAndy Fiddaman 	} rh;
95*b30d1939SAndy Fiddaman 	union
96*b30d1939SAndy Fiddaman 	{ Dtlink_t*	__left;	/* left child or prev	*/
97*b30d1939SAndy Fiddaman 	  unsigned int	__hash;	/* hash value of object	*/
98*b30d1939SAndy Fiddaman 	} lh;
99*b30d1939SAndy Fiddaman #endif
100*b30d1939SAndy Fiddaman };
101*b30d1939SAndy Fiddaman 
102*b30d1939SAndy Fiddaman /* private structure to hold an object */
103*b30d1939SAndy Fiddaman struct _dthold_s
104*b30d1939SAndy Fiddaman {	Dtlink_t	hdr;	/* header to hold obj	*/
105*b30d1939SAndy Fiddaman 	Void_t*		obj;	/* application object	*/
106*b30d1939SAndy Fiddaman };
107*b30d1939SAndy Fiddaman 
108*b30d1939SAndy Fiddaman /* method to manipulate dictionary structure */
109*b30d1939SAndy Fiddaman struct _dtmethod_s
110*b30d1939SAndy Fiddaman {	Dtsearch_f	searchf; /* search function	*/
111*b30d1939SAndy Fiddaman 	unsigned int	type;	 /* type of operation	*/
112*b30d1939SAndy Fiddaman 	int		(*eventf)_ARG_((Dt_t*, int, Void_t*));
113*b30d1939SAndy Fiddaman 	char*		name;	 /* name of method	*/
114*b30d1939SAndy Fiddaman 	char*		description; /* description */
115*b30d1939SAndy Fiddaman };
116*b30d1939SAndy Fiddaman 
117*b30d1939SAndy Fiddaman /* structure to hold methods that manipulate an object */
118*b30d1939SAndy Fiddaman struct _dtdisc_s
119*b30d1939SAndy Fiddaman {	int		key;	/* where the key resides 	*/
120*b30d1939SAndy Fiddaman 	int		size;	/* key size and type		*/
121*b30d1939SAndy Fiddaman 	int		link;	/* offset to Dtlink_t field	*/
122*b30d1939SAndy Fiddaman 	Dtmake_f	makef;	/* object constructor		*/
123*b30d1939SAndy Fiddaman 	Dtfree_f	freef;	/* object destructor		*/
124*b30d1939SAndy Fiddaman 	Dtcompar_f	comparf;/* to compare two objects	*/
125*b30d1939SAndy Fiddaman 	Dthash_f	hashf;	/* to compute hash value 	*/
126*b30d1939SAndy Fiddaman 	Dtmemory_f	memoryf;/* to allocate/free memory	*/
127*b30d1939SAndy Fiddaman 	Dtevent_f	eventf;	/* to process events		*/
128*b30d1939SAndy Fiddaman };
129*b30d1939SAndy Fiddaman 
130*b30d1939SAndy Fiddaman #define DTDISC(dc,ky,sz,lk,mkf,frf,cmpf,hshf,memf,evf) \
131*b30d1939SAndy Fiddaman 	( (dc)->key = (int)(ky), (dc)->size = (int)(sz), (dc)->link = (int)(lk), \
132*b30d1939SAndy Fiddaman 	  (dc)->makef = (mkf), (dc)->freef = (frf), \
133*b30d1939SAndy Fiddaman 	  (dc)->comparf = (cmpf), (dc)->hashf = (hshf), \
134*b30d1939SAndy Fiddaman 	  (dc)->memoryf = (memf), (dc)->eventf = (evf) )
135*b30d1939SAndy Fiddaman 
136*b30d1939SAndy Fiddaman #ifdef offsetof
137*b30d1939SAndy Fiddaman #define DTOFFSET(struct_s, member)	offsetof(struct_s, member)
138*b30d1939SAndy Fiddaman #else
139*b30d1939SAndy Fiddaman #define DTOFFSET(struct_s, member)	((int)(&((struct_s*)0)->member))
140*b30d1939SAndy Fiddaman #endif
141*b30d1939SAndy Fiddaman 
142*b30d1939SAndy Fiddaman /* the dictionary structure itself */
143*b30d1939SAndy Fiddaman struct _dt_s
144*b30d1939SAndy Fiddaman {	Dtsearch_f	searchf;/* search function		*/
145*b30d1939SAndy Fiddaman 	Dtdisc_t*	disc;	/* object type definitition	*/
146*b30d1939SAndy Fiddaman 	Dtdata_t*	data;	/* sharable data		*/
147*b30d1939SAndy Fiddaman 	Dtmemory_f	memoryf;/* for memory allocation	*/
148*b30d1939SAndy Fiddaman 	Dtmethod_t*	meth;	/* storage method		*/
149*b30d1939SAndy Fiddaman 	ssize_t		nview;	/* #parent view dictionaries	*/
150*b30d1939SAndy Fiddaman 	Dt_t*		view;	/* next on viewpath		*/
151*b30d1939SAndy Fiddaman 	Dt_t*		walk;	/* dictionary being walked	*/
152*b30d1939SAndy Fiddaman 	Dtuser_t*	user;	/* for user's usage		*/
153*b30d1939SAndy Fiddaman 	Dttype_f	typef;	/* for binary compatibility	*/
154*b30d1939SAndy Fiddaman };
155*b30d1939SAndy Fiddaman 
156*b30d1939SAndy Fiddaman /* structure to get status of a dictionary */
157*b30d1939SAndy Fiddaman #define DT_MAXRECURSE	1024	/* limit to avoid stack overflow	*/
158*b30d1939SAndy Fiddaman #define DT_MAXSIZE	256	/* limit for size of below arrays	*/
159*b30d1939SAndy Fiddaman struct _dtstat_s
160*b30d1939SAndy Fiddaman {	unsigned int	meth;	/* method type				*/
161*b30d1939SAndy Fiddaman 	ssize_t		size;	/* total # of elements in dictionary	*/
162*b30d1939SAndy Fiddaman 	ssize_t		space;	/* memory usage of data structure	*/
163*b30d1939SAndy Fiddaman 	ssize_t		mlev;	/* max #levels in tree or hash table	*/
164*b30d1939SAndy Fiddaman 	ssize_t		msize;	/* max #defined elts in below arrays	*/
165*b30d1939SAndy Fiddaman 	ssize_t		lsize[DT_MAXSIZE]; /* #objects by level		*/
166*b30d1939SAndy Fiddaman 	ssize_t		tsize[DT_MAXSIZE]; /* #tables by level		*/
167*b30d1939SAndy Fiddaman };
168*b30d1939SAndy Fiddaman 
169*b30d1939SAndy Fiddaman /* supported storage methods */
170*b30d1939SAndy Fiddaman #define DT_SET		0000000001 /* unordered set, unique elements	*/
171*b30d1939SAndy Fiddaman #define DT_BAG		0000000002 /* unordered set, repeated elements	*/
172*b30d1939SAndy Fiddaman #define DT_OSET		0000000004 /* ordered set			*/
173*b30d1939SAndy Fiddaman #define DT_OBAG		0000000010 /* ordered multiset			*/
174*b30d1939SAndy Fiddaman #define DT_LIST		0000000020 /* linked list			*/
175*b30d1939SAndy Fiddaman #define DT_STACK	0000000040 /* stack: insert/delete at top	*/
176*b30d1939SAndy Fiddaman #define DT_QUEUE	0000000100 /* queue: insert top, delete at tail	*/
177*b30d1939SAndy Fiddaman #define DT_DEQUE	0000000200 /* deque: insert top, append at tail	*/
178*b30d1939SAndy Fiddaman #define DT_RHSET	0000000400 /* rhset: sharable unique objects	*/
179*b30d1939SAndy Fiddaman #define DT_RHBAG	0000001000 /* rhbag: sharable repeated objects	*/
180*b30d1939SAndy Fiddaman #define DT_METHODS	0000001777 /* all currently supported methods	*/
181*b30d1939SAndy Fiddaman #define DT_ORDERED	(DT_OSET|DT_OBAG)
182*b30d1939SAndy Fiddaman 
183*b30d1939SAndy Fiddaman /* asserts to dtdisc() to improve performance when changing disciplines */
184*b30d1939SAndy Fiddaman #define DT_SAMECMP	0000000001 /* compare functions are equivalent	*/
185*b30d1939SAndy Fiddaman #define DT_SAMEHASH	0000000002 /* hash functions are equivalent	*/
186*b30d1939SAndy Fiddaman 
187*b30d1939SAndy Fiddaman /* operation types */
188*b30d1939SAndy Fiddaman #define DT_INSERT	0000000001 /* insert object if not found	*/
189*b30d1939SAndy Fiddaman #define DT_DELETE	0000000002 /* delete a matching object if any	*/
190*b30d1939SAndy Fiddaman #define DT_SEARCH	0000000004 /* look for an object		*/
191*b30d1939SAndy Fiddaman #define DT_NEXT		0000000010 /* look for next element		*/
192*b30d1939SAndy Fiddaman #define DT_PREV		0000000020 /* find previous element		*/
193*b30d1939SAndy Fiddaman #define DT_FIRST	0000000200 /* get first object			*/
194*b30d1939SAndy Fiddaman #define DT_LAST		0000000400 /* get last object			*/
195*b30d1939SAndy Fiddaman #define DT_MATCH	0000001000 /* find object matching key		*/
196*b30d1939SAndy Fiddaman #define DT_ATTACH	0000004000 /* attach an object to dictionary	*/
197*b30d1939SAndy Fiddaman #define DT_DETACH	0000010000 /* detach an object from dictionary	*/
198*b30d1939SAndy Fiddaman #define DT_APPEND	0000020000 /* append an object			*/
199*b30d1939SAndy Fiddaman #define DT_ATLEAST	0000040000 /* find the least elt >= object	*/
200*b30d1939SAndy Fiddaman #define DT_ATMOST	0000100000 /* find the biggest elt <= object	*/
201*b30d1939SAndy Fiddaman #define DT_REMOVE	0002000000 /* remove a specific object		*/
203*b30d1939SAndy Fiddaman 
204*b30d1939SAndy Fiddaman #define DT_RELINK	0000002000 /* re-inserting (dtdisc,dtmethod...)	*/
205*b30d1939SAndy Fiddaman #define DT_FLATTEN	0000000040 /* flatten objects into a list	*/
206*b30d1939SAndy Fiddaman #define DT_CLEAR	0000000100 /* clearing all objects		*/
207*b30d1939SAndy Fiddaman #define DT_EXTRACT	0000200000 /* FLATTEN and clear dictionary	*/
208*b30d1939SAndy Fiddaman #define DT_RESTORE	0000400000 /* reinsert a list of elements	*/
209*b30d1939SAndy Fiddaman #define DT_STAT		0001000000 /* get statistics of dictionary	*/
211*b30d1939SAndy Fiddaman 
212*b30d1939SAndy Fiddaman /* these bits may combine with the DT_METHODS and DT_OPERATIONS bits */
213*b30d1939SAndy Fiddaman #define DT_INDATA	0010000000 /* Dt_t was allocated with Dtdata_t	*/
214*b30d1939SAndy Fiddaman #define DT_SHARE	0020000000 /* concurrent access mode 		*/
215*b30d1939SAndy Fiddaman #define DT_ANNOUNCE	0040000000 /* announcing a successful operation	*/
216*b30d1939SAndy Fiddaman 				   /* the actual event will be this bit */
217*b30d1939SAndy Fiddaman 				   /* combined with the operation bit	*/
218*b30d1939SAndy Fiddaman #define DT_OPTIMIZE	0100000000 /* optimizing data structure		*/
219*b30d1939SAndy Fiddaman 
220*b30d1939SAndy Fiddaman /* events for discipline and method event-handling functions */
221*b30d1939SAndy Fiddaman #define DT_OPEN		1	/* a dictionary is being opened		*/
222*b30d1939SAndy Fiddaman #define DT_ENDOPEN	5	/* end of dictionary opening		*/
223*b30d1939SAndy Fiddaman #define DT_CLOSE	2	/* a dictionary is being closed		*/
224*b30d1939SAndy Fiddaman #define DT_ENDCLOSE	6	/* end of dictionary closing		*/
225*b30d1939SAndy Fiddaman #define DT_DISC		3	/* discipline is about to be changed	*/
226*b30d1939SAndy Fiddaman #define DT_METH		4	/* method is about to be changed	*/
227*b30d1939SAndy Fiddaman #define DT_HASHSIZE	7	/* initialize hash table size		*/
228*b30d1939SAndy Fiddaman #define DT_ERROR	0xbad	/* announcing an error			*/
229*b30d1939SAndy Fiddaman 
230*b30d1939SAndy Fiddaman _BEGIN_EXTERNS_	/* data structures and functions */
231*b30d1939SAndy Fiddaman #if _BLD_cdt && defined(__EXPORT__)
232*b30d1939SAndy Fiddaman #define extern	__EXPORT__
233*b30d1939SAndy Fiddaman #endif
234*b30d1939SAndy Fiddaman #if !_BLD_cdt && defined(__IMPORT__)
235*b30d1939SAndy Fiddaman #define extern	__IMPORT__
236*b30d1939SAndy Fiddaman #endif
237*b30d1939SAndy Fiddaman 
238*b30d1939SAndy Fiddaman extern Dtmethod_t* 	Dtset;
239*b30d1939SAndy Fiddaman extern Dtmethod_t* 	Dtbag;
240*b30d1939SAndy Fiddaman extern Dtmethod_t* 	Dtoset;
241*b30d1939SAndy Fiddaman extern Dtmethod_t* 	Dtobag;
242*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtlist;
243*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtstack;
244*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtqueue;
245*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtdeque;
246*b30d1939SAndy Fiddaman 
247*b30d1939SAndy Fiddaman #if _PACKAGE_ast /* dtplugin() for proprietary and non-standard methods -- requires -ldll */
248*b30d1939SAndy Fiddaman 
249*b30d1939SAndy Fiddaman #define dtplugin(name)	((Dtmethod_t*)dllmeth("cdt", name, CDT_PLUGIN_VERSION))
250*b30d1939SAndy Fiddaman 
251*b30d1939SAndy Fiddaman #define Dtrhbag		dtplugin("rehash:Dtrhbag")
252*b30d1939SAndy Fiddaman #define Dtrhset		dtplugin("rehash:Dtrhset")
253*b30d1939SAndy Fiddaman 
254*b30d1939SAndy Fiddaman #else
255*b30d1939SAndy Fiddaman 
256*b30d1939SAndy Fiddaman #if CDTPROPRIETARY
257*b30d1939SAndy Fiddaman 
258*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtrhset;
259*b30d1939SAndy Fiddaman extern Dtmethod_t*	Dtrhbag;
260*b30d1939SAndy Fiddaman 
261*b30d1939SAndy Fiddaman #endif /*CDTPROPRIETARY*/
262*b30d1939SAndy Fiddaman 
263*b30d1939SAndy Fiddaman #endif /*_PACKAGE_ast*/
264*b30d1939SAndy Fiddaman 
265*b30d1939SAndy Fiddaman #undef extern
266*b30d1939SAndy Fiddaman 
267*b30d1939SAndy Fiddaman #if _BLD_cdt && defined(__EXPORT__)
268*b30d1939SAndy Fiddaman #define extern	__EXPORT__
269*b30d1939SAndy Fiddaman #endif
270*b30d1939SAndy Fiddaman 
271*b30d1939SAndy Fiddaman extern Dt_t*		dtopen _ARG_((Dtdisc_t*, Dtmethod_t*));
272*b30d1939SAndy Fiddaman extern int		dtclose _ARG_((Dt_t*));
273*b30d1939SAndy Fiddaman extern Dt_t*		dtview _ARG_((Dt_t*, Dt_t*));
274*b30d1939SAndy Fiddaman extern Dtdisc_t*	dtdisc _ARG_((Dt_t* dt, Dtdisc_t*, int));
275*b30d1939SAndy Fiddaman extern Dtmethod_t*	dtmethod _ARG_((Dt_t*, Dtmethod_t*));
276*b30d1939SAndy Fiddaman extern int		dtwalk _ARG_((Dt_t*, int(*)(Dt_t*,Void_t*,Void_t*), Void_t*));
277*b30d1939SAndy Fiddaman extern int		dtcustomize _ARG_((Dt_t*, int, int));
278*b30d1939SAndy Fiddaman extern unsigned int	dtstrhash _ARG_((unsigned int, Void_t*, ssize_t));
279*b30d1939SAndy Fiddaman extern int		dtuserlock _ARG_((Dt_t*, unsigned int, int));
280*b30d1939SAndy Fiddaman extern Void_t*		dtuserdata _ARG_((Dt_t*, Void_t*, unsigned int));
281*b30d1939SAndy Fiddaman 
282*b30d1939SAndy Fiddaman /* deal with upward binary compatibility (operation bit translation, etc.) */
283*b30d1939SAndy Fiddaman extern Dt_t*		_dtopen _ARG_((Dtdisc_t*, Dtmethod_t*, unsigned long));
284*b30d1939SAndy Fiddaman #define dtopen(dc,mt)	_dtopen((dc), (mt), CDT_VERSION)
285*b30d1939SAndy Fiddaman 
286*b30d1939SAndy Fiddaman #undef extern
287*b30d1939SAndy Fiddaman 
288*b30d1939SAndy Fiddaman #if _PACKAGE_ast && !defined(_CDTLIB_H)
289*b30d1939SAndy Fiddaman 
290*b30d1939SAndy Fiddaman #if _BLD_dll && defined(__EXPORT__)
291*b30d1939SAndy Fiddaman #define extern	__EXPORT__
292*b30d1939SAndy Fiddaman #endif
293*b30d1939SAndy Fiddaman 
294*b30d1939SAndy Fiddaman extern void*		dllmeth(const char*, const char*, unsigned long);
295*b30d1939SAndy Fiddaman 
296*b30d1939SAndy Fiddaman #undef	extern
297*b30d1939SAndy Fiddaman 
298*b30d1939SAndy Fiddaman #endif
299*b30d1939SAndy Fiddaman 
300*b30d1939SAndy Fiddaman _END_EXTERNS_
301*b30d1939SAndy Fiddaman 
302*b30d1939SAndy Fiddaman /* internal functions for translating among holder, object and key */
303*b30d1939SAndy Fiddaman #define _DT(dt)		((Dt_t*)(dt))
304*b30d1939SAndy Fiddaman 
305*b30d1939SAndy Fiddaman #define _DTLNK(dc,o)	((Dtlink_t*)((char*)(o) + (dc)->link) ) /* get link from obj */
306*b30d1939SAndy Fiddaman 
307*b30d1939SAndy Fiddaman #define _DTO(dc,l)	(Void_t*)((char*)(l) - (dc)->link) /* get object from link */
308*b30d1939SAndy Fiddaman #define _DTOBJ(dc,l)	((dc)->link >= 0 ? _DTO(dc,l) : ((Dthold_t*)(l))->obj )
309*b30d1939SAndy Fiddaman 
310*b30d1939SAndy Fiddaman #define _DTK(dc,o)	((char*)(o) + (dc)->key) /* get key from object */
311*b30d1939SAndy Fiddaman #define _DTKEY(dc,o)	(Void_t*)((dc)->size >= 0 ? _DTK(dc,o) : *((char**)_DTK(dc,o)) )
312*b30d1939SAndy Fiddaman 
313*b30d1939SAndy Fiddaman #define _DTCMP(dt,k1,k2,dc) \
314*b30d1939SAndy Fiddaman 			((dc)->comparf  ? (*(dc)->comparf)((dt), (k1), (k2), (dc)) : \
315*b30d1939SAndy Fiddaman 			 (dc)->size > 0 ? memcmp((Void_t*)(k1), ((Void_t*)k2), (dc)->size) : \
316*b30d1939SAndy Fiddaman 					  strcmp((char*)(k1), ((char*)k2)) )
317*b30d1939SAndy Fiddaman 
318*b30d1939SAndy Fiddaman #define _DTHSH(dt,ky,dc) ((dc)->hashf   ? (*(dc)->hashf)((dt), (ky), (dc)) : \
319*b30d1939SAndy Fiddaman 					  dtstrhash(0, (ky), (dc)->size) )
320*b30d1939SAndy Fiddaman 
321*b30d1939SAndy Fiddaman #define dtvnext(d)	(_DT(d)->view)
322*b30d1939SAndy Fiddaman #define dtvcount(d)	(_DT(d)->nview)
323*b30d1939SAndy Fiddaman #define dtvhere(d)	(_DT(d)->walk)
324*b30d1939SAndy Fiddaman 
325*b30d1939SAndy Fiddaman #define dtlink(d,e)	(((Dtlink_t*)(e))->rh.__rght)
326*b30d1939SAndy Fiddaman #define dtobj(d,e)	_DTOBJ(_DT(d)->disc, (e))
327*b30d1939SAndy Fiddaman 
328*b30d1939SAndy Fiddaman #define dtfirst(d)	(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_FIRST)
329*b30d1939SAndy Fiddaman #define dtnext(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_NEXT)
330*b30d1939SAndy Fiddaman #define dtatleast(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_ATLEAST)
331*b30d1939SAndy Fiddaman #define dtlast(d)	(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_LAST)
332*b30d1939SAndy Fiddaman #define dtprev(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_PREV)
333*b30d1939SAndy Fiddaman #define dtatmost(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_ATMOST)
334*b30d1939SAndy Fiddaman #define dtsearch(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_SEARCH)
335*b30d1939SAndy Fiddaman #define dtmatch(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_MATCH)
336*b30d1939SAndy Fiddaman #define dtinsert(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_INSERT)
337*b30d1939SAndy Fiddaman #define dtappend(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_APPEND)
338*b30d1939SAndy Fiddaman #define dtdelete(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_DELETE)
339*b30d1939SAndy Fiddaman #define dtremove(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_REMOVE)
340*b30d1939SAndy Fiddaman #define dtattach(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_ATTACH)
341*b30d1939SAndy Fiddaman #define dtdetach(d,o)	(*(_DT(d)->searchf))((d),(Void_t*)(o),DT_DETACH)
342*b30d1939SAndy Fiddaman #define dtclear(d)	(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_CLEAR)
343*b30d1939SAndy Fiddaman 
344*b30d1939SAndy Fiddaman #define dtflatten(d)	(Dtlink_t*)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_FLATTEN)
345*b30d1939SAndy Fiddaman #define dtextract(d)	(Dtlink_t*)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_EXTRACT)
346*b30d1939SAndy Fiddaman #define dtrestore(d,l)	(Dtlink_t*)(*(_DT(d)->searchf))((d),(Void_t*)(l),DT_RESTORE)
347*b30d1939SAndy Fiddaman 
348*b30d1939SAndy Fiddaman #define dtstat(d,s)	(ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(s),DT_STAT)
349*b30d1939SAndy Fiddaman #define dtsize(d)	(ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_STAT)
350*b30d1939SAndy Fiddaman 
351*b30d1939SAndy Fiddaman #define DT_PRIME	17109811 /* 2#00000001 00000101 00010011 00110011 */
352*b30d1939SAndy Fiddaman #define dtcharhash(h,c) (((unsigned int)(h) + (unsigned int)(c)) * DT_PRIME )
353*b30d1939SAndy Fiddaman 
354*b30d1939SAndy Fiddaman #endif /* _CDT_H */