Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
271
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 startIndex = endIndex with
  12.         | true -> Some <| xs.[startIndex]
  13.         | _ ->
  14.  
  15.         let half = startIndex + ((endIndex - startIndex) / 2)
  16.         let date,value = xs.[half]
  17.  
  18.         match compare key date with
  19.         | 0 -> Some (date,value)
  20.         | 1 -> find key half endIndex
  21.         | _ -> find key startIndex half
  22.  
  23.     find key 0 (length - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement