fast creating a graph from a text file in c++ -


i want make graph text file containing 36692 nodes , each line of text contains source , target node of edge of graph. used igraph library create graph. wrote following code slow. how can improve it?

  igraph_empty(&graph, 36692, 0);   ifstream inputfile("email-enron.txt");   string line;    while (getline(inputfile, line))   {         istringstream ss(line);                int v1, v2;         ss >>  v1 >> v2 ;         igraph_add_edge(&graph, v1, v2);    } 

if file read bottleneck (which should profile), i'd suggest rid of superfluous stringstream variable.

if each line contains 2 numbers , nothing else, reading in numbers pairwise directly stream works well, because operator >> treats new line white space , ignores same way ignores blanks:

  igraph_empty(&graph, 36692, 0);   ifstream inputfile("email-enron.txt");    int v1, v2;   while ( (inputfile >>  v1 >> v2) ) {         igraph_add_edge(&graph, v1, v2);   } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -