/[svn]/types/sortedList.ml
ViewVC logotype

Diff of /types/sortedList.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 232 by abate, Tue Jul 10 17:16:34 2007 UTC revision 233 by abate, Tue Jul 10 17:17:31 2007 UTC
# Line 60  Line 60 
60      type ('a,'b) map      type ('a,'b) map
61      external get: ('a,'b) map -> ('a elem * 'b) list = "%identity"      external get: ('a,'b) map -> ('a elem * 'b) list = "%identity"
62      val empty: ('a,'b) map      val empty: ('a,'b) map
63        val iter: ('b -> unit) -> ('a,'b) map -> unit
64      val is_empty: ('a,'b) map -> bool      val is_empty: ('a,'b) map -> bool
65      val singleton: 'a elem -> 'b -> ('a,'b) map      val singleton: 'a elem -> 'b -> ('a,'b) map
66        val assoc_remove: 'a elem -> ('a,'b) map -> 'b * ('a,'b) map
67      val merge: ('b -> 'b -> 'b ) -> ('a,'b) map -> ('a,'b) map -> ('a,'b) map      val merge: ('b -> 'b -> 'b ) -> ('a,'b) map -> ('a,'b) map -> ('a,'b) map
68      val merge_elem: 'b -> ('a,'b) map -> ('a,'b) map -> ('a,'b) map      val merge_elem: 'b -> ('a,'b) map -> ('a,'b) map -> ('a,'b) map
69      val union_disj: ('a,'b) map -> ('a,'b) map -> ('a,'b) map      val union_disj: ('a,'b) map -> ('a,'b) map -> ('a,'b) map
# Line 70  Line 72 
72      val map_from_slist: ('a elem -> 'b) -> 'a t -> ('a,'b) map      val map_from_slist: ('a elem -> 'b) -> 'a t -> ('a,'b) map
73      val collide: ('b -> 'c -> unit) -> ('a,'b) map -> ('a,'c) map -> unit      val collide: ('b -> 'c -> unit) -> ('a,'b) map -> ('a,'c) map -> unit
74      val map: ('b -> 'c) -> ('a,'b) map -> ('a,'c) map      val map: ('b -> 'c) -> ('a,'b) map -> ('a,'c) map
75        val mapi: ('a elem -> 'b -> 'c) -> ('a,'b) map -> ('a,'c) map
76      val constant: 'b -> 'a t -> ('a,'b) map      val constant: 'b -> 'a t -> ('a,'b) map
77      val num: int -> 'a t -> ('a,int) map      val num: int -> 'a t -> ('a,int) map
78      val map_to_list: ('b -> 'c) -> ('a,'b) map -> 'c list      val map_to_list: ('b -> 'c) -> ('a,'b) map -> 'c list
# Line 219  Line 222 
222    let is_empty l = l = []    let is_empty l = l = []
223    let singleton x y = [ (x,y) ]    let singleton x y = [ (x,y) ]
224    
225      let rec iter f = function
226        | (_,y)::l -> f y; iter f l
227        | [] -> ()
228    
229      let rec assoc_remove_aux v r = function
230        | ((x,y) as a)::l ->
231            let c = X.compare x v in
232            if c = 0 then (r := y; l)
233            else if c < 0 then a :: (assoc_remove_aux v r l)
234            else raise Not_found
235        | [] -> raise Not_found
236    
237      let assoc_remove v l =
238        let r = ref (Obj.magic 0) in
239        let l = assoc_remove_aux v r l in
240        (!r, l)
241    
242    let rec merge f l1 l2 =    let rec merge f l1 l2 =
243      match (l1,l2) with      match (l1,l2) with
244        | ((x1,y1) as t1)::q1, ((x2,y2) as t2)::q2 ->        | ((x1,y1) as t1)::q1, ((x2,y2) as t2)::q2 ->
# Line 278  Line 298 
298      | (x,y)::l -> (x, f y)::(map f l)      | (x,y)::l -> (x, f y)::(map f l)
299      | [] -> []      | [] -> []
300    
301      let rec mapi f = function
302        | (x,y)::l -> (x, f x y)::(mapi f l)
303        | [] -> []
304    
305    let rec mapi_to_list f = function    let rec mapi_to_list f = function
306      | (x,y)::l -> (f x y) ::(mapi_to_list f l)      | (x,y)::l -> (f x y) ::(mapi_to_list f l)
307      | [] -> []      | [] -> []

Legend:
Removed from v.232  
changed lines
  Added in v.233

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5