- Timestamp:
- Jun 27, 2018, 3:20:35 PM (8 years ago)
- Location:
- branches/czw_branch/20170908/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libohana/src/bisection.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20170908/Ohana
- Property svn:mergeinfo changed
-
branches/czw_branch/20170908/Ohana/src/libohana/src/bisection.c
r38459 r40477 32 32 return (N); 33 33 } 34 35 // return the index of the last value < threshold 36 int ohana_bisection_int (int *values, int Nvalues, int threshold) { 37 38 int Nlo = 0; 39 int Nhi = Nvalues - 1; 40 41 if (Nvalues < 1) return (-1); 42 if (values[Nlo] > threshold) return (-1); 43 44 if (Nvalues < 2) return (0); 45 if (values[Nhi] < threshold) return (Nhi); 46 47 int N; 48 while (Nhi - Nlo > 4) { 49 N = 0.5*(Nlo + Nhi); 50 if (values[N] < threshold) { 51 Nlo = MAX(N, 0); 52 } else { 53 Nhi = MIN(N + 1, Nvalues - 1); 54 } 55 } 56 // values[Nlo] < threshold 57 // values[Nhi] >= threshold 58 59 for (N = Nlo; N < Nhi; N++) { 60 if (values[N] >= threshold) { 61 return (N-1); 62 } 63 } 64 return (N); 65 }
Note:
See TracChangeset
for help on using the changeset viewer.
