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 Dtlink_t *dtflatten(Dt_t * dt)
00031 #else
00032 Dtlink_t *dtflatten(dt)
00033 Dt_t *dt;
00034 #endif
00035 {
00036 reg Dtlink_t *t, *r, *list, *last, **s, **ends;
00037
00038
00039 if (dt->data->type & DT_FLATTEN)
00040 return dt->data->here;
00041
00042 list = last = NIL(Dtlink_t *);
00043 if (dt->data->type & (DT_SET | DT_BAG)) {
00044 for (ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s) {
00045 if ((t = *s)) {
00046 if (last)
00047 last->right = t;
00048 else
00049 list = last = t;
00050 while (last->right)
00051 last = last->right;
00052 *s = last;
00053 }
00054 }
00055 } else if (dt->data->type & (DT_LIST | DT_STACK | DT_QUEUE))
00056 list = dt->data->head;
00057 else if ((r = dt->data->here)) {
00058 while ((t = r->left))
00059 RROTATE(r, t);
00060 for (list = last = r, r = r->right; r; last = r, r = r->right) {
00061 if ((t = r->left)) {
00062 do
00063 RROTATE(r, t);
00064 while ((t = r->left));
00065
00066 last->right = r;
00067 }
00068 }
00069 }
00070
00071 dt->data->here = list;
00072 dt->data->type |= DT_FLATTEN;
00073
00074 return list;
00075 }