*** empty log message ***
[charm.git] / src / conv-ldb / edgelist.c
1 /* The data structure/ ADT for the edge-list */
2
3 #include "typedefs.h"
4
5 extern VerticesListType graph;
6
7 void * InitEdgeList(E)
8 int E;
9 {
10   EdgeListType * edgesRec;
11
12   edgesRec = (EdgeListType *) malloc(sizeof(EdgeListType));
13   edgesRec->next = 0;
14   edgesRec->edges = (Edge *) malloc(E*sizeof(Edge));
15   return(edgesRec);
16 }
17
18 addEdge(EdgeList, v,w)
19      EdgeListType * EdgeList;
20      int v;
21      int w;
22 { int n, index;
23   n = EdgeList->next;
24   EdgeList->next++;
25
26   /* printf("adding edge: (%d, %d)\n", v, w); */
27   ((EdgeList->edges)[n]).node1 = v;
28   (EdgeList->edges[n]).node2 = w;
29    index =  graph.vertexArray[v].next++;
30    graph.adjArray[ index ] = w;
31    index =  graph.vertexArray[w].next++;
32    graph.adjArray[ index ] = v;
33
34    graph.vertexArray[v].degree++;
35    graph.vertexArray[w].degree++;
36 }
37
38 printEdges(EdgeList)
39      EdgeListType * EdgeList;
40 {int i;
41  Edge * edges;
42  edges = EdgeList->edges;
43  for (i=0; i< (EdgeList->next ); i++)
44    {printf("%d\t%d\n", edges[i].node1, edges[i].node2);
45   }
46 }
47
48 int edgeExists(x,y)
49 {
50   int deg, i, ind;
51   ind = graph.vertexArray[x].adjListInd; 
52   
53   for(i=0; i< graph.vertexArray[x].degree; i++)
54     { if (graph.adjArray[ind + i] == y) return 1;}
55   
56   return 0;
57 }