1
1
/*BHEADER**********************************************************************
2
* Copyright (c) 2006 The Regents of the University of California.
2
* Copyright (c) 2008, Lawrence Livermore National Security, LLC.
3
3
* Produced at the Lawrence Livermore National Laboratory.
4
* Written by the HYPRE team, UCRL-CODE-222953.
7
* This file is part of HYPRE (see http://www.llnl.gov/CASC/hypre/).
8
* Please see the COPYRIGHT_and_LICENSE file for the copyright notice,
9
* disclaimer and the GNU Lesser General Public License.
11
* This program is free software; you can redistribute it and/or modify it
12
* under the terms of the GNU General Public License (as published by the Free
4
* This file is part of HYPRE. See file COPYRIGHT for details.
6
* HYPRE is free software; you can redistribute it and/or modify it under the
7
* terms of the GNU Lesser General Public License (as published by the Free
13
8
* Software Foundation) version 2.1 dated February 1999.
15
* This program is distributed in the hope that it will be useful, but WITHOUT
16
* ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or
17
* FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software Foundation,
22
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
11
***********************************************************************EHEADER*/
28
15
#include "_hypre_utilities.h"
51
/*--------------------------------------------------------------------------
53
* this one is a bit more robust:
54
* avoids overflow of m as can happen above when (low+high) overflows
55
* lets user specifiy high and low bounds for array (so a subset
57
* if not found, then spot returns where is should be inserted
59
*--------------------------------------------------------------------------*/
61
int hypre_BinarySearch2(int *list, int value, int low, int high, int *spot)
68
m = low + (high - low)/2;
72
else if (value > list[m])
80
/* not found (high = low-1) - so insert at low */