PandA-2024.02
load_graph.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <assert.h>
7 #include "simple_API.h"
8 
9 void
10 loadGraph(char * InVertexFileName, char * OutVertexFileName, char * InEdgeFileName, char * OutEdgeFileName)
11 {
12  int IVF, OVF, IEF, OEF;
13 
14  IVF = open(InVertexFileName, O_RDONLY);
15  assert(IVF != -1);
16  OVF = open(OutVertexFileName, O_RDONLY);
17  assert(OVF != -1);
18  IEF = open(InEdgeFileName, O_RDONLY);
19  assert(IEF != -1);
20  OEF = open(OutEdgeFileName, O_RDONLY);
21  assert(OEF != -1);
22 
23  unsigned int vertexNumber, secondvertexNumber;
24  unsigned int inEdgeNumber;
25  unsigned int outEdgeNumber;
26  unsigned bytes_read;
27  bytes_read = read(IVF, &vertexNumber, sizeof(unsigned int));
28  assert(bytes_read == sizeof(unsigned int));
29  bytes_read = read(OVF, &secondvertexNumber, sizeof(unsigned int));
30  assert(secondvertexNumber == vertexNumber);
31  assert(bytes_read == sizeof(unsigned int));
32 
33  bytes_read = read(IEF, &inEdgeNumber, sizeof(unsigned int));
34  assert(bytes_read == sizeof(unsigned int));
35  bytes_read = read(OEF, &outEdgeNumber, sizeof(unsigned int));
36  assert(bytes_read == sizeof(unsigned int));
37 
38  TheGraph.numVertices = vertexNumber - 1;
39  printf("VertexNumber : %lu\n", TheGraph.numVertices);
40  printf("InEdgeNumber : %d\n", inEdgeNumber);
41  printf("outEdgeNumber : %d\n", outEdgeNumber);
42 
43  bytes_read = read(IVF, TheGraph.inEdgesIDs, sizeof(TheGraph.inEdgesIDs[0]) * (TheGraph.numVertices + 1));
44  assert(bytes_read == sizeof(TheGraph.inEdgesIDs[0]) * (TheGraph.numVertices + 1));
45  bytes_read = read(OVF, TheGraph.outEdgesIDs, sizeof(TheGraph.outEdgesIDs[0]) * (TheGraph.numVertices + 1));
46  assert(bytes_read == sizeof(TheGraph.outEdgesIDs[0]) * (TheGraph.numVertices + 1));
47 
48  bytes_read = read(IEF, TheGraph.inEdges, sizeof(Edge) * inEdgeNumber);
49  assert(bytes_read == sizeof(Edge) * inEdgeNumber);
50  bytes_read = read(OEF, TheGraph.outEdges, sizeof(Edge) * outEdgeNumber);
51  assert(bytes_read == sizeof(Edge) * outEdgeNumber);
52 
53  printf("Graph Loading Completed!\n");
54 
55  close(IVF);
56  close(OVF);
57  close(IEF);
58  close(OEF);
59 }
60 
EdgeId inEdgesIDs[MAX_VERTEX_NUMBER]
Definition: simple_API.h:33
Edge outEdges[MAX_EDGE_NUMBER]
Definition: simple_API.h:36
Graph TheGraph
Definition: data.c:7
Edge inEdges[MAX_EDGE_NUMBER]
Definition: simple_API.h:35
size_t numVertices
Definition: simple_API.h:30
void loadGraph(char *InVertexFileName, char *OutVertexFileName, char *InEdgeFileName, char *OutEdgeFileName)
Definition: load_graph.c:10
EdgeId outEdgesIDs[MAX_VERTEX_NUMBER]
Definition: simple_API.h:32
short int read(short int *data)
Definition: read.c:3

Generated on Mon Feb 12 2024 13:02:47 for PandA-2024.02 by doxygen 1.8.13