Revision 73a7e5b9424a49ffecf7e188efcdbc11983eaece authored by Olaf Hering on 11 October 2019, 11:09:36 UTC, committed by Olaf Hering on 11 October 2019, 19:28:39 UTC
Fixes #52 Signed-off-by: Olaf Hering <olaf@aepfle.de>
1 parent 803edbb
parmap_utils.ml
let log_error fmt =
Printf.kprintf (fun s -> Format.eprintf "[Parmap]: %s@.%!" s) fmt
(* tail recursive version of List.append *)
let append_tr l1 l2 =
let rec aux acc = function
[] -> acc
| a::r -> aux (a::acc) r
in aux l2 (List.rev l1)
(* tail recursive version of List.concat *)
let concat_tr (l: 'a list) =
List.fold_left (fun acc l -> append_tr l acc) [] (List.rev l)
(* tail recursive version of List.fold_right from ExtLib *)
let fold_right f l init =
let fold_right_max = 1000 in
let rec tail_loop acc = function
| [] -> acc
| h :: t -> tail_loop (f h acc) t
in
let rec loop n = function
| [] -> init
| h :: t ->
if n < fold_right_max then
f h (loop (n+1) t)
else
f h (tail_loop init (List.rev t))
in
loop 0 l
(* would be [? a | a <- startv--endv] using list comprehension from Batteries *)
let range startv endv =
let s,e = (min startv endv),(max startv endv) in
let rec aux acc = function n -> if n=s then n::acc else aux (n::acc) (n-1)
in aux [] e
(* create a shadow file descriptor *)
let tempfd () =
let name = Filename.temp_file "mmap" "TMP" in
try
let fd = Unix.openfile name [Unix.O_RDWR; Unix.O_CREAT] 0o600 in
Unix.unlink name;
fd
with e -> Unix.unlink name; raise e
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...