Module Prime_enummap.Make_monadic
Parameters
Signature
include S
val empty : 'a t
The empty map.
val is_empty : 'a t -> bool
Holds for the empty map only.
val cardinal : 'a t -> int
cardinal m
is the cardinality ofm
.
val app : 'a t -> key -> 'a option
app m
is the partial function corresponding tom
. This is the same asfind
except for the argument ordering and that it does not raise any exception.
val find : key -> 'a t -> 'a
find k m
returns the binding fork
inm
or raisesNot_found
if it is unbound.
val find_opt : key -> 'a t -> 'a option
val locate : key -> 'a t -> bool * int
locate k m
is a pair(present, pos)
wherepresent
is true iffk
is bound inm
andpos
is the number of keys ofm
precedingk
.
val get : 'a t -> int -> 'a
get i m
is thei
th value ofm
.- raises Invalid_argument
if the index is out of bounds.
val get_binding : 'a t -> int -> key * 'a
get_binding m i
is thei
th binding ofm
according to the key order.
val pred_binding : 'a t -> key -> (key * 'a) option
pred_binding m k
is the last binding strictly beforek
inm
.
val succ_binding : 'a t -> key -> (key * 'a) option
succ_binding m k
is the first binding strictly afterk
inm
.
val add : key -> 'a -> 'a t -> 'a t
add k e m
is the map which agrees withm
on all keys except thatk
is mapped toe
.
val pop : key -> 'a t -> ('a * 'a t) option
pop k m
isSome (k, remove k m)
ifm
bindsk
toe
, otherwiseNone
.
val pop_min : 'a t -> key * 'a * 'a t
pop_min m
is the tuple(k, e, m')
where(k, e)
is the binding ofm
with the minimal key andm'
is the remainder ofm
.
val pop_max : 'a t -> key * 'a * 'a t
pop_max m
is the tuple(k, e, m')
where(k, e)
is the binding ofm
with the maximum key andm'
is the remainder ofm
.
val remove : key -> 'a t -> 'a t
remove k m
is the map which agrees withm
on all keys except thatk
is unbound. Ifk
is unbound inm
, thenremove k m
ism
.
val update : key -> ('a option -> 'a option) -> 'a t -> 'a t
update k f m
is the mapm
withk
rebound tof v
wherev
is the current binding ofk
inm
andNone
means no binding for both argument and result.
val cut_binding : key -> 'a t -> 'a option * 'a t * 'a t
cut_binding k m
is(e_opt, sL, sR)
wheree_opt
is the element bound tok
, if any, andsL
andsR
are the submaps ofm
with keys smaller or langer thank
, respectively.
val bindings : 'a t -> (key * 'a) list
A
(key, element)
pair for each binding of the map in key order.
val of_ordered_bindings : (key * 'a) list -> 'a t
Assuming
bindings
is a key-ordered list of bindings, as returned frombindings
,of_ordered_bindings bindings
is a map containing precisely those bindings, computed in linear time. This is an optimisation ofList.fold (uncurry add) bindings empty
.- raises Invalid_argument
of
bindings
is not sorted.
val asc_bindings : ?where:(key -> int) -> 'a t -> (key * 'a) Stdlib.Seq.t
asc_bindings ?where m
is the sequence of bindings ofe
in 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.t
dsc_bindings ?where m
is the sequence of bindings ofm
in 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 option
search f m
is the firstf k e
fork ↦ e
inm
which is different fromNone
, orNone
if no such mapping exists inm
.
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold f m
is the composition off k e
for each(k, e)
inm
, applied in order of increasing keys.
val fold_rev : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold_rev f m
is the composition off k e
for each(k, e)
inm
applied in order of decreasing keys.
val iter : (key -> 'a -> unit) -> 'a t -> unit
iter f m
callsf k e
for each(k, e)
inm
in order of increasing keys.
val for_all : (key -> 'a -> bool) -> 'a t -> bool
for_all f m
is true ifff k e
is true for all bindings(k, e)
ofm
.
val exists : (key -> 'a -> bool) -> 'a t -> bool
exists f m
is true ifff k e
for some binding(k, e)
ofm
.
val map : ('a -> 'b) -> 'a t -> 'b t
map f m
is the minimal map which for each(k, e)
ofm
contains(k, f e)
.
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
mapi f m
is the minimal map which for each(k, e)
ofm
contains(k, f k e)
.
val fmapi : (key -> 'a -> 'b option) -> 'a t -> 'b t
fmapi f m
is the minimal map which contains(k, e)
ifff k e' = Some e
for some(k, e')
inm
.
val filter : (key -> 'a -> bool) -> 'a t -> 'a t
filter f m
is the maximal submap ofm
such thatf k e
holds for each binding(k, e)
.
val compare : ('a -> 'b -> int) -> 'a t -> 'b t -> int
compare f
is a total order over maps usingf
to compare elements.
val equal : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
equal f m0 m1
is true iffm0
andm1
have the same keys andf
is true on the respective mappings for each key.
val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c t
merge f m1 m2
is the map containing a binding(k, e)
for eachk
bound 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 t
finter f m1 m2
is the minimal map which for each shared keyk
ofm1
andm2
contains(k, e)
iff k m1 m2 = Some e
for somee
.
val funion : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
funion f m1 m2
is the minimal map which contains all bindings offinter f m1 m2
and all bindings ofm1
andm2
whose key does not occur in the other map.
val fcompl : (key -> 'a -> 'b -> 'b option) -> 'a t -> 'b t -> 'b t
fcompl f m1 m2
is the minimal map which contains the bindings offinter f m1 m2
and the bindings ofm2
with the key not inm1
.
val fpatch : (key -> 'a -> 'b option -> 'b option) -> 'a t -> 'b t -> 'b t
fpatch f m1 m2
is the minimal map which contains the bindings ofm2
having keys disjoint fromm1
, and which contains(k, e)
iff(k, e')
is inm1
andf k e' (find k m2) = Some e
.
val split_union : (key -> 'a -> 'b -> 'c) -> 'a t -> 'b t -> 'a t * 'b t * 'c t
split_union mA mB
is a triple(mA', mB', mC')
wheremA'
andmB'
are the respective bindings ofmA
andmB
which have disjoint keys, andmC'
has a binding(k, f k a b)
for each pair of bindings(k, a)
ofmA
and(k, b)
ofmB
sharingk
.
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 monad
val iter_s : (key -> 'a -> unit monad) -> 'a t -> unit monad
val search_s : (key -> 'a -> 'b option monad) -> 'a t -> 'b option monad
val for_all_s : (key -> 'a -> bool monad) -> 'a t -> bool monad
val exists_s : (key -> 'a -> bool monad) -> 'a t -> bool monad
val filter_s : (key -> 'a -> bool monad) -> 'a t -> 'a t monad
val map_s : ('a -> 'b monad) -> 'a t -> 'b t monad
val mapi_s : (key -> 'a -> 'b monad) -> 'a t -> 'b t monad
val fmapi_s : (key -> 'a -> 'b option monad) -> 'a t -> 'b t monad