Commit ffdb961f authored by bguillaum's avatar bguillaum

clean

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@7423 7838e531-6607-4d57-9587-6c381814729c
parent 37a91e70
......@@ -63,7 +63,6 @@ module G_node = struct
let rm_out_edges t = {t with next = Massoc_gid.empty}
let build_neighbour t = {empty with pos = match t.pos with Some x -> Some (x+1) | None -> None}
let pos_comp n1 n2 = Pervasives.compare n1.pos n2.pos
......
......@@ -17,7 +17,6 @@ module G_node: sig
val set_fs: t -> G_fs.t -> t
(* FIXME move Gid up and replace int by Gid.t *)
val remove: Gid.t -> G_edge.t -> t -> t
val remove_key: Gid.t -> t -> t
......
......@@ -496,105 +496,6 @@ module Massoc_gid = Massoc_make (Gid)
(* ================================================================================ *)
module Massoc_pid = Massoc_make (Pid)
(* ================================================================================ *)
module Massoc = struct
(* Massoc is implemented with caml lists *)
(* invariant: we suppose that all 'a list in the structure are not empty! *)
type 'a t = (int * 'a list) list
let empty = []
let is_empty t = (t=[])
let rec assoc key = function
| [] -> []
| (h,_)::_ when key<h -> []
| (h,v)::t when key=h -> v
| (h,_)::t (* when key>h *) -> assoc key t
let to_string elt_to_string t =
List_.to_string
(fun (i,elt_list) ->
sprintf "%d -> [%s]" i (List_.to_string elt_to_string "," elt_list)
) "; " t
let iter fct t =
List.iter
(fun (key,list) ->
List.iter
(fun elt -> fct key elt)
list
) t
let rec add key elt = function
| [] -> Some [(key, [elt])]
| (h,list)::t when h=key ->
(match List_.usort_insert elt list with
| Some new_list -> Some ((h, new_list)::t)
| None -> None
)
| ((h,_)::_) as t when key<h -> Some ((key,[elt])::t)
| (h,l)::t (* when key>h *) ->
match (add key elt t) with Some t' -> Some ((h,l)::t') | None -> None
let fold_left fct init t =
List.fold_left
(fun acc (key,list) ->
List.fold_left
(fun acc2 elt ->
fct acc2 key elt)
acc list)
init t
let rec remove key value = function
| [] -> raise Not_found
| (h,_)::_ when key<h -> raise Not_found
| (h,[v])::t when key=h && value=v -> t
| (h,list)::t when key=h -> (h,List_.usort_remove value list)::t
| (h,list)::t (* when key>h *) -> (h,list) :: (remove key value t)
let rec remove_key key = function
| [] -> raise Not_found
| (h,_)::_ when key<h -> raise Not_found
| (h,list)::t when key=h -> t
| (h,list)::t (* when key>h *) -> (h,list) :: (remove_key key t)
let rec mem key value = function
| [] -> false
| (h,_)::_ when key<h -> false
| (h,list)::t when key=h -> List_.sort_mem value list
| (h,list)::t (* when key>h *) -> mem key value t
let rec mem_key key = function
| [] -> false
| (h,_)::_ when key<h -> false
| (h,_)::t when key=h -> true
| (h,_)::t (* when key>h *) -> mem_key key t
exception Not_disjoint
let disjoint_union t1 t2 =
let rec loop = function
| [], t | t, [] -> t
| ((h1,l1)::t1, (h2,l2)::t2) when h1 < h2 -> (h1,l1)::(loop (t1,((h2,l2)::t2)))
| ((h1,l1)::t1, (h2,l2)::t2) when h1 > h2 -> (h2,l2)::(loop (((h1,l1)::t1),t2))
| ((h1,l1)::t1, (h2,l2)::t2) (* when h1=h2*) ->
try (h1,List_.sort_disjoint_union l1 l2)::(loop (t1, t2))
with List_.Not_disjoint -> raise Not_disjoint
in loop (t1, t2)
exception Duplicate
let merge_key i j t =
try
let i_list = List.assoc i t in
disjoint_union (remove_key i t) [j,i_list]
with
| Not_found -> (* no key i *) t
| Not_disjoint -> raise Duplicate
let exists fct t = List.exists (fun (key,list) -> List.exists (fun value -> fct key value) list) t
end (* module Massoc *)
(* ================================================================================ *)
module Error = struct
......
......@@ -198,47 +198,6 @@ module type S =
module Massoc_make (Ord : OrderedType) : S with type key = Ord.t
(* ================================================================================ *)
(* module Massoc implements multi-association data: keys are (hardly coded as) int and the same key can be
associated with a set of values *)
module Massoc: sig
type 'a t
val empty: 'a t
(* an empty list returned if the key is undefined *)
val assoc: int -> 'a t -> 'a list
val is_empty: 'a t -> bool
val to_string: ('a -> string) -> 'a t -> string
val iter: (int -> 'a -> unit) -> 'a t -> unit
val add: int -> 'a -> 'a t -> 'a t option
val fold_left: ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'b
(* raise Not_found if no (key,elt) *)
val remove: int -> 'a -> 'a t -> 'a t
(* raise Not_found if no (key,elt) *)
val remove_key: int -> 'a t -> 'a t
(* [mem key value t ] test if the couple (key, value) is in the massoc [t]. *)
val mem: int -> 'a -> 'a t -> bool
(* mem_key key t] tests is [key] is associated to at least one value in [t]. *)
val mem_key: int -> 'a t -> bool
exception Not_disjoint
val disjoint_union: 'a t -> 'a t -> 'a t
exception Duplicate
val merge_key: int -> int -> 'a t -> 'a t
val exists: (int -> 'a -> bool) -> 'a t -> bool
end
module Massoc_gid : S with type key = Gid.t
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment