Java Array Max Value maxdiffbits(int initoffset, int[] i, int pos, int length)

Here you can find the source of maxdiffbits(int initoffset, int[] i, int pos, int length)

Description

get the msb of differences among the consecutive input integers

License

Open Source License

Parameter

Parameter Description
initoffset introduce the difference to the first element
i a parameter
pos a parameter
length a parameter

Declaration

public static int maxdiffbits(int initoffset, int[] i, int pos, int length) 

Method Source Code

//package com.java2s;
/**//from   ww w  .  j  a va 2s  .  c  o  m
 * This code is released under the
 * Apache License Version 2.0 http://www.apache.org/licenses/.
 *
 * (c) Daniel Lemire, http://lemire.me/en/
 */

public class Main {
    /**
     * get the msb of differences among the consecutive input integers
     * 
     * @param initoffset
     *            introduce the difference to the first element
     * @param i
     * @param pos
     * @param length
     * @return
     */
    public static int maxdiffbits(int initoffset, int[] i, int pos, int length) {
        int mask = 0;
        mask |= (i[pos] - initoffset);
        for (int k = pos + 1; k < pos + length; ++k) {
            mask |= i[k] - i[k - 1];
        }
        return bits(mask);
    }

    public static int bits(int i) {
        return 32 - Integer.numberOfLeadingZeros(i);
    }
}

Related

  1. maxbits32(int[] i, int pos)
  2. maxCommonLeadingWhitespaceForAll(String[] strings)
  3. maxcount(int[] vals, int max, int maxcount)
  4. maxDblArrayValue(int npts, double[] dbls)
  5. maxdex(float... values)
  6. maxDiffLocation(double[] list1, double[] list2)
  7. maxDistance(byte[] array, int maxDistance)
  8. maxDouble(double a, double... others)
  9. maxElement(double[] d)