<commit_before>package com.jeffreydiaz.connectivity;

import com.jeffreydiaz.exceptions.InvalidInputException;

/**
 * Connectivity problem solved using a Quick find method, but o(n) union operation.
 * Complexities:
 *      create: O(N)
 *      find: O(1)
 *      union: O(N)
 * @author <NAME>
 */
public class QuickFindUF {

	private int[] components;

	/**
	 * Create a QuickFindUF holding n nodes.
	 * @param n the number of nodes.
	 * @throws InvalidInputException if n < 0 or greater than possible int max.
	 */
	public QuickFindUF(int n) throws InvalidInputException
	{
		validateSizeOfN(n);
		components = new int[n];
		initComponentsArray();
	}

	private void validateSizeOfN(int n) throws InvalidInputException
	{
		if (n < 0 || n > Integer.MAX_VALUE) {
			throw new InvalidInputException("Invalid size");
		}
	}

	// Initialize components array so every element has its index as its value.
	private void initComponentsArray()
	{
		for (int i = 0; i < components.length; ++i) {
			components[i] = i;
		}
	}

	/**<commit_msg>Some logic mistakes here..<commit_after>package com.jeffreydiaz.connectivity;

import com.jeffreydiaz.exceptions.InvalidInputException;

/**
 * Connectivity problem solved using a Quick find method, but o(n) union operation.
 * Complexities:
 *      create: O(N)
 *      find: O(1)
 *      union: O(N)
 * @author <NAME>
 */
public class QuickFindUF {

	private int[] components;

	/**
	 * Create a QuickFindUF holding n nodes.
	 * @param n the number of nodes.
	 * @throws InvalidInputException if n < 0 or greater than possible int max.
	 */
	public QuickFindUF(int n) throws InvalidInputException
	{
		validateSizeOfN(n);
		components = new int[n];
		initComponentsArray();
	}

	private void validateSizeOfN(int n) throws InvalidInputException
	{
		if (n <= 0) {
			throw new InvalidInputException("Invalid size");
		}
	}

	// Initialize components array so every element has its index as its value.
	private void initComponentsArray()
	{
		for (int i = 0; i < components.length; ++i) {
			components[i] = i;
		}
	}

	/**
{'fraction_non_alphanumeric': 0.10938259601361205, 'fraction_numerical': 0.003889158969372873, 'mean_word_length': 3.563192904656319, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, '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': '3514810', 'n_tokens_mistral': 691, 'n_tokens_neox': 644, 'n_words': 207}