<commit_before>#include <algorithm>
#include "kruskal.hpp"

UnionFind::UnionFind(std::vector<Node *> &nodes, std::vector<Edge *> &edges) {
	this->nodes = nodes;
	this->edges = edges;
	for (std::vector<Node *>::iterator it = nodes.begin(); it != nodes.end();
			it++) {
		ufTable[(*it)] = *it;
	}
}

UnionFind::~UnionFind() {

}

bool UnionFind::join(Node *nodeA, Node *nodeB) {
	Node *a = find(nodeA);
	Node *b = find(nodeB);

	// Reference comparison, we want to know if they are the same object
	if (a == b)
		return false;

	if (a->rank > b->rank) {
		std::swap(a, b);
	}

	// if both are equal, the combined tree becomes 1 deeper
	if (a->rank == b->rank)
		b->rank++;

	ufTable[a] = b;
	return true;
}

Node *UnionFind::find(Node *node) {
	if (ufTable[node] != ufTable[ufTable[node]]) {
		ufTable[node] = find(ufTable[node]);
	}
	return ufTable[node];
}

Kruskal::Kruskal(std::vector<Node *> &nodes, std::vector<Edge *> &edges) :
		uf(nodes, edges), nodes(nodes), edges(edges) {
	solved = false;
}

bool Kruskal::sortFunction(Edge* first, Edge* second) {
	return first->getWeight() < second->getWeight();
}

std::vector<Edge *> Kruskal::getEdges() {
	if (!solved) {
		solve();
	}
	return mst;
}

float Kruskal::solve() {
	solved = true;
	std::sort(edges.begin(), edges.end(), sortFunction);

	int treeCount = nodes.size();
	float weight = 0;

	for (unsigned int i = 0; i < nodes.size() && treeCount > 1; i++) {
		if (uf.join(edges[i]->a, edges[i]->b)) {
			treeCount--;
			weight += edges[i]->getWeight();

			// Save the edge, it may be useful for the user
			mst.push_back(edges[i]);
		}
	}

	return weight;
}<commit_msg>Fixed a bug<commit_after>#include <algorithm>
#include "kruskal.hpp"

UnionFind::UnionFind(std::vector<Node *> &nodes, std::vector<Edge *> &edges) {
	this->nodes = nodes;
	this->edges = edges;
	for (std::vector<Node *>::iterator it = nodes.begin(); it != nodes.end();
			it++) {
		ufTable[(*it)] = *it;
	}
}

UnionFind::~UnionFind() {

}

bool UnionFind::join(Node *nodeA, Node *nodeB) {
	Node *a = find(nodeA);
	Node *b = find(nodeB);

	// Reference comparison, we want to know if they are the same object
	if (a == b)
		return false;

	if (a->rank > b->rank) {
		std::swap(a, b);
	}

	// if both are equal, the combined tree becomes 1 deeper
	if (a->rank == b->rank)
		b->rank++;

	ufTable[a] = b;
	return true;
}

Node *UnionFind::find(Node *node) {
	if (ufTable[node] != ufTable[ufTable[node]]) {
		ufTable[node] = find(ufTable[node]);
	}
	return ufTable[node];
}

Kruskal::Kruskal(std::vector<Node *> &nodes, std::vector<Edge *> &edges) :
		uf(nodes, edges), nodes(nodes), edges(edges) {
	solved = false;
}

bool Kruskal::sortFunction(Edge* first, Edge* second) {
	return first->getWeight() < second->getWeight();
}

std::vector<Edge *> Kruskal::getEdges() {
	if (!solved) {
		solve();
	}
	return mst;
}

float Kruskal::solve() {
	solved = true;
	std::sort(edges.begin(), edges.end(), sortFunction);

	int treeCount = nodes.size();
	float weight = 0;

	for (unsigned int i = 0; i < edges.size() && treeCount > 1; i++) {
		if (uf.join(edges[i]->a, edges[i]->b)) {
			treeCount--;
			weight += edges[i]->getWeight();

			// Save the edge, it may be useful for the user
			Edge *e = edges[i];
			mst.push_back(e);
		}
	}

	return weight;
}
{'fraction_non_alphanumeric': 0.19798041615667075, 'fraction_numerical': 0.0024479804161566705, 'mean_word_length': 4.060371517027864, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, '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': '5745566', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1283, 'n_words': 307}