Module Prime_enummap.Make_monadic
Parameters
Signature
include S
val empty : 'a tThe empty map.
val is_empty : 'a t -> boolHolds for the empty map only.
val cardinal : 'a t -> intcardinal mis the cardinality ofm.
val app : 'a t -> key -> 'a optionapp mis the partial function corresponding tom. This is the same asfindexcept for the argument ordering and that it does not raise any exception.
val find : key -> 'a t -> 'afind k mreturns the binding forkinmor raisesNot_foundif it is unbound.
val find_opt : key -> 'a t -> 'a optionval locate : key -> 'a t -> bool * intlocate k mis a pair(present, pos)wherepresentis true iffkis bound inmandposis the number of keys ofmprecedingk.
val get : 'a t -> int -> 'aget i mis theith value ofm.- raises Invalid_argument
if the index is out of bounds.
val get_binding : 'a t -> int -> key * 'aget_binding m iis theith binding ofmaccording to the key order.
val pred_binding : 'a t -> key -> (key * 'a) optionpred_binding m kis the last binding strictly beforekinm.
val succ_binding : 'a t -> key -> (key * 'a) optionsucc_binding m kis the first binding strictly afterkinm.
val add : key -> 'a -> 'a t -> 'a tadd k e mis the map which agrees withmon all keys except thatkis mapped toe.
val pop : key -> 'a t -> ('a * 'a t) optionpop k misSome (k, remove k m)ifmbindsktoe, otherwiseNone.
val pop_min : 'a t -> key * 'a * 'a tpop_min mis the tuple(k, e, m')where(k, e)is the binding ofmwith the minimal key andm'is the remainder ofm.
val pop_max : 'a t -> key * 'a * 'a tpop_max mis the tuple(k, e, m')where(k, e)is the binding ofmwith the maximum key andm'is the remainder ofm.
val remove : key -> 'a t -> 'a tremove k mis the map which agrees withmon all keys except thatkis unbound. Ifkis unbound inm, thenremove k mism.
val update : key -> ('a option -> 'a option) -> 'a t -> 'a tupdate k f mis the mapmwithkrebound tof vwherevis the current binding ofkinmandNonemeans no binding for both argument and result.
val cut_binding : key -> 'a t -> 'a option * 'a t * 'a tcut_binding k mis(e_opt, sL, sR)wheree_optis the element bound tok, if any, andsLandsRare the submaps ofmwith keys smaller or langer thank, respectively.
val bindings : 'a t -> (key * 'a) listA
(key, element)pair for each binding of the map in key order.
val of_ordered_bindings : (key * 'a) list -> 'a tAssuming
bindingsis a key-ordered list of bindings, as returned frombindings,of_ordered_bindings bindingsis a map containing precisely those bindings, computed in linear time. This is an optimisation ofList.fold (uncurry add) bindings empty.- raises Invalid_argument
of
bindingsis not sorted.
val asc_bindings : ?where:(key -> int) -> 'a t -> (key * 'a) Stdlib.Seq.tasc_bindings ?where mis the sequence of bindings ofein order of increasing keys, optionally restricted to keys in a subrange given bywhere.- parameter where
must be monotonically increasing, in which case the returned bindings will be the continuous range with keys at which this function evaluates to zero.
val dsc_bindings : ?where:(key -> int) -> 'a t -> (key * 'a) Stdlib.Seq.tdsc_bindings ?where mis the sequence of bindings ofmin order of decreasing keys, optionally restricted to keys in a subrange given bywhere.- parameter where
must be monotonically increasing, in which case the returned bindings will be the continuous range with keys at which this function evaluates to zero.
val search : (key -> 'a -> 'b option) -> 'a t -> 'b optionsearch f mis the firstf k efork ↦ einmwhich is different fromNone, orNoneif no such mapping exists inm.
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold f mis the composition off k efor each(k, e)inm, applied in order of increasing keys.
val fold_rev : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold_rev f mis the composition off k efor each(k, e)inmapplied in order of decreasing keys.
val iter : (key -> 'a -> unit) -> 'a t -> unititer f mcallsf k efor each(k, e)inmin order of increasing keys.
val for_all : (key -> 'a -> bool) -> 'a t -> boolfor_all f mis true ifff k eis true for all bindings(k, e)ofm.
val exists : (key -> 'a -> bool) -> 'a t -> boolexists f mis true ifff k efor some binding(k, e)ofm.
val map : ('a -> 'b) -> 'a t -> 'b tmap f mis the minimal map which for each(k, e)ofmcontains(k, f e).
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b tmapi f mis the minimal map which for each(k, e)ofmcontains(k, f k e).
val fmapi : (key -> 'a -> 'b option) -> 'a t -> 'b tfmapi f mis the minimal map which contains(k, e)ifff k e' = Some efor some(k, e')inm.
val filter : (key -> 'a -> bool) -> 'a t -> 'a tfilter f mis the maximal submap ofmsuch thatf k eholds for each binding(k, e).
val compare : ('a -> 'b -> int) -> 'a t -> 'b t -> intcompare fis a total order over maps usingfto compare elements.
val equal : ('a -> 'b -> bool) -> 'a t -> 'b t -> boolequal f m0 m1is true iffm0andm1have the same keys andfis true on the respective mappings for each key.
val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c tmerge f m1 m2is the map containing a binding(k, e)for eachkbound in at least one of the maps, such thatf (find k m1) (find k m2) = Some e.
val finter : (key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tfinter f m1 m2is the minimal map which for each shared keykofm1andm2contains(k, e)iff k m1 m2 = Some efor somee.
val funion : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a tfunion f m1 m2is the minimal map which contains all bindings offinter f m1 m2and all bindings ofm1andm2whose key does not occur in the other map.
val fcompl : (key -> 'a -> 'b -> 'b option) -> 'a t -> 'b t -> 'b tfcompl f m1 m2is the minimal map which contains the bindings offinter f m1 m2and the bindings ofm2with the key not inm1.
val fpatch : (key -> 'a -> 'b option -> 'b option) -> 'a t -> 'b t -> 'b tfpatch f m1 m2is the minimal map which contains the bindings ofm2having keys disjoint fromm1, and which contains(k, e)iff(k, e')is inm1andf k e' (find k m2) = Some e.
val split_union : (key -> 'a -> 'b -> 'c) -> 'a t -> 'b t -> 'a t * 'b t * 'c tsplit_union mA mBis a triple(mA', mB', mC')wheremA'andmB'are the respective bindings ofmAandmBwhich have disjoint keys, andmC'has a binding(k, f k a b)for each pair of bindings(k, a)ofmAand(k, b)ofmBsharingk.
include S_monadic with type key := key and type 'a t := 'a t
val fold_s : (key -> 'a -> 'b -> 'b monad) -> 'a t -> 'b -> 'b monadval iter_s : (key -> 'a -> unit monad) -> 'a t -> unit monadval search_s : (key -> 'a -> 'b option monad) -> 'a t -> 'b option monadval for_all_s : (key -> 'a -> bool monad) -> 'a t -> bool monadval exists_s : (key -> 'a -> bool monad) -> 'a t -> bool monadval filter_s : (key -> 'a -> bool monad) -> 'a t -> 'a t monadval map_s : ('a -> 'b monad) -> 'a t -> 'b t monadval mapi_s : (key -> 'a -> 'b monad) -> 'a t -> 'b t monadval fmapi_s : (key -> 'a -> 'b option monad) -> 'a t -> 'b t monad