<commit_before>package com.jwetherell.algorithms.sorts.timing;

import java.text.DecimalFormat;
import java.util.Formatter;
import java.util.Locale;
import java.util.Random;

import com.jwetherell.algorithms.sorts.AmericanFlagSort;
import com.jwetherell.algorithms.sorts.BubbleSort;
import com.jwetherell.algorithms.sorts.CountingSort;
import com.jwetherell.algorithms.sorts.HeapSort;
import com.jwetherell.algorithms.sorts.InsertionSort;
import com.jwetherell.algorithms.sorts.MergeSort;
import com.jwetherell.algorithms.sorts.QuickSort;
import com.jwetherell.algorithms.sorts.RadixSort;
import com.jwetherell.algorithms.sorts.ShellSort;

public class SortsTiming {

    private static final DecimalFormat FORMAT = new DecimalFormat("#.###");
    private static final int SIZE = 1024*100;
    private static final boolean showResult = false;
    private static final boolean checkResults = true;

    private static int insertionCount = 0;
    private static double[] insertionResults = null;
    private static int bubbleCount = 0;
    private static double[] bubbleResults = null;
    private static int shellCount = 0;
    private static double[] shellResults = null;
    private static int mergeCount = 0;
    private static double[] mergeResults = null;
    private static int quickCount = 0;
    private static double[] quickResults = null;
    private static int heapCount = 0;
    private static double[] heapResults = null;
    private static int countingCount = 0;
    private static double[] countingResults = null;
    private static int radixCount = 0;
    private static double[] radixResults = null;
    private static int americanFlagCount = 0;
    private static double[] americanFlagResults = null;

    private static Integer[] unsorted = null;
    private static Integer[] sorted = null;
    private static Integer[] reverse = null;

    public static void main(String[] args) {
        System.out.println("Generating random array.");
        Random random = new Random();
        unsorted = new Integer[SIZE];
        int i = 0;
        while (i < unsorted.length) {
            int j = random.nextInt(unsorted.length * 10);
            unsorted[i++] = j;
        }
        System.out.println("Generated random array.");

        System.out.println("Generating sorted array.");
        sorted = new Integer[SIZE];
        for (i = 0; i < sorted.length; i++) {
            sorted[i] = i;
        }
        System.out.println("Generated sorted array.");

        System.out.println("Generating reverse sorted array.");
        reverse = new Integer[SIZE];
        for (i = (reverse.length - 1); i >= 0; i--) {
            reverse[i] = (SIZE - 1) - i;
        }
        System.out.println("Generated reverse sorted array.");
        System.out.println();
        System.out.flush();

        System.out.println("Starting sorts...");
        System.out.println();
        System.out.flush();

        insertionResults = new double[1 * 3];
        insertionCount = runTest(new Insertion(), unsorted, sorted, insertionResults, insertionCount);
        showComparison();

        bubbleResults = new double[1 * 3];
        bubbleCount = runTest(new Bubble(), unsorted, sorted, bubbleResults, bubbleCount);
        showComparison();

        shellResults = new double[1 * 3];
        shellCount = runTest(new Shell(), unsorted, sorted, shellResults, shellCount);
        showComparison();

        mergeResults = new double[2 * 3];
        mergeCount = runTest(new MergeNotInPlace(), unsorted, sorted, mergeResults, mergeCount);
        mergeCount = runTest(new MergeInPlace(), unsorted, sorted, mergeResults, mergeCount);
        showComparison();

        quickResults = new double[3 * 3];
        quickCount = runTest(new QuickFirst(), unsorted, sorted, quickResults, quickCount);
        quickCount = runTest(new QuickMiddle(), unsorted, sorted, quickResults, quickCount);
        quickCount = runTest(new QuickRandom(), unsorted, sorted, quickResults, quickCount);
        showComparison();

        heapResults = new double[1 * 3];
        heapCount = runTest(new Heap(), unsorted, sorted, heapResults, heapCount);<commit_msg>Labelled the merge sort incorrectly<commit_after>package com.jwetherell.algorithms.sorts.timing;

import java.text.DecimalFormat;
import java.util.Formatter;
import java.util.Locale;
import java.util.Random;

import com.jwetherell.algorithms.sorts.AmericanFlagSort;
import com.jwetherell.algorithms.sorts.BubbleSort;
import com.jwetherell.algorithms.sorts.CountingSort;
import com.jwetherell.algorithms.sorts.HeapSort;
import com.jwetherell.algorithms.sorts.InsertionSort;
import com.jwetherell.algorithms.sorts.MergeSort;
import com.jwetherell.algorithms.sorts.QuickSort;
import com.jwetherell.algorithms.sorts.RadixSort;
import com.jwetherell.algorithms.sorts.ShellSort;

public class SortsTiming {

    private static final DecimalFormat FORMAT = new DecimalFormat("#.###");
    private static final int SIZE = 1024*100;
    private static final boolean showResult = false;
    private static final boolean checkResults = true;

    private static int insertionCount = 0;
    private static double[] insertionResults = null;
    private static int bubbleCount = 0;
    private static double[] bubbleResults = null;
    private static int shellCount = 0;
    private static double[] shellResults = null;
    private static int mergeCount = 0;
    private static double[] mergeResults = null;
    private static int quickCount = 0;
    private static double[] quickResults = null;
    private static int heapCount = 0;
    private static double[] heapResults = null;
    private static int countingCount = 0;
    private static double[] countingResults = null;
    private static int radixCount = 0;
    private static double[] radixResults = null;
    private static int americanFlagCount = 0;
    private static double[] americanFlagResults = null;

    private static Integer[] unsorted = null;
    private static Integer[] sorted = null;
    private static Integer[] reverse = null;

    public static void main(String[] args) {
        System.out.println("Generating random array.");
        Random random = new Random();
        unsorted = new Integer[SIZE];
        int i = 0;
        while (i < unsorted.length) {
            int j = random.nextInt(unsorted.length * 10);
            unsorted[i++] = j;
        }
        System.out.println("Generated random array.");

        System.out.println("Generating sorted array.");
        sorted = new Integer[SIZE];
        for (i = 0; i < sorted.length; i++) {
            sorted[i] = i;
        }
        System.out.println("Generated sorted array.");

        System.out.println("Generating reverse sorted array.");
        reverse = new Integer[SIZE];
        for (i = (reverse.length - 1); i >= 0; i--) {
            reverse[i] = (SIZE - 1) - i;
        }
        System.out.println("Generated reverse sorted array.");
        System.out.println();
        System.out.flush();

        System.out.println("Starting sorts...");
        System.out.println();
        System.out.flush();

        insertionResults = new double[1 * 3];
        insertionCount = runTest(new Insertion(), unsorted, sorted, insertionResults, insertionCount);
        showComparison();

        bubbleResults = new double[1 * 3];
        bubbleCount = runTest(new Bubble(), unsorted, sorted, bubbleResults, bubbleCount);
        showComparison();

        shellResults = new double[1 * 3];
        shellCount = runTest(new Shell(), unsorted, sorted, shellResults, shellCount);
        showComparison();

        mergeResults = new double[2 * 3];
        mergeCount = runTest(new MergeInPlace(), unsorted, sorted, mergeResults, mergeCount);
        mergeCount = runTest(new MergeNotInPlace(), unsorted, sorted, mergeResults, mergeCount);
        showComparison();

        quickResults = new double[3 * 3];
        quickCount = runTest(new QuickFirst(), unsorted, sorted, quickResults, quickCount);
        quickCount = runTest(new QuickMiddle(), unsorted, sorted, quickResults, quickCount);
        quickCount = runTest(new QuickRandom(), unsorted, sorted, quickResults, quickCount);
        showComparison();

        heapResults = new double[1 * 3];
        heapCount = runTest(new Heap(), unsorted, sorted, heapResults, heapCount);
{'fraction_non_alphanumeric': 0.10656723598749097, 'fraction_numerical': 0.008419533317296127, 'mean_word_length': 3.1762933199397287, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '7247653', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2257, 'n_words': 659}