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

« back to all changes in this revision

Viewing changes to fdp/component.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
/* component.c
 
2
 */
 
3
 
 
4
#include "structs.h"
 
5
#include "component.h"
 
6
 
 
7
#ifdef DMALLOC
 
8
#include "dmalloc.h"
 
9
#endif
 
10
 
 
11
static Agnode_t*  
 
12
getRoot (Agnode_t* n)
 
13
{
 
14
    Agnode_t*  root = n;
 
15
    Agnode_t*  pp;
 
16
 
 
17
    while ((pp = rootOf(root)) != 0) root = pp;
 
18
    for (; n != root; n = pp) {
 
19
      pp = rootOf(n);
 
20
      rootOf(n) = root;
 
21
    }
 
22
    return root;
 
23
}
 
24
 
 
25
int 
 
26
sameComponent (Agnode_t* p, Agnode_t* q)
 
27
{
 
28
    return (getRoot(p) == getRoot(q));
 
29
}
 
30
 
 
31
void 
 
32
merge (Agnode_t* p, Agnode_t* q)
 
33
{
 
34
    Agnode_t*  rootp;
 
35
    Agnode_t*  rootq;
 
36
 
 
37
    rootp = getRoot (p);
 
38
    rootq = getRoot (q);
 
39
    if (rootp != rootq) {
 
40
      if (sizeOf(rootp) > sizeOf(rootq)) {
 
41
        rootOf(rootq) = rootp;
 
42
        sizeOf(rootp) += sizeOf(rootq);
 
43
      }
 
44
      else {
 
45
        rootOf(rootp) = rootq;
 
46
        sizeOf(rootq) += sizeOf(rootp);
 
47
      }
 
48
    }
 
49
}