include Stdlib.Map.S with type key = T.t and type 'a t = 'a Stdlib.Map.Make(T).t
type key = T.tThe type of the map keys.
type 'a t = 'a Stdlib.Map.Make(T).tThe type of maps from type
keyto type'a.
val empty : 'a tThe empty map.
val is_empty : 'a t -> boolTest whether a map is empty or not.
val mem : key -> 'a t -> boolmem x mreturnstrueifmcontains a binding forx, andfalseotherwise.
val add : key -> 'a -> 'a t -> 'a tadd x y mreturns a map containing the same bindings asm, plus a binding ofxtoy. Ifxwas already bound inmto a value that is physically equal toy,mis returned unchanged (the result of the function is then physically equal tom). Otherwise, the previous binding ofxinmdisappears.- before 4.03
Physical equality was not ensured.
val update : key -> ('a option -> 'a option) -> 'a t -> 'a tupdate x f mreturns a map containing the same bindings asm, except for the binding ofx. Depending on the value ofywhereyisf (find_opt x m), the binding ofxis added, removed or updated. IfyisNone, the binding is removed if it exists; otherwise, ifyisSome zthenxis associated tozin the resulting map. Ifxwas already bound inmto a value that is physically equal toz,mis returned unchanged (the result of the function is then physically equal tom).- since
- 4.06.0
val singleton : key -> 'a -> 'a tsingleton x yreturns the one-element map that contains a bindingyforx.- since
- 3.12.0
val remove : key -> 'a t -> 'a tremove x mreturns a map containing the same bindings asm, except forxwhich is unbound in the returned map. Ifxwas not inm,mis returned unchanged (the result of the function is then physically equal tom).- before 4.03
Physical equality was not ensured.
val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c tmerge f m1 m2computes a map whose keys is a subset of keys ofm1and ofm2. The presence of each such binding, and the corresponding value, is determined with the functionf. In terms of thefind_optoperation, we havefind_opt x (merge f m1 m2) = f (find_opt x m1) (find_opt x m2)for any keyx, provided thatf None None = None.- since
- 3.12.0
val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a tunion f m1 m2computes a map whose keys is the union of keys ofm1and ofm2. When the same binding is defined in both arguments, the functionfis used to combine them. This is a special case ofmerge:union f m1 m2is equivalent tomerge f' m1 m2, wheref' _key None None = Nonef' _key (Some v) None = Some vf' _key None (Some v) = Some vf' key (Some v1) (Some v2) = f key v1 v2
- since
- 4.03.0
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intTotal ordering between maps. The first argument is a total ordering used to compare data associated with equal keys in the two maps.
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> boolequal cmp m1 m2tests whether the mapsm1andm2are equal, that is, contain equal keys and associate them with equal data.cmpis the equality predicate used to compare the data associated with the keys.
val iter : (key -> 'a -> unit) -> 'a t -> unititer f mappliesfto all bindings in mapm.freceives the key as first argument, and the associated value as second argument. The bindings are passed tofin increasing order with respect to the ordering over the type of the keys.
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold f m acomputes(f kN dN ... (f k1 d1 a)...), wherek1 ... kNare the keys of all bindings inm(in increasing order), andd1 ... dNare the associated data.
val for_all : (key -> 'a -> bool) -> 'a t -> boolfor_all p mchecks if all the bindings of the map satisfy the predicatep.- since
- 3.12.0
val exists : (key -> 'a -> bool) -> 'a t -> boolexists p mchecks if at least one binding of the map satisfies the predicatep.- since
- 3.12.0
val filter : (key -> 'a -> bool) -> 'a t -> 'a tfilter p mreturns the map with all the bindings inmthat satisfy predicatep. Ifpsatisfies every binding inm,mis returned unchanged (the result of the function is then physically equal tom)- since
- 3.12.0
- before 4.03
Physical equality was not ensured.
val partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a tpartition p mreturns a pair of maps(m1, m2), wherem1contains all the bindings ofsthat satisfy the predicatep, andm2is the map with all the bindings ofsthat do not satisfyp.- since
- 3.12.0
val cardinal : 'a t -> intReturn the number of bindings of a map.
- since
- 3.12.0
val bindings : 'a t -> (key * 'a) listReturn the list of all bindings of the given map. The returned list is sorted in increasing order of keys with respect to the ordering
Ord.compare, whereOrdis the argument given toMap.Make.- since
- 3.12.0
val min_binding : 'a t -> key * 'aReturn the binding with the smallest key in a given map (with respect to the
Ord.compareordering), or raiseNot_foundif the map is empty.- since
- 3.12.0
val min_binding_opt : 'a t -> (key * 'a) optionReturn the binding with the smallest key in the given map (with respect to the
Ord.compareordering), orNoneif the map is empty.- since
- 4.05
val max_binding : 'a t -> key * 'aSame as
Map.S.min_binding, but returns the binding with the largest key in the given map.- since
- 3.12.0
val max_binding_opt : 'a t -> (key * 'a) optionSame as
Map.S.min_binding_opt, but returns the binding with the largest key in the given map.- since
- 4.05
val choose : 'a t -> key * 'aReturn one binding of the given map, or raise
Not_foundif the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.- since
- 3.12.0
val choose_opt : 'a t -> (key * 'a) optionReturn one binding of the given map, or
Noneif the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.- since
- 4.05
val split : key -> 'a t -> 'a t * 'a option * 'a tsplit x mreturns a triple(l, data, r), wherelis the map with all the bindings ofmwhose key is strictly less thanx;ris the map with all the bindings ofmwhose key is strictly greater thanx;dataisNoneifmcontains no binding forx, orSome vifmbindsvtox.- since
- 3.12.0
val find : key -> 'a t -> 'afind x mreturns the current binding ofxinm, or raisesNot_foundif no such binding exists.
val find_opt : key -> 'a t -> 'a optionfind_opt x mreturnsSome vif the current binding ofxinmisv, orNoneif no such binding exists.- since
- 4.05
val find_first : (key -> bool) -> 'a t -> key * 'afind_first f m, wherefis a monotonically increasing function, returns the binding ofmwith the lowest keyksuch thatf k, or raisesNot_foundif no such key exists.For example,
find_first (fun k -> Ord.compare k x >= 0) mwill return the first bindingk, vofmwhereOrd.compare k x >= 0(intuitively:k >= x), or raiseNot_foundifxis greater than any element ofm.- since
- 4.05
val find_first_opt : (key -> bool) -> 'a t -> (key * 'a) optionfind_first_opt f m, wherefis a monotonically increasing function, returns an option containing the binding ofmwith the lowest keyksuch thatf k, orNoneif no such key exists.- since
- 4.05
val find_last : (key -> bool) -> 'a t -> key * 'afind_last f m, wherefis a monotonically decreasing function, returns the binding ofmwith the highest keyksuch thatf k, or raisesNot_foundif no such key exists.- since
- 4.05
val find_last_opt : (key -> bool) -> 'a t -> (key * 'a) optionfind_last_opt f m, wherefis a monotonically decreasing function, returns an option containing the binding ofmwith the highest keyksuch thatf k, orNoneif no such key exists.- since
- 4.05
val map : ('a -> 'b) -> 'a t -> 'b tmap f mreturns a map with same domain asm, where the associated valueaof all bindings ofmhas been replaced by the result of the application offtoa. The bindings are passed tofin increasing order with respect to the ordering over the type of the keys.
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b tSame as
Map.S.map, but the function receives as arguments both the key and the associated value for each binding of the map.
Iterators
val to_seq : 'a t -> (key * 'a) Stdlib.Seq.tIterate on the whole map, in ascending order of keys
- since
- 4.07
val to_seq_from : key -> 'a t -> (key * 'a) Stdlib.Seq.tto_seq_from k miterates on a subset of the bindings ofm, in ascending order of keys, from keykor above.- since
- 4.07
val add_seq : (key * 'a) Stdlib.Seq.t -> 'a t -> 'a tAdd the given bindings to the map, in order.
- since
- 4.07
val of_seq : (key * 'a) Stdlib.Seq.t -> 'a tBuild a map from the given bindings
- since
- 4.07
val filter_map : 'a t -> f:(key -> 'a -> 'b option) -> 'b tval of_list : (key * 'a) list -> 'a tval disjoint_union : ?eq:('a -> 'a -> bool) -> ?print:(Stdlib.Format.formatter -> 'a -> unit) -> 'a t -> 'a t -> 'a tdisjoint_union m1 m2contains all bindings fromm1andm2. If some binding is present in both and the associated value is not equal, a Fatal_error is raised
val union_right : 'a t -> 'a t -> 'a tunion_right m1 m2contains all bindings fromm1andm2. If some binding is present in both, the one fromm2is taken
val union_merge : ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a tval rename : key t -> key -> keyval map_keys : (key -> key) -> 'a t -> 'a tval keys : 'a t -> Stdlib.Set.Make(T).tval data : 'a t -> 'a listval of_set : (key -> 'a) -> Stdlib.Set.Make(T).t -> 'a tval transpose_keys_and_data : key t -> key tval transpose_keys_and_data_set : key t -> Stdlib.Set.Make(T).t tval print : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit