Skip to content

Commit

Permalink
Fix indenting in binsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
corwinjoy committed Jul 9, 2015
1 parent 988d513 commit 508d679
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/binsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@

/* Find the smallest index for which A[index] >= key */
int lower_bound(double key, double *A, int len_A) {
int mid;
int lo = 0;
int hi = len_A-1;
while (lo < hi) {
mid = lo + (hi - lo) / 2;
if (A[mid] >= key) {
hi = mid;
}
else {
lo = mid + 1;
}
}
int mid;
int lo = 0;
int hi = len_A-1;
while (lo < hi) {
mid = lo + (hi - lo) / 2;
if (A[mid] >= key) {
hi = mid;
}
else {
lo = mid + 1;
}
}

return lo; // lo is the least x for which A[x] >= key is true
return lo; // lo is the least x for which A[x] >= key is true
}

/* Find the smallest index for which A[index] > key */
int upper_bound(double key, double *A, int len_A) {
int mid;
int lo = 0;
int hi = len_A - 1;
while (lo < hi) {
mid = lo + (hi - lo) / 2;
if (A[mid] > key) {
hi = mid;
}
else {
lo = mid + 1;
}
}
int mid;
int lo = 0;
int hi = len_A - 1;
while (lo < hi) {
mid = lo + (hi - lo) / 2;
if (A[mid] > key) {
hi = mid;
}
else {
lo = mid + 1;
}
}

return lo; // lo is the least x for which A[x] > key is true
return lo; // lo is the least x for which A[x] > key is true
}

/* bound the key in the array of vals.
if start == true, return lowest index s.t. vals[index] >= key
if start == false, return highest index s.t. vals[index] <= key
*/
int bound(double key, double *vals, int len_vals, int start) {
int item;
if (start) {
item = lower_bound(key, vals, len_vals);
}
else {
item = upper_bound(key, vals, len_vals);
int item;
if (start) {
item = lower_bound(key, vals, len_vals);
}
else {
item = upper_bound(key, vals, len_vals);
/* if handles edge cases. item may be at the lo/hi end of array */
if (item > 0 && vals[item] > key) --item;
}
return(item);
if (item > 0 && vals[item] > key) --item;
}
return(item);
}

SEXP binsearch(SEXP key, SEXP vec, SEXP start)
Expand Down

0 comments on commit 508d679

Please sign in to comment.