Path: blob/v3_openjdk/jre_lwjgl3glfw/src/main/java/android/util/ContainerHelpers.java
2129 views
/*1* Copyright (C) 2013 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516package android.util;1718class ContainerHelpers {1920// This is Arrays.binarySearch(), but doesn't do any argument validation.21static int binarySearch(int[] array, int size, int value) {22int lo = 0;23int hi = size - 1;2425while (lo <= hi) {26final int mid = (lo + hi) >>> 1;27final int midVal = array[mid];2829if (midVal < value) {30lo = mid + 1;31} else if (midVal > value) {32hi = mid - 1;33} else {34return mid; // value found35}36}37return ~lo; // value not present38}3940static int binarySearch(long[] array, int size, long value) {41int lo = 0;42int hi = size - 1;4344while (lo <= hi) {45final int mid = (lo + hi) >>> 1;46final long midVal = array[mid];4748if (midVal < value) {49lo = mid + 1;50} else if (midVal > value) {51hi = mid - 1;52} else {53return mid; // value found54}55}56return ~lo; // value not present57}58}596061