| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (** A native integer module with usual utility functions. *) |
| 12 | |
| 13 | type t = int |
| 14 | |
| 15 | external equal : t -> t -> bool = "%eq" |
| 16 | |
| 17 | external compare : t -> t -> int = "caml_int_compare" |
| 18 | |
| 19 | val hash : t -> int |
| 20 | |
| 21 | module Set : Set.S with type elt = t |
| 22 | module Map : CMap.ExtS with type key = t and module Set := Set |
| 23 | |
| 24 | module List : sig |
| 25 | val mem : int -> int list -> bool |
| 26 | val assoc : int -> (int * 'a) list -> 'a |
| 27 | val mem_assoc : int -> (int * 'a) list -> bool |
| 28 | val remove_assoc : int -> (int * 'a) list -> (int * 'a) list |
| 29 | end |
| 30 | |
| 31 | module PArray : |
| 32 | sig |
| 33 | type 'a t |
| 34 | (** Persistent, auto-resizable arrays. The [get] and [set] functions never |
| 35 | fail whenever the index is between [0] and [Sys.max_array_length - 1]. *) |
| 36 | |
| 37 | val empty : int -> 'a t |
| 38 | (** The empty array, with a given starting size. *) |
| 39 | |
| 40 | val get : 'a t -> int -> 'a option |
| 41 | (** Get a value at the given index. Returns [None] if undefined. *) |
| 42 | |
| 43 | val set : 'a t -> int -> 'a option -> 'a t |
| 44 | (** Set/unset a value at the given index. *) |
| 45 | end |
| 46 | |
| 47 | module PMap : |
| 48 | sig |
| 49 | type key = int |
| 50 | type 'a t |
| 51 | val empty : 'a t |
| 52 | val is_empty : 'a t -> bool |
| 53 | val mem : key -> 'a t -> bool |
| 54 | val add : key -> 'a -> 'a t -> 'a t |
| 55 | val singleton : key -> 'a -> 'a t |
| 56 | val remove : key -> 'a t -> 'a t |
| 57 | (* val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c t *) |
| 58 | (* val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int *) |
| 59 | (* val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool *) |
| 60 | val iter : (key -> 'a -> unit) -> 'a t -> unit |
| 61 | val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b |
| 62 | val for_all : (key -> 'a -> bool) -> 'a t -> bool |
| 63 | val exists : (key -> 'a -> bool) -> 'a t -> bool |
| 64 | (* val filter : (key -> 'a -> bool) -> 'a t -> 'a t *) |
| 65 | (* val partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a t *) |
| 66 | (* val cardinal : 'a t -> int *) |
| 67 | (* val bindings : 'a t -> (key * 'a) list *) |
| 68 | (* val min_binding : 'a t -> key * 'a *) |
| 69 | (* val max_binding : 'a t -> key * 'a *) |
| 70 | (* val choose : 'a t -> key * 'a *) |
| 71 | (* val split : key -> 'a t -> 'a t * 'a option * 'a t *) |
| 72 | val find : key -> 'a t -> 'a |
| 73 | (* val map : ('a -> 'b) -> 'a t -> 'b t *) |
| 74 | (* val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t *) |
| 75 | val domain : 'a t -> Set.t |
| 76 | val cast : 'a t -> 'a Map.t |
| 77 | end |
| 78 | (** This is a (partial) implementation of a [Map] interface on integers, except |
| 79 | that it internally uses persistent arrays. This ensures O(1) accesses in |
| 80 | non-backtracking cases. It is thus better suited for zero-starting, |
| 81 | contiguous keys, or otherwise a lot of space will be empty. To keep track of |
| 82 | the present keys, a binary tree is also used, so that adding a key is |
| 83 | still logarithmic. It is therefore essential that most of the operations |
| 84 | are accesses and not add/removes. *) |