summaryrefslogtreecommitdiff
path: root/BS/baselines/gpu/cpu_lib.py
blob: 9a45f94789f41a24aa8a3bef4c93397e66cc1f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-

def binary_search(arr, search):
    
    L = 0
    R = len(arr)
    
    while(L<=R):
        
        if L>R:
            return -1 #Error code 1
        
        m = (L+R)/2
        if(arr[m] < search):
            L = m+1
        elif(arr[m] > search):
            R = m-1
        else:
            return m
    
    return -2 #Error code 2