Java Binary Search binarySearch(final Enum[] full, final int[] partial, final char key, final int index)

Here you can find the source of binarySearch(final Enum[] full, final int[] partial, final char key, final int index)

Description

binary Search

License

Open Source License

Declaration

public static int binarySearch(final Enum<?>[] full,
            final int[] partial, final char key, final int index) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2014 lib4j
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * You should have received a copy of The MIT License (MIT) along with this
 * program. If not, see <http://opensource.org/licenses/MIT/>.
 *///w  w  w.jav a  2s  .c o  m

public class Main {
    public static int binarySearch(final Enum<?>[] full,
            final int[] partial, final char key, final int index) {
        int low = 0;
        int high = partial.length - 1;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            final String name = full[partial[mid]].toString();
            char midVal = index < name.length() ? name.charAt(index) : ' ';

            if (midVal < key)
                low = mid + 1;
            else if (midVal > key)
                high = mid - 1;
            else
                return mid; // key found
        }

        return -(low + 1); // key not found.
    }
}

Related

  1. binarySearch(double experience, int min, int max)
  2. binarySearch(double values[], double search)
  3. binarySearch(double[] a, double key)
  4. binarySearch(double[] arr, double value, int p, int q)
  5. binarySearch(final double[] array, final double val)
  6. binarySearch(final Object[] a, final int fromIndex, final int toIndex, final Object key)
  7. binarySearch(int arr[], int low, int high, int key)
  8. binarySearch(int codePoint)
  9. binarySearch(int[] array, int key)