1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
28 ** Written by Kiem-Phong Vo (5/26/96)
32 static Void_t
* dtmemory(Dt_t
* dt
,Void_t
* addr
,size_t size
,Dtdisc_t
* disc
)
34 static Void_t
* dtmemory(dt
, addr
, size
, disc
)
35 Dt_t
* dt
; /* dictionary */
36 Void_t
* addr
; /* address to be manipulate */
37 size_t size
; /* size to obtain */
38 Dtdisc_t
* disc
; /* discipline */
46 else return realloc(addr
,size
);
48 else return size
> 0 ? malloc(size
) : NIL(Void_t
*);
52 Dtdisc_t
* dtdisc(Dt_t
* dt
, Dtdisc_t
* disc
, int type
)
54 Dtdisc_t
* dtdisc(dt
,disc
,type
)
60 reg Dtsearch_f searchf
;
65 if(!(old
= dt
->disc
) ) /* initialization call from dtopen() */
67 if(!(dt
->memoryf
= disc
->memoryf
) )
68 dt
->memoryf
= dtmemory
;
72 if(!disc
) /* only want to know current discipline */
75 searchf
= dt
->meth
->searchf
;
79 if(old
->eventf
&& (*old
->eventf
)(dt
,DT_DISC
,(Void_t
*)disc
,old
) < 0)
80 return NIL(Dtdisc_t
*);
83 if(!(dt
->memoryf
= disc
->memoryf
) )
84 dt
->memoryf
= dtmemory
;
86 if(dt
->data
->type
&(DT_STACK
|DT_QUEUE
|DT_LIST
))
88 else if(dt
->data
->type
&DT_BAG
)
89 { if(type
&DT_SAMEHASH
)
93 else if(dt
->data
->type
&(DT_SET
|DT_BAG
))
94 { if((type
&DT_SAMEHASH
) && (type
&DT_SAMECMP
))
98 else /*if(dt->data->type&(DT_OSET|DT_OBAG))*/
103 dt
->data
->type
&= ~DT_FLATTEN
;
104 dt
->data
->here
= NIL(Dtlink_t
*);
107 if(dt
->data
->type
&(DT_SET
|DT_BAG
))
108 { reg Dtlink_t
**s
, **ends
;
109 ends
= (s
= dt
->data
->htab
) + dt
->data
->ntab
;
111 *s
++ = NIL(Dtlink_t
*);
117 if(!(type
&DT_SAMEHASH
)) /* new hash value */
118 { k
= (char*)_DTOBJ(r
,disc
->link
);
119 k
= _DTKEY((Void_t
*)k
,disc
->key
,disc
->size
);
120 r
->hash
= _DTHSH(dt
,k
,disc
,disc
->size
);
122 (void)(*searchf
)(dt
,(Void_t
*)r
,DT_RENEW
);