Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • bd626d3
  • /
  • parmap_utils.ml
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:e9fe74d09c618fd75badfc5394fcc70f1bf81374
directory badge Iframe embedding
swh:1:dir:bd626d3a844a9e0d01c649d4e255fa860c0587ab
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
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

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top