Btree.Map
A finite map implemented by a B tree.
module Key : Interfaces.SORTABLE
include Interfaces.MAP with type key = Key.t
type key = Key.t
Type of the keys
val is_empty : 'a t -> bool
Is the map empty?
val cardinal : 'a t -> int
cardinal map
The cardinality of the map i.e. the number of key value pairs in the map.
fold_left f start map
Fold the bindings in the map map
from left to right i.e. lexically ascending using the start value start
for the accumulator and the folding function f
where f
is applied f accue key value
yielding a new accumulator by consuming one key value pair.
fold_left f start map
Fold the bindings in the map map
from right to left i.e. lexically descending using the start value start
for the accumulator and the folding function f
where f
is applied f accu key value
yielding a new accumulator by consuming one key value pair.
find_opt key map
Find the value which is bound to the key key
in the map map
. Return None
if no value is bound to key
.
val empty : 'a t
The empty map.
add key value map
Add the key value pair key, value
to the map. If the map has already a key value pair with the key key
then overwrite the old value with the new value.
remove key map
Remove the key value pair with the key key
from the map map
. If the key is not present, then do nothing.
update key f map
Update the value bound to the key key
in the map map
by the update function f
. If no value is bound to key
then f None
is called. If value
is bound to key
then f (Some value)
is called.
If f
returns None
then no value is added and the old binding is deleted (if it existed before).
If f
return Some new_value
then the old value is updated, if existed, or the new value is added if no old value existed before.
All key value pairs of a finite map can be considered as a sorted list of key value pairs. It is possible to iterate over this sequence with the help of the function fold_left
. However this function performs the whole iteration.
Sometimes it is desirable to iterate over the sequence of the sorted key value pairs and keep the control over the iteration. For that purpose it is convenient to have the finite map as a stream of key value pairs.
val has_more : 'a source -> bool
Has the stream of key value pairs more elements?
advances source
Advance the stream by one element.
Precondition: has_more source
module Source (Value : Interfaces.ANY) : sig ... end
Module which satisfies the interface Interfaces.SOURCE