| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include <cdt/dthdr.h> |
| 4 |
#include <stddef.h> |
| 5 |
|
| 6 |
/* Flatten a dictionary into a linked list. |
| 7 |
** This may be used when many traversals are likely. |
| 8 |
** |
| 9 |
** Written by Kiem-Phong Vo (5/25/96). |
| 10 |
*/ |
| 11 |
|
| 12 |
Dtlink_t* dtflatten(Dt_t* dt) |
| 13 |
{ |
| 14 |
Dtlink_t *t, *r, *list, *last, **s, **ends; |
| 15 |
|
| 16 |
/* already flattened */ |
| 17 |
if (dt->data.type & DT_FLATTEN ) |
| 18 |
return dt->data.here; |
| 19 |
|
| 20 |
list = last = NULL; |
| 21 |
if (dt->data.type & DT_SET) |
| 22 |
{ for (ends = (s = dt->data.htab) + dt->data.ntab; s < ends; ++s) |
| 23 |
{ if((t = *s) ) |
| 24 |
{ if(last) |
| 25 |
last->right = t; |
| 26 |
else list = last = t; |
| 27 |
while(last->right) |
| 28 |
last = last->right; |
| 29 |
*s = last; |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
else if ((r = dt->data.here)) // if (dt->data.type & (DT_OSET|DT_OBAG)) |
| 34 |
{ while((t = r->left) ) |
| 35 |
RROTATE(r,t); |
| 36 |
for(list = last = r, r = r->right; r; last = r, r = r->right) |
| 37 |
{ if((t = r->left) ) |
| 38 |
{ do RROTATE(r,t); |
| 39 |
while((t = r->left) ); |
| 40 |
|
| 41 |
last->right = r; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
dt->data.here = list; |
| 47 |
dt->data.type |= DT_FLATTEN; |
| 48 |
|
| 49 |
return list; |
| 50 |
} |