~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to cdt/dtflatten.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This software may only be used by you under license from AT&T Corp.
 
3
    ("AT&T").  A copy of AT&T's Source Code Agreement is available at
 
4
    AT&T's Internet website having the URL:
 
5
    <http://www.research.att.com/sw/tools/graphviz/license/source.html>
 
6
    If you received this software without first entering into a license
 
7
    with AT&T, you have an infringing copy of this software and cannot use
 
8
    it without violating AT&T's intellectual property rights.
 
9
*/
 
10
#include        "dthdr.h"
 
11
 
 
12
#ifdef DMALLOC
 
13
#include "dmalloc.h"
 
14
#endif
 
15
 
 
16
/*      Flatten a dictionary into a linked list.
 
17
**      This may be used when many traversals are likely.
 
18
**
 
19
**      Written by Kiem-Phong Vo (5/25/96).
 
20
*/
 
21
 
 
22
#if __STD_C
 
23
Dtlink_t* dtflatten(Dt_t* dt)
 
24
#else
 
25
Dtlink_t* dtflatten(dt)
 
26
Dt_t*   dt;
 
27
#endif
 
28
{
 
29
        reg Dtlink_t    *t, *r, *list, *last, **s, **ends;
 
30
 
 
31
        /* already flattened */
 
32
        if(dt->data->type&DT_FLATTEN )
 
33
                return dt->data->here;
 
34
 
 
35
        list = last = NIL(Dtlink_t*);
 
36
        if(dt->data->type&(DT_SET|DT_BAG))
 
37
        {       for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
 
38
                {       if((t = *s) )
 
39
                        {       if(last)
 
40
                                        last->right = t;
 
41
                                else    list = last = t;
 
42
                                while(last->right)
 
43
                                        last = last->right;
 
44
                                *s = last;
 
45
                        }
 
46
                }
 
47
        }
 
48
        else if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE) )
 
49
                list = dt->data->head;
 
50
        else if((r = dt->data->here) ) /*if(dt->data->type&(DT_OSET|DT_OBAG))*/
 
51
        {       while((t = r->left) )
 
52
                        RROTATE(r,t);
 
53
                for(list = last = r, r = r->right; r; last = r, r = r->right)
 
54
                {       if((t = r->left) )
 
55
                        {       do      RROTATE(r,t);
 
56
                                while((t = r->left) );
 
57
 
 
58
                                last->right = r;
 
59
                        }
 
60
                }
 
61
        }
 
62
 
 
63
        dt->data->here = list;
 
64
        dt->data->type |= DT_FLATTEN;
 
65
 
 
66
        return list;
 
67
}