jon.recoil.org

Module Boxable_number.Map

type key = t
module Set = Set
type !+'a t
val empty : 'a t
val is_empty : 'a t -> bool
val mem : key -> 'a t -> bool
val add : key -> 'a -> 'a t -> 'a t
val update : key -> ('a option -> 'a option) -> 'a t -> 'a t
val singleton : key -> 'a -> 'a t
val remove : key -> 'a t -> 'a t
val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c t
val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t

When the function always returns Some _, union_total has better performance.

val union_sharing : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t

union_sharing f m1 m2 is a version of union f m1 m2 that maximizes sharing of the result with m1.

val union_shared : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t

union_shared f m1 m2 is a version of union_sharing f m1 m2 that also exploits sharing of m1 and m2 to avoid calling f when possible, assuming that f x x = Some x for all xs.

val union_total : (key -> 'a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t

union_total f m1 m2 is the same as union (fun k x y -> Some (f k x y)) m1 m2

val union_total_shared : (key -> 'a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t

union_total_shared f m1 m2 is a version of union_total f m1 m2 that also exploits sharing of m1 and m2 to avoid calling f when possible, assuming that f k x x = x for all keys k and values x. It also maximises sharing with m1.

val union_left_biased : 'a t -> 'a t -> 'a t

union_left_biased m1 m2 is the same as union_total_shared (fun _ l _ -> l) m1 m2

val union_right_biased : 'a t -> 'a t -> 'a t

union_right_biased m1 m2 is the same as union_total_shared (fun _ _ r -> r) m1 m2

val update_many : (key -> 'a option -> 'b -> 'a option) -> 'a t -> 'b t -> 'a t
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val for_all : (key -> 'a -> bool) -> 'a t -> bool
val exists : (key -> 'a -> bool) -> 'a t -> bool
val filter : (key -> 'a -> bool) -> 'a t -> 'a t
val filter_map : (key -> 'a -> 'b option) -> 'a t -> 'b t
val filter_map_sharing : (key -> 'a -> 'a option) -> 'a t -> 'a t
val partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
val cardinal : 'a t -> int
val bindings : 'a t -> (key * 'a) list
val min_binding : 'a t -> key * 'a
val min_binding_opt : 'a t -> (key * 'a) option
val max_binding : 'a t -> key * 'a
val max_binding_opt : 'a t -> (key * 'a) option
val choose : 'a t -> key * 'a
val choose_opt : 'a t -> (key * 'a) option
val split : key -> 'a t -> 'a t * 'a option * 'a t
val find : key -> 'a t -> 'a
val find_opt : key -> 'a t -> 'a option
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
val to_seq : 'a t -> (key * 'a) Seq.t
val print_debug : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
val of_list : (key * 'a) list -> 'a t
val disjoint_union : ?eq:('a -> 'a -> bool) -> ?print:(Format.formatter -> 'a -> unit) -> 'a t -> 'a t -> 'a t
val map_keys : (key -> key) -> 'a t -> 'a t
val keys : 'a t -> Set.t
val data : 'a t -> 'a list
val of_set : (key -> 'a) -> Set.t -> 'a t
val print : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
val subset_domain : 'a t -> 'b t -> bool
val diff_domains : 'a t -> 'b t -> 'a t
val inter : (key -> 'a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val diff : (key -> 'a -> 'b -> 'a option) -> 'a t -> 'b t -> 'a t

diff f m1 m2 computes a map whose keys are a subset of the keys of m1. When a binding is defined in both m1 and m2, the function f is used to combine them. Bindings that are only present in m1 are preserved. This is a special case of merge: diff f m1 m2 is equivalent to merge f' m1 m2, where

  • f' _key None _ = None
  • f' _key (Some v) None = Some v
  • f' key (Some v1) (Some v2) = f key v1 v2
val diff_sharing : (key -> 'a -> 'b -> 'a option) -> 'a t -> 'b t -> 'a t

diff_sharing f m1 m2 is a version of diff f m1 m2 that maximizes sharing of the result with m1.

val diff_shared : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t

diff_shared f m1 m2 is a version of diff_sharing f m1 m2 that further exploits sharing of m1 and m2 to avoid calling f when possible, assuming that f x x always returns None.

val inter_domain_is_non_empty : 'a t -> 'a t -> bool
val get_singleton : 'a t -> (key * 'a) option
val replace : key -> ('a -> 'a) -> 'a t -> 'a t
val map_sharing : ('a -> 'a) -> 'a t -> 'a t