Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.58 KB | None | 0 0
  1. let find key (xs: ('a * 'b) []) =
  2.     let first,_ = xs.[0]
  3.  
  4.     match key < first with
  5.     | true -> None
  6.     | _ ->
  7.  
  8.     let length = Array.length xs
  9.  
  10.     let rec find key startIndex endIndex =
  11.         match endIndex - startIndex with
  12.         | 0
  13.         | 1 -> Some <| xs.[startIndex]
  14.         | _ ->
  15.  
  16.         let half = startIndex + ((endIndex - startIndex) / 2)
  17.         let date,value = xs.[half]
  18.  
  19.         match compare key date with
  20.         | 0 -> Some (date,value)
  21.         | 1 -> find key half endIndex
  22.         | _ -> find key startIndex half
  23.  
  24.     find key 0 (length - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement