PatriciaTree.MakeCustom
Create an Heterogeneous map with a custom Node
.
module Key : HeterogeneousKey
include BaseMap_S
with type 'a key = 'a Key.t
with type ('k, 'm) value = ('k, 'm) Value.t
with type 'm t = 'm Node.t
include Node
with type 'a key = 'a Key.t
with type ('k, 'm) value = ('k, 'm) Value.t
with type 'm t = 'm Node.t
type 'a key = 'a Key.t
The type of keys.
type ('k, 'm) value = ('k, 'm) Value.t
The type of value, which depends on the type of the key and the type of the map.
type 'm t = 'm Node.t
The type of the map, which is parameterized by a type.
val empty : 'map t
type 'map view = private
| Empty : 'map view
Can happen only at the toplevel: there is no empty interior node.
*)| Branch : {
} -> 'map view
Branching bit contains only one bit set; the corresponding mask is (branching_bit - 1). The prefixes are normalized: the bits below the branching bit are set to zero (i.e. prefix & (branching_bit - 1) = 0).
*)| Leaf : {
} -> 'map view
A key -> value mapping.
*)This makes the map nodes accessible to the pattern matching algorithm; this corresponds 1:1 to the SimpleNode implementation. This just needs to be copy-and-pasted for every node type.
val is_empty : 'map t -> bool
val min_binding : 'a t -> 'a key_value_pair
val max_binding : 'a t -> 'a key_value_pair
val cardinal : 'a t -> int
The size of the map
val is_singleton : 'a t -> 'a key_value_pair option
is_singleton m
returns Some(KeyValue(k,v))
if and only if m
contains a unique binding k->v
.
Same as find
, but returns None
for Not_found
val pop_minimum : 'map t -> ('map key_value_pair * 'map t) option
val pop_maximum : 'map t -> ('map key_value_pair * 'map t) option
split key map
splits the map into:
map
whose keys are smaller than key
key
(if present)map
whose keys are bigger than key
Where the order is given by Key.to_int
.iter m f
calls f.f
on all bindings of m
, in the order given by Key.to_int
fold m f acc
returns f.f key_n value_n (... (f.f key_1 value_1 acc))
where (key_1, value_1) ... (key_n, value_n)
are the bindings of m
, in the order given by Key.to_int
.
val filter : 'map t -> 'map polypredicate -> 'map t
filter m f
returns the submap of m
containing the bindings k->v
such that f.f k v = true
. f.f
is called in the order given by Key.to_int
val for_all : 'map t -> 'map polypredicate -> bool
for_all m f
checks that f
holds on all bindings of m
7 Short-circuiting.
In the following, the *no_share function allows taking arguments of different types (but cannot share subtrees of the map), while the default functions attempt to preserve and benefit from sharing the subtrees (using physical equality to detect sharing).
map m f
and map_no_share m f
replace all bindings (k,v)
by (k, f.f k v)
. Bindings are examined in the order given by Key.to_int
.
val filter_map : 'map t -> ('map, 'map) polyfilter_map -> 'map t
filter_map m f
and filter_map_no_share m f
remove the bindings (k,v)
for which f.f k v
is None
, and replaces the bindings (k,v)
for which f.f k v
is Some v'
by (k,v')
. Bindings are examined in the order given by Key.to_int
.
val pretty :
?pp_sep:(Stdlib.Format.formatter -> unit -> unit) ->
'map polypretty ->
Stdlib.Format.formatter ->
'map t ->
unit
Pretty-prints a map using the given formatter. pp_sep
is called once between each binding, it defaults to Format.pp_print_cut
. Bindings are printed in the order given by Key.to_int
val reflexive_same_domain_for_all2 :
'map t ->
'map t ->
('map, 'map) polysame_domain_for_all2 ->
bool
val nonreflexive_same_domain_for_all2 :
'map1 t ->
'map2 t ->
('map1, 'map2) polysame_domain_for_all2 ->
bool
val reflexive_subset_domain_for_all2 :
'map t ->
'map t ->
('map, 'map) polysame_domain_for_all2 ->
bool
idempotent_union map1 map2 f
returns a map whose keys is the union of the keys of map1
and map2
. f.f
is used to combine the values of keys mapped in both maps. @assumes f.f
idempotent (i.e. f key value value == value
) f.f
is called in the order given by Key.to_int
. f.f
is never called on physically equal values. Preserves physical equality as much as possible. Complexity is O(log(n)*Delta) where Delta is the number of different keys between map1
and map2
.
idempotent_inter map1 map2 f
returns a map whose keys is the intersection of the keys of map1
and map2
. f.f
is used to combine the values a key is mapped in both maps. @assumes f.f
idempotent (i.e. f key value value == value
) f.f
is called in the order given by Key.to_int
. f.f
is never called on physically equal values. Preserves physical equality as much as possible. Complexity is O(log(n)*Delta) where Delta is the number of different keys between map1
and map2
.
nonidempotent_inter_no_share map1 map2 f
is the same as idempotent_inter
but doesn't preverse physical equality, doesn't assume f.f
is idempotent, and can change the type of values. f.f
is called on every shared binding. f.f
is called in increasing order of keys. O(n) complexity
val idempotent_inter_filter :
'a t ->
'a t ->
('a, 'a, 'a) polyinterfilter ->
'a t
idempotent_inter_filter map1 map2 f
is the same as idempotent_inter
but f.f
can return None
to remove a binding from the resutling map.
module WithForeign (Map2 : BaseMap_S with type 'a key = 'a key) : sig ... end