All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.carrotsearch.hppcrt.DoubleArrays Maven / Gradle / Ivy

Go to download

High Performance Primitive Collections Realtime (fork of HPPC of Carrotsearch) Fundamental data structures (maps, sets, lists, stacks, queues, heaps, sorts) generated for combinations of object and primitive types to conserve JVM memory and speed up execution. The Realtime fork intend of extending collections while tweaking and optimizations to remove any dynamic allocations at runtime, and low variance execution times.

There is a newer version: 0.7.5
Show newest version
package com.carrotsearch.hppcrt;

import java.util.Arrays;

  
/**
 * Utility class gathering array or DoubleIndexedContainer handling algorithms for doubles.
 * This is a kind of complement for {@link java.util.Arrays}.
 */
 @javax.annotation.Generated(date = "2015-02-27T19:21:18+0100", value = "HPPC-RT generated from: DoubleArrays.java") 
public final class DoubleArrays
{
    final private static int BLANK_ARRAY_SIZE_IN_BIT_SHIFT = 10;

    /**
     * Batch blanking array size
     */
    final private static int BLANK_ARRAY_SIZE = 1 << DoubleArrays.BLANK_ARRAY_SIZE_IN_BIT_SHIFT;

    /**
     * Batch blanking array with double nulls
     */
         final private static double[] BLANKING_OBJECT_ARRAY = (new double[DoubleArrays.BLANK_ARRAY_SIZE]);
      

    private DoubleArrays() {

        //nothing
    }

    /**
     * Rotate utility :
     * Transforms the range [[slice_1:  from; mid - 1][slice_2: mid, to - 1]] of table, into
     * [[slice_2][slice_1]]in place, i.e swap the two slices while keeping their own internal order.
     * @param table
     * @param from the start range to consider
     * @param mid start index of the second slice
     * @param to the array end range, exclusive
     */
    public static  void rotate(final double[] table, final int from, final int mid, final int to) {

        DoubleArrays.reverse(table, from, mid);
        DoubleArrays.reverse(table, mid, to);
        DoubleArrays.reverse(table, from, to);
    }

    /**
     * Rotate utility :
     * Transforms the range [[slice_1:  from; mid - 1][slice_2: mid, to - 1]] of DoubleIndexedContainer, into
     * [[slice_2][slice_1]] in place, i.e swap the two slices while keeping their own internal order.
     * @param table
     * @param from the start range to consider
     * @param mid start index of the second slice
     * @param to the array end range, exclusive
     */
    public static  void rotate(final DoubleIndexedContainer table, final int from, final int mid, final int to) {

        DoubleArrays.reverse(table, from, mid);
        DoubleArrays.reverse(table, mid, to);
        DoubleArrays.reverse(table, from, to);
    }

    /**
     * Reverse the elements positions of the specified range of array table :
     * @param table
     * @param from the start range to consider
     * @param to the array end range, exclusive
     */
    public static  void reverse(final double[] table, final int from, final int to) {

        final int halfSize = (to - from) >>> 1;
    double tmpValue;

    for (int i = 0; i < halfSize; i++)
    {
        tmpValue = table[i + from];
        table[i + from] = table[to - i - 1];
        table[to - i - 1] = tmpValue;
    }
    }

    /**
     * Reverse the elements positions of the specified range of DoubleIndexedContainer table :
     * @param table
     * @param from the start range to consider
     * @param to the array end range, exclusive
     */
    public static  void reverse(final DoubleIndexedContainer table, final int from, final int to) {

        final int halfSize = (to - from) >>> 1;
        double tmpValue;

        for (int i = 0; i < halfSize; i++)
        {
            tmpValue = table.get(i + from);
            table.set(i + from, table.get(to - i - 1));
            table.set(to - i - 1, tmpValue);
        }
    }

    /**
     * Method to blank any double[] array elements to its default value
     * from [startIndex; endIndex[, equivalent to {@link Arrays}.fill(objectArray, startIndex, endIndex, 0 or null)
     */
    public static  void blankArray(final double[] objectArray, final int startIndex, final int endIndex) {

        assert startIndex <= endIndex;

        final int size = endIndex - startIndex;
        final int nbChunks = size >> DoubleArrays.BLANK_ARRAY_SIZE_IN_BIT_SHIFT;
        //compute remainder
        final int rem = size & (DoubleArrays.BLANK_ARRAY_SIZE - 1);

        for (int i = 0; i < nbChunks; i++) {

            System.arraycopy(DoubleArrays.BLANKING_OBJECT_ARRAY, 0,
                    objectArray, startIndex + (i << DoubleArrays.BLANK_ARRAY_SIZE_IN_BIT_SHIFT),
                    DoubleArrays.BLANK_ARRAY_SIZE);
        } //end for

        //fill the reminder
        if (rem > 0) {
            Arrays.fill(objectArray, startIndex + (nbChunks << DoubleArrays.BLANK_ARRAY_SIZE_IN_BIT_SHIFT),
                    startIndex + (nbChunks << DoubleArrays.BLANK_ARRAY_SIZE_IN_BIT_SHIFT) + rem, (0.0));
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy