Changeset 13572


Ignore:
Timestamp:
10/09/12 20:33:14 (12 years ago)
Author:
Mathieu Morlighem
Message:

BUG: changed offset==-1 to offset=-1 + some cosmetics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/shared/Sorting/binary_search.cpp

    r13569 r13572  
    1818
    1919        /*intermediary: */
    20         int* beg=NULL;
    21         int* end=NULL;
    22         int* mid=NULL;
     20        int *beg = NULL;
     21        int *end = NULL;
     22        int *mid = NULL;
    2323
    2424        // point to beginning and end of the array
     
    6969        int offset=0; 
    7070        int found=0; /*found=0: not found.   
    71                                    found=1: found, and target is == to value at offset
    72                                    found=2: found, and target is > to value at offset  and < to value at offset+1
    73                                    */
     71                                                found=1: found, and target is == to value at offset
     72                                                found=2: found, and target is > to value at offset  and < to value at offset+1
     73                                                */
    7474
    7575        /*intermediary: */
    76         double* beg=NULL;
    77         double* end=NULL;
    78         double* mid=NULL;
     76        double *beg = NULL;
     77        double *end = NULL;
     78        double *mid = NULL;
    7979
    8080        // point to beginning and end of the array
    81         beg=sorted_doubles;
    82         end=sorted_doubles+num_doubles;
    83         mid=beg+(int)(num_doubles/2.0);
     81        beg = sorted_doubles;
     82        end = sorted_doubles+num_doubles;
     83        mid = beg+(int)(num_doubles/2.0);
    8484
    8585        if (target<*beg){
    86                 offset==-1;
    87                 found=0;
     86                offset = -1;
     87                found  = 0;
    8888        }
    8989        if (*beg==target){
    90                 found=1;
    91                 offset=0;
     90                found  = 1;
     91                offset = 0;
    9292        }
    9393        else if(*(end-1)==target){
    94                 found=1;
    95                 offset=num_doubles-1;
     94                found  = 1;
     95                offset = num_doubles-1;
    9696        }
    9797        else{
    98                 while((beg <= end) && !( target>=*mid &&  target<*(mid+1)) ){
     98                while((beg <= end) && !( target>=*mid && target<*(mid+1)) ){
    9999                        // is the target in lower or upper half?
    100100                        if (target < *mid) {
Note: See TracChangeset for help on using the changeset viewer.