<commit_before>/*
 * METISGraphWriter.cpp
 *
 *  Created on: 30.01.2013
 *      Author: <NAME> (<EMAIL>)
 */

#include "METISGraphWriter.h"

#include "../auxiliary/Enforce.h"

namespace NetworKit {

void METISGraphWriter::write(Graph& G, const std::string& path) {
	this->write(G, G.isWeighted(), path);
}
void METISGraphWriter::write(Graph& G, bool weighted, std::string path) {
	if (G.isDirected()) {
		throw std::invalid_argument{"METIS does not support directed graphs"};
	}
	std::ofstream file(path);
	Aux::enforceOpened(file);

	count n = G.numberOfNodes();
	count m = G.numberOfEdges();

	file << n << " " << m << " " << int{weighted} << '\n';

	if (weighted == false) {
		G.forNodes([&](node u) {
			G.forNeighborsOf(u, [&](node v){
				file << v + 1 << " ";
			});
			file << '\n';
		});
	} else {
			G.forNodes([&](node u) {
			G.forNeighborsOf(u, [&](node v){
				file << v + 1 << " " << G.weight(u, v) <<"\t";
			});
			file << '\n';
		});
	}
}

} /* namespace NetworKit */
<commit_msg>METISGraphWriter: improve performance by not using Graph::weight()<commit_after>/*
 * METISGraphWriter.cpp
 *
 *  Created on: 30.01.2013
 *      Author: <NAME> (<EMAIL>)
 */

#include "METISGraphWriter.h"

#include "../auxiliary/Enforce.h"

namespace NetworKit {

void METISGraphWriter::write(Graph& G, const std::string& path) {
	this->write(G, G.isWeighted(), path);
}
void METISGraphWriter::write(Graph& G, bool weighted, std::string path) {
	if (G.isDirected()) {
		throw std::invalid_argument{"METIS does not support directed graphs"};
	}
	std::ofstream file(path);
	Aux::enforceOpened(file);

	count n = G.numberOfNodes();
	count m = G.numberOfEdges();

	file << n << " " << m << " " << int{weighted} << '\n';

	if (weighted == false) {
		G.forNodes([&](node u) {
			G.forNeighborsOf(u, [&](node v){
				file << v + 1 << " ";
			});
			file << '\n';
		});
	} else {
			G.forNodes([&](node u) {
			G.forNeighborsOf(u, [&](node v, edgeweight w){
				file << v + 1 << " " << w <<"\t";
			});
			file << '\n';
		});
	}
}

} /* namespace NetworKit */

{'fraction_non_alphanumeric': 0.21658536585365853, 'fraction_numerical': 0.00975609756097561, 'mean_word_length': 3.4490238611713666, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1197267', 'n_tokens_mistral': 878, 'n_tokens_neox': 782, 'n_words': 171}