<commit_before>/*
 *    Copyright 2015 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package sg.yikjiun.aurora;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author <NAME>
 */
public class ArrayUtils {
    /**
     * Shuffles an array using Fisher-Yates shuffle.
     *
     * Time: O(n)
     * Space: O(1)
     * where n is the number of elements in the array.
     */
    public static void fisherYatesShuffle(int[] nums) {
        Random r = ThreadLocalRandom.current();
        int n = nums.length;
        for (int i = 0; i < n - 1; ++i) {
            int j = r.nextInt(i + 1);
            swap(nums, i, j);
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }

    /**
     * Returns a sorted array using lsd radix sort.
     *
     * Only works on non-negative integers.
     * Time: O(31n)
     * Space: O(n)
     * where n is the number of elements in the array to be sorted
     */
    public static int[] LsdRadixSort(int[] nums) {
        int n = nums.length;
        for (int i = 0, j = 1; i < 31; ++i, j <<= 1) {
            int[] tmpNums = new int[n];
            int numOnes = 0;
            for (int num : nums) {
                if ((num & j) == j) {
                    ++numOnes;<commit_msg>Update Fisher-Yates Shuffle.<commit_after>/*
 *    Copyright 2015 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package sg.yikjiun.aurora;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author <NAME>
 */
public class ArrayUtils {
    /**
     * Shuffles an array using Fisher-Yates shuffle.
     *
     * Time: O(n)
     * Space: O(1)
     * where n is the number of elements in the array.
     */
    public static void fisherYatesShuffle(int[] nums) {
        Random r = ThreadLocalRandom.current();
        int n = nums.length;
        for (int i = n-1; i > 1; --i) {
            int j = r.nextInt(i + 1);
            swap(nums, i, j);
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }

    /**
     * Returns a sorted array using lsd radix sort.
     *
     * Only works on non-negative integers.
     * Time: O(31n)
     * Space: O(n)
     * where n is the number of elements in the array to be sorted
     */
    public static int[] LsdRadixSort(int[] nums) {
        int n = nums.length;
        for (int i = 0, j = 1; i < 31; ++i, j <<= 1) {
            int[] tmpNums = new int[n];
            int numOnes = 0;
            for (int num : nums) {
                if ((num & j) == j) {
                    ++numOnes;
{'fraction_non_alphanumeric': 0.111315305854555, 'fraction_numerical': 0.010501443948542924, 'mean_word_length': 1.9835552075176195, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '970927', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1179, 'n_words': 440}