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 ***********************************************************************/
24 /* Set a view path from dict to view.
26 ** Written by Kiem-Phong Vo (5/25/96)
31 static Void_t
* dtvsearch(Dt_t
* dt
, reg Void_t
* obj
, reg
int type
)
33 static Void_t
* dtvsearch(dt
,obj
,type
)
40 Void_t
*o
, *n
, *ok
, *nk
;
44 /* these operations only happen at the top level */
45 if(type
&(DT_INSERT
|DT_DELETE
|DT_CLEAR
|DT_RENEW
))
46 return (*(dt
->meth
->searchf
))(dt
,obj
,type
);
48 if((type
&(DT_MATCH
|DT_SEARCH
)) || /* order sets first/last done below */
49 ((type
&(DT_FIRST
|DT_LAST
)) && !(dt
->meth
->type
&(DT_OBAG
|DT_OSET
)) ) )
50 { for(d
= dt
; d
; d
= d
->view
)
51 if((o
= (*(d
->meth
->searchf
))(d
,obj
,type
)) )
57 if(dt
->meth
->type
& (DT_OBAG
|DT_OSET
) )
58 { if(!(type
& (DT_FIRST
|DT_LAST
|DT_NEXT
|DT_PREV
)) )
61 n
= nk
= NIL(Void_t
*); p
= NIL(Dt_t
*);
62 for(d
= dt
; d
; d
= d
->view
)
63 { if(!(o
= (*d
->meth
->searchf
)(d
, obj
, type
)) )
65 _DTDSC(d
->disc
,ky
,sz
,lk
,cmpf
);
68 if(n
) /* get the right one among all dictionaries */
69 { cmp
= _DTCMP(d
,ok
,nk
,d
->disc
,cmpf
,sz
);
70 if(((type
& (DT_NEXT
|DT_FIRST
)) && cmp
< 0) ||
71 ((type
& (DT_PREV
|DT_LAST
)) && cmp
> 0) )
74 else /* looks good for now */
85 /* non-ordered methods */
86 if(!(type
& (DT_NEXT
|DT_PREV
)) )
89 if(!dt
->walk
|| obj
!= _DTOBJ(dt
->walk
->data
->here
, dt
->walk
->disc
->link
) )
90 { for(d
= dt
; d
; d
= d
->view
)
91 if((o
= (*(d
->meth
->searchf
))(d
, obj
, DT_SEARCH
)) )
98 for(d
= dt
->walk
, obj
= (*d
->meth
->searchf
)(d
, obj
, type
);; )
99 { while(obj
) /* keep moving until finding an uncovered object */
100 { for(p
= dt
; ; p
= p
->view
)
101 { if(p
== d
) /* adjacent object is uncovered */
103 if((*(p
->meth
->searchf
))(p
, obj
, DT_SEARCH
) )
106 obj
= (*d
->meth
->searchf
)(d
, obj
, type
);
109 if(!(d
= dt
->walk
= d
->view
) ) /* move on to next dictionary */
111 else if(type
&DT_NEXT
)
112 obj
= (*(d
->meth
->searchf
))(d
,NIL(Void_t
*),DT_FIRST
);
113 else obj
= (*(d
->meth
->searchf
))(d
,NIL(Void_t
*),DT_LAST
);
118 Dt_t
* dtview(reg Dt_t
* dt
, reg Dt_t
* view
)
120 Dt_t
* dtview(dt
,view
)
130 if(view
->meth
!= dt
->meth
) /* must use the same method */
134 /* make sure there won't be a cycle */
135 for(d
= view
; d
; d
= d
->view
)
139 /* no more viewing lower dictionary */
142 dt
->view
= dt
->walk
= NIL(Dt_t
*);
145 { dt
->searchf
= dt
->meth
->searchf
;
151 dt
->searchf
= dtvsearch
;