/*BHEADER********************************************************************** * Copyright (c) 2008, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * This file is part of HYPRE. See file COPYRIGHT for details. * * HYPRE is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * $Revision: 2.4 $ ***********************************************************************EHEADER*/ #include "utilities.h" /*-------------------------------------------------------------------------- * hypre_BinarySearch * to contain ordered nonnegative numbers * the routine returns the location of the value or -1 *--------------------------------------------------------------------------*/ int hypre_BinarySearch(int *list, int value, int list_length) { int low, high, m; int not_found = 1; low = 0; high = list_length-1; while (not_found && low <= high) { m = (low + high) / 2; if (value < list[m]) { high = m - 1; } else if (value > list[m]) { low = m + 1; } else { not_found = 0; return m; } } return -1; } /*-------------------------------------------------------------------------- * hypre_BigBinarySearch * to contain ordered nonnegative numbers * the routine returns the location of the value or -1 *--------------------------------------------------------------------------*/ int hypre_BigBinarySearch(HYPRE_BigInt *list, HYPRE_BigInt value, int list_length) { int low, high, m; int not_found = 1; low = 0; high = list_length-1; while (not_found && low <= high) { m = (low + high) / 2; if (value < list[m]) { high = m - 1; } else if (value > list[m]) { low = m + 1; } else { not_found = 0; return m; } } return -1; }