~ubuntu-branches/ubuntu/karmic/hypre/karmic

« back to all changes in this revision

Viewing changes to src/utilities/binsearch.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2009-03-20 11:40:12 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090320114012-132h6ok9w2r6o609
Tags: 2.4.0b-2
Rebuild against new openmpi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
5
 
 * All rights reserved.
6
 
 *
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.
10
 
 *
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.
 
5
 *
 
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.
14
9
 *
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.
19
 
 *
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
23
 
 *
24
 
 * $Revision: 2.3 $
 
10
 * $Revision: 2.7 $
25
11
 ***********************************************************************EHEADER*/
26
12
 
 
13
 
27
14
 
28
15
#include "_hypre_utilities.h"
29
16
 
61
48
   return -1;
62
49
}
63
50
 
 
51
/*--------------------------------------------------------------------------
 
52
 * hypre_BinarySearch2
 
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 
 
56
     of array can be used)
 
57
 *  if not found, then spot returns where is should be inserted
 
58
 
 
59
 *--------------------------------------------------------------------------*/
 
60
 
 
61
int hypre_BinarySearch2(int *list, int value, int low, int high, int *spot) 
 
62
{
 
63
   
 
64
   int m;
 
65
   
 
66
   while (low <= high) 
 
67
   {
 
68
      m = low + (high - low)/2;
 
69
 
 
70
      if (value < list[m])
 
71
         high = m - 1;
 
72
      else if (value > list[m])
 
73
         low = m + 1;
 
74
      else
 
75
      {
 
76
         *spot = m;
 
77
         return m;
 
78
      }
 
79
   }
 
80
   /* not found (high = low-1) - so insert at low */
 
81
      *spot = low;
 
82
 
 
83
   return -1;
 
84
}