 Timestamp:
 Oct 11, 2011, 5:42:20 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.2/8051indexedlabelsbranch/src/utilities/extArray.ml
r1349 r1357 1 type +'a t = {1 type 'a t = { 2 2 mutable t_cont : 'a array; 3 3 mutable t_length : int; … … 5 5 } 6 6 7 let default_buffer_size = 4 8 9 let make n a = 10 let m = min default_buffer_size n in 7 let make ?(buff = 16) n a = 8 let m = max 1 (max buff n) in 11 9 {t_cont = Array.make m a; t_length = n; t_def = a} 12 10 … … 20 18 let length v = v.t_length 21 19 22 let chop v n = v.t_length < max 0 (v.t_length  n) 20 let chop v n = 21 let n = min n v.t_length in 22 Array.fill v.t_cont (v.t_length  n) v.t_length v.t_def; 23 v.t_length < v.t_length  n 23 24 24 let assure v n =25 let ensure v n = 25 26 let m = Array.length v.t_cont in 26 (if n >= m then27 if n >= m then 27 28 let d = n / m + 1 in 28 29 let new_arr = Array.make (d * m) v.t_def in 29 30 Array.blit v.t_cont 0 new_arr 0 m; 30 v.t_cont < new_arr); 31 v.t_length < max v.t_length (m + 1) 31 v.t_cont < new_arr; 32 else (); 33 v.t_length < max (n + 1) v.t_length 32 34 33 35 34 36 35 let extend v n = assure v (v.t_length + n)37 let extend v n = ensure v (v.t_length + n  1) 36 38 37 39 let set v n a = 38 40 (if n < 0 then invalid_arg "out of bounds"); 39 assure v n;40 v.t_cont.(n) < a ;41 ensure v n; 42 v.t_cont.(n) < a 41 43 42 44 let append v a = set v (v.t_length) a 43 45 46 let reclaim ?(packet = 16) v = 47 let new_l = v.t_length  (v.t_length  1) mod packet + packet  1 in 48 let new_l = max 1 new_l in 49 if new_l <> Array.length v.t_cont then 50 let new_cont = Array.make new_l v.t_def in 51 Array.blit v.t_cont 0 new_cont 0 v.t_length; 52 v.t_cont < new_cont 53 54 exception Finish_iter 55 56 let iteri f v = 57 let f' i a = if i < v.t_length then f i a else raise Finish_iter in 58 try Array.iteri f' v.t_cont with Finish_iter > () 59 60 let iter f = iteri (fun _ > f) 61 62 let fold_left f a v = 63 let res = ref a in 64 let f' b = res := f !res b in 65 iter f' v; !res 66 67 let fold_right f v a = 68 let funct = ref (fun x > x) in 69 let f' b = let funct' = !funct in funct := fun x > funct' (f b x) in 70 iter f' v; !funct a 71 72 44 73 45 74
Note: See TracChangeset
for help on using the changeset viewer.