1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(* SPDX-License-Identifier: AGPL-3.0-or-later *)
(* Copyright © 2021-2024 OCamlPro *)
(* Written by the Owi programmers *)

type t = int

module Map = Map.Make (Int)

type 'a collection =
  { c : 'a Map.t
  ; last : int
  }

let empty = { c = Map.empty; last = 0 }

let with_fresh_id f { c; last } =
  let open Syntax in
  let+ e, r = f last in
  let c = Map.add last e c in
  let last = succ last in
  ({ c; last }, r)

let get i c = Map.find i c.c

let map f c = { c with c = Map.map f c.c }

module Tbl = Hashtbl.Make (struct
  include Int

  let hash x = x
end)