dbd9d51824b0482e27a9b68cd12a9d4d440feb5f
[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   _MEMCHECK(edgesRec);
14   edgesRec->next = 0;
15   edgesRec->edges = (Edge *) malloc(E*sizeof(Edge));
16   _MEMCHECK(edgesRec->edges);
17   return(edgesRec);
18 }
19
20 void addEdge(EdgeList, v,w)
21      EdgeListType * EdgeList;
22      int v;
23      int w;
24 { int n, index;
25   n = EdgeList->next;
26   EdgeList->next++;
27
28   /* printf("adding edge: (%d, %d)\n", v, w); */
29   ((EdgeList->edges)[n]).node1 = v;
30   (EdgeList->edges[n]).node2 = w;
31    index =  graph.vertexArray[v].next++;
32    graph.adjArray[ index ] = w;
33    index =  graph.vertexArray[w].next++;
34    graph.adjArray[ index ] = v;
35
36    graph.vertexArray[v].degree++;
37    graph.vertexArray[w].degree++;
38 }
39
40 void printEdges(EdgeList)
41      EdgeListType * EdgeList;
42 {int i;
43  Edge * edges;
44  edges = EdgeList->edges;
45  for (i=0; i< (EdgeList->next ); i++)
46    {printf("%d\t%d\n", edges[i].node1, edges[i].node2);
47   }
48 }
49
50 int edgeExists(x,y)
51 {
52   int i, ind;
53   ind = graph.vertexArray[x].adjListInd; 
54   
55   for(i=0; i< graph.vertexArray[x].degree; i++)
56     { if (graph.adjArray[ind + i] == y) return 1;}
57   
58   return 0;
59 }