Ignore:
Timestamp:
Sep 20, 2010, 10:35:53 AM (9 years ago)
Author:
mulligan
Message:

int_of_vect implemented.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/BitVectors.ml

    r87 r88  
    6363let half_add l r = full_add l r false
    6464
    65 let rec split_last = function [] -> assert false | [he] -> he,[] | he::tl -> let l,res = split_last tl in l,he::res
     65let rec split_last =
     66  function
     67    [] -> assert false
     68  | [he] -> he,[]
     69  | he::tl ->
     70      let l,res = split_last tl in
     71        l,he::res
    6672
    67 let shift_left = function [] -> assert false | _::tl -> tl @ [false]
     73let shift_left =
     74  function
     75    [] -> assert false
     76  | _::tl -> tl @ [false]
    6877let shift_right l = false :: snd (split_last l)
    69 let rotate_left = function [] -> assert false | he::tl -> tl @ [he]
    70 let rotate_right l = let he,tl = split_last l in he::tl
     78let rotate_left =
     79  function
     80    [] -> assert false
     81  | he::tl -> tl @ [he]
     82let rotate_right l =
     83  let he,tl = split_last l in
     84    he::tl
     85
     86let int_of_vect v =
     87  let rec aux pow v =
     88    match v with
     89      [] -> 0
     90    | hd::tl ->
     91        if hd = true then
     92          pow + (aux (pow * 2) tl)
     93        else
     94          aux (pow * 2) tl
     95  in
     96    aux 1 (List.rev v)
Note: See TracChangeset for help on using the changeset viewer.