00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "dthdr.h"
00018
00019 #ifdef DMALLOC
00020 #include "dmalloc.h"
00021 #endif
00022
00023
00024
00025
00026
00027
00028
00029 #if __STD_C
00030 static Void_t *dtvsearch(Dt_t * dt, reg Void_t * obj, reg int type)
00031 #else
00032 static Void_t *dtvsearch(dt, obj, type)
00033 Dt_t *dt;
00034 reg Void_t *obj;
00035 reg int type;
00036 #endif
00037 {
00038 reg Dt_t *d, *p;
00039 reg Void_t *o;
00040 reg Dtdisc_t *disc;
00041 reg Dtlink_t *here;
00042
00043
00044 if (type & (DT_INSERT | DT_DELETE | DT_CLEAR | DT_RENEW))
00045 return (*(dt->meth->searchf)) (dt, obj, type);
00046
00047 if (!obj && !(type & (DT_FIRST | DT_LAST)))
00048 return NIL(Void_t *);
00049
00050 if (type & (DT_MATCH | DT_SEARCH | DT_FIRST | DT_LAST)) {
00051 for (d = dt; d; d = d->view) {
00052 if ((o = (*(d->meth->searchf)) (d, obj, type))) {
00053 dt->walk = d;
00054 return o;
00055 }
00056 }
00057
00058 dt->walk = NIL(Dt_t *);
00059 return NIL(Void_t *);
00060 }
00061
00062
00063 if (!dt->walk || !(here = dt->walk->data->here) ||
00064 obj != OBJ(here, dt->walk->disc->link)) {
00065 for (d = dt; d; d = d->view) {
00066 if ((o = (*(d->meth->searchf)) (d, obj, DT_SEARCH))) {
00067 dt->walk = d;
00068 goto do_adj;
00069 }
00070 }
00071
00072 dt->walk = NIL(Dt_t *);
00073 return NIL(Void_t *);
00074 }
00075
00076 do_adj:for (d = dt->walk, o = (*(d->meth->searchf)) (d, obj, type);;)
00077 {
00078 while (o) {
00079 disc = d->disc;
00080 here = (d->meth->type & (DT_SET | DT_BAG)) ?
00081 d->data->here : NIL(Dtlink_t *);
00082
00083 for (p = dt;; p = p->view) {
00084 reg Dtdisc_t *dc;
00085
00086 if (p == d)
00087 return o;
00088
00089
00090 if (here && (p->meth->type & (DT_SET | DT_BAG)) &&
00091 (disc == (dc = p->disc) ||
00092 (disc->key == dc->key && disc->size == dc->size &&
00093 disc->link == dc->link && disc->hashf == dc->hashf)))
00094 {
00095 if ((*(p->meth->searchf)) (p, here, DT_VSEARCH))
00096 break;
00097 } else {
00098 if ((*(p->meth->searchf)) (p, o, DT_SEARCH))
00099 break;
00100 }
00101 }
00102
00103 o = (*(d->meth->searchf)) (d, o, type);
00104 }
00105
00106 if (!(d = dt->walk = d->view))
00107 return NIL(Void_t *);
00108
00109 if (type & DT_NEXT)
00110 o = (*(d->meth->searchf)) (d, NIL(Void_t *), DT_FIRST);
00111 else
00112 o = (*(d->meth->searchf)) (d, NIL(Void_t *), DT_LAST);
00113 }
00114 }
00115
00116 #if __STD_C
00117 Dt_t *dtview(reg Dt_t * dt, reg Dt_t * view)
00118 #else
00119 Dt_t *dtview(dt, view)
00120 reg Dt_t *dt;
00121 reg Dt_t *view;
00122 #endif
00123 {
00124 reg Dt_t *d;
00125
00126 UNFLATTEN(dt);
00127 if (view)
00128 UNFLATTEN(view);
00129
00130
00131 for (d = view; d; d = d->view)
00132 if (d == dt)
00133 return NIL(Dt_t *);
00134
00135
00136 if ((d = dt->view))
00137 d->nview -= 1;
00138 dt->view = dt->walk = NIL(Dt_t *);
00139
00140 if (!view) {
00141 dt->searchf = dt->meth->searchf;
00142 return d;
00143 }
00144
00145
00146 dt->view = view;
00147 dt->searchf = dtvsearch;
00148 view->nview += 1;
00149
00150 return view;
00151 }