use CldCountTokens instead of CldLoad() to estimate the current load. CldLoad() has...
[charm.git] / src / conv-ldb / edgelist.c
1 /*****************************************************************************
2  * $Source$
3  * $Author$
4  * $Date$
5  * $Revision$
6  *****************************************************************************/
7
8 /* The data structure/ ADT for the edge-list */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "graphdefs.h"
12
13 /*extern VerticesListType graph; */
14
15 void * InitEdgeList(int E)
16 {
17   EdgeListType * edgesRec;
18
19   edgesRec = (EdgeListType *) malloc(sizeof(EdgeListType));
20   _MEMCHECK(edgesRec);
21   edgesRec->next = 0;
22   edgesRec->edges = (Edge *) malloc(E*sizeof(Edge));
23   _MEMCHECK(edgesRec->edges);
24   return(edgesRec);
25 }
26
27 void addEdge(VerticesListType *graph, EdgeListType * EdgeList, int v, int w)
28 {
29   int n, index;
30   n = EdgeList->next;
31   EdgeList->next++;
32
33   /* printf("adding edge: (%d, %d)\n", v, w); */
34   ((EdgeList->edges)[n]).node1 = v;
35   (EdgeList->edges[n]).node2 = w;
36    index =  graph->vertexArray[v].next++;
37    graph->adjArray[ index ] = w;
38    index =  graph->vertexArray[w].next++;
39    graph->adjArray[ index ] = v;
40
41    graph->vertexArray[v].degree++;
42    graph->vertexArray[w].degree++;
43 }
44
45 void printEdges(EdgeListType *EdgeList)
46 {
47  int i;
48  Edge * edges;
49  edges = EdgeList->edges;
50  for (i=0; i< (EdgeList->next ); i++)
51    {printf("%d\t%d\n", edges[i].node1, edges[i].node2);
52   }
53 }
54
55 int edgeExists(VerticesListType *graph, int x, int y)
56 {
57   int i, ind;
58   ind = graph->vertexArray[x].adjListInd; 
59   
60   for(i=0; i< graph->vertexArray[x].degree; i++)
61     { if (graph->adjArray[ind + i] == y) return 1;}
62   
63   return 0;
64 }
65
66 /*
67   If we are adding an edge between two nodes already connected then we 
68   need special changes. We open some distinct edge say x,y and 
69   connect v with y and x with w
70 */
71
72 void addspEdge(VerticesListType *graph, EdgeListType * EdgeList, int v, int w)
73
74   int n, index,i,x,y,ind;
75   n = EdgeList->next;
76   EdgeList->next++;
77
78   /* printf("adding edge: (%d, %d)\n", v, w); */
79   /*((EdgeList->edges)[n]).node1 = v;*/
80   /*(EdgeList->edges[n]).node2 = w;*/
81    for (i=0;i<n-1;i++)
82      if (((EdgeList->edges[i]).node1!=v) && ((EdgeList->edges[i]).node2!=w)) 
83         {
84             x=(EdgeList->edges[i]).node1;
85             y=(EdgeList->edges[i]).node2;       
86             (EdgeList->edges[i]).node2=w;
87             (EdgeList->edges[n]).node1=v;
88             (EdgeList->edges[n]).node2=y;       
89
90             
91             ind =  graph->vertexArray[x].adjListInd;
92             for(i=0; i< graph->vertexArray[x].degree; i++)
93                     { if (graph->adjArray[ind + i] == y) graph->adjArray[ind+i]=w;}
94
95             ind =  graph->vertexArray[y].adjListInd;
96             for(i=0; i< graph->vertexArray[y].degree; i++)
97                     { if (graph->adjArray[ind + i] == x) graph->adjArray[ind+i]=y;}
98         
99             index =  graph->vertexArray[v].next++;
100             graph->adjArray[ index ] = y;
101             index =  graph->vertexArray[w].next++;
102             graph->adjArray[ index ] = x;
103             graph->vertexArray[v].degree++;
104             graph->vertexArray[w].degree++;
105             break;
106          
107         }
108 }
109