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

com.github.azbh111.utils.java.math.permutation.ShortPermutationHolder Maven / Gradle / Ivy

The newest version!
package com.github.azbh111.utils.java.math.permutation;

import com.github.azbh111.utils.java.array.ArrayUtils;

/**
 *
 * @author pyz
 * @date 2019/4/14 11:13 AM
 */
public class ShortPermutationHolder extends PermutationHolder {
    private short[] arr;

    public ShortPermutationHolder(short[] arr) {
        this.arr = arr;
    }

    @Override
    public int length() {
        return arr.length;
    }

    @Override
    public int compare(int i, int j) {
        return Short.compare(arr[i], arr[j]);
    }

    @Override
    public void swap(int i, int j) {
        short n = arr[i];
        arr[i] = arr[j];
        arr[j] = n;
    }

    @Override
    public void reverse(int fromIndex, int toIndex) {
        ArrayUtils.reverse(arr, fromIndex, toIndex);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy