1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 let rec removeq_rec ele list tail
=
24 if e
== ele
then removeq_rec ele list tail
26 removeq_rec ele list
(e
:: tail
)
28 let rec removeq ele list
=
29 removeq_rec ele list
[]
31 let rec remove_rec ele list tail
=
35 if e
= ele
then remove_rec ele list tail
37 remove_rec ele list
(e
:: tail
)
40 remove_rec ele list
[]
42 let rec remove_one_rec ele list tail
=
47 List.rev_append tail list
49 remove_one_rec ele list
(e
:: tail
)
51 let remove_one ele list
=
52 remove_rec ele list
[]
54 let rec removeq_first ele list
=
56 e
:: tail
when e
== ele
-> tail
57 | e
:: tail
-> e
:: (removeq_first ele tail
)
60 let rec remove_first ele list
=
62 e
:: tail
when e
= ele
-> remove_first ele tail
63 | e
:: tail
-> e
:: (remove_first ele tail
)
66 let rec cut_rec n list r
=
68 (0,_
) | (_
, []) -> List.rev r
, list
70 cut_rec (n
-1) tail
(x
:: r
)
73 if n
< 0 then failwith
"List2.sub: invalid parameter";
77 List.rev
(List.rev_map f list
)
80 let rec assoc_inv x
= function
82 | (a
,b
)::l
-> if b
= x
then a
else assoc_inv x l
84 let safe_iter f list
=
85 List.iter
(fun v
-> try f v
with _
-> ()) list
96 | m
:: tail
-> iter m tail
106 [] -> raise Not_found
107 | m
:: tail
-> iter m tail
110 let a = Array.of_list list
in
115 List.fold_left
(fun acc x
-> match f x
with Some y
-> y
:: acc
| None
-> acc
) []
118 let rec loop i
= function
120 | x
::xs
-> f i x
; loop (i
+1) xs