<commit_before>package teetime.stage.quicksort;

import teetime.framework.AbstractDCStage;

public final class QuicksortStage extends AbstractDCStage<QuicksortProblem, QuicksortSolution> {

	@Override
	protected boolean isBaseCase(final QuicksortProblem quickSortProblem) {
		return (quickSortProblem.getHigh() - quickSortProblem.getLow() >= 1 ? false : true);
	}

	@Override
	protected void divide(final QuicksortProblem problem) {
		final int low = problem.getLow();
		final int high = problem.getHigh();
		final int[] numbers = problem.getNumbers();

		// pick the pivot
		final int middle = low + (high - low) / 2;
		final int pivot = numbers[middle];

		// make left < pivot and right > pivot
		int i = low;
		int j = high;
		while (i <= j) {
			while (numbers[i] < pivot) {
				i++;
			}

			while (numbers[j] > pivot) {
				j--;
			}

			if (i <= j) {
				int temp = numbers[i];
				numbers[i] = numbers[j];
				numbers[j] = temp;
				i++;
				j--;
			}
		}
		// recursively sort two sub parts
		// FIXME Put following code in AbstraceDCStage
		QuicksortProblem newQuicksortProblem1 = new QuicksortProblem(problem.getID(), low, j, numbers);
		leftOutputPort.send(newQuicksortProblem1);
		QuicksortProblem newQuicksortProblem2 = new QuicksortProblem(problem.getID(), i, high, numbers);
		rightOutputPort.send(newQuicksortProblem2);
	}

	@Override
	protected QuicksortSolution solve(final QuicksortProblem problem) {
		QuicksortSolution solution = new QuicksortSolution(problem.getID(), problem.getLow(), problem.getHigh(), problem.getNumbers());
		return solution;
	}

	@Override
	protected void combine(final QuicksortSolution s1, final QuicksortSolution s2) {
		this.getOutputPort().send(s1);
	}

	@Override
	public AbstractDCStage<QuicksortProblem, QuicksortSolution> duplicate() {
		return new QuicksortStage();
	}
}<commit_msg>changed return type of divide() to Pair<P,P> in order to maintain concept.<commit_after>package teetime.stage.quicksort;

import org.apache.commons.math3.util.Pair;

import teetime.framework.AbstractDCStage;

public final class QuicksortStage extends AbstractDCStage<QuicksortProblem, QuicksortSolution> {

	@Override
	protected boolean isBaseCase(final QuicksortProblem quickSortProblem) {
		return (quickSortProblem.getHigh() - quickSortProblem.getLow() >= 1 ? false : true);
	}

	@Override
	protected Pair<QuicksortProblem, QuicksortProblem> divide(final QuicksortProblem problem) {
		final int low = problem.getLow();
		final int high = problem.getHigh();
		final int[] numbers = problem.getNumbers();

		// pick the pivot
		final int middle = low + (high - low) / 2;
		final int pivot = numbers[middle];

		// make left < pivot and right > pivot
		int i = low;
		int j = high;
		while (i <= j) {
			while (numbers[i] < pivot) {
				i++;
			}

			while (numbers[j] > pivot) {
				j--;
			}

			if (i <= j) {
				int temp = numbers[i];
				numbers[i] = numbers[j];
				numbers[j] = temp;
				i++;
				j--;
			}
		}
		// recursively sort two sub parts
		return new Pair<QuicksortProblem, QuicksortProblem>(
				new QuicksortProblem(problem.getID(), low, j, numbers),
				new QuicksortProblem(problem.getID(), i, high, numbers));
	}

	@Override
	protected QuicksortSolution solve(final QuicksortProblem problem) {
		return new QuicksortSolution(
				problem.getID(),
				problem.getLow(),
				problem.getHigh(),
				problem.getNumbers());
	}

	@Override
	protected QuicksortSolution combine(final QuicksortSolution s1, final QuicksortSolution s2) {
		return s1;
	}

	@Override
	public AbstractDCStage<QuicksortProblem, QuicksortSolution> duplicate() {
		return new QuicksortStage();
	}
}
{'fraction_non_alphanumeric': 0.11527854384997242, 'fraction_numerical': 0.004136789851075565, 'mean_word_length': 4.072727272727272, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, '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': '5214488', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1135, 'n_words': 305}