Module type OwnMap.S


module type S = sig .. end
The signature for the map, very similar to the Map.S signature (from the OCaml standard library).

type key 
The domain of the map
type img 
The image of the map
type t 
The map itself
val empty : t
The empty map
val is_empty : t -> bool
Tests if the map is empty or not.
val add : key -> img -> t -> t
add x y m returns a map containing the same bindings as m, plus a binding of x to y. If x was already bound in m, its previous binding disappears.
val find : key -> t -> img
Returns the image of the given key. Raises Not_found if the key is not assigned to a value.
val remove : key -> t -> t
remove x m returns a map containing the same bindings as m, except for x which is unbound in the returned map.
val mem : key -> t -> bool
mem x m returns true if m contains a binding for x, and false otherwise.
val iter : (key -> img -> unit) -> t -> unit
iter f m applies f to all bindings in map m. f receives the key as first argument, and the associated value as second argument. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys. Only current bindings are presented to f: bindings hidden by more recent bindings are not passed to f.
val map : (img -> img) -> t -> t
map f m returns a map with same domain as m, where the associated value a of all bindings of m has been replaced by the result of the application of f to a. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.
val mapi : (key -> img -> img) -> t -> t
Same as S.map, but the function receives as arguments both the key and the associated value for each binding of the map.
val fold : (key -> img -> 'a -> 'a) -> t -> 'a -> 'a
fold f m a computes (f kN dN ... (f k1 d1 a)...), where k1 ... kN are the keys of all bindings in m (in increasing order), and d1 ... dN are the associated data.
val compare : t -> t -> int
Total ordering between maps. Here's no need to give a compare function for the images like in the standard library, because the image compare function is know throw the functor parameter Img.compare.
val equal : t -> t -> bool
equal m1 m2 tests whether the maps m1 and m2 are equal, that is, contain equal keys and associate them with equal data. Here's no need to give a compare function for the images like in the standard library, because the image compare function is know throw the functor parameter Img.compare.

New Functions


val add' : key -> img option -> t -> t
add' x y m returns m if y = None, and add x (Some e) m if y = Some e.
val find' : key -> t -> img option
Similar to find, but does not raise an error if no image is found.
val add_list : (key * img) list -> t -> t
add a list of key,img pairs to the map
val to_list : t -> (key * img) list
returns the hole map as list of key,img tuples
val from_list : (key * img) list -> t
creates a new map from a assignment list
val map_to_list : (key -> img -> 'a) -> t -> 'a list
map_to_list f m returns the list of values that f return, if it is applied to the key and image values of the map m.
val mapi_and_map_to_list : (key -> img -> img * 'a) ->
t -> t * 'a list
mapi_and_map_to_list f m returns the list of values that f return, if it is applied to the key and image values of the map m and allows to change the image of the map at the same time.
val domain : t -> key list
Returns the domain of the map as a list of keys
val fold_two : (key -> img option -> img option -> 'a -> 'a) ->
'a -> t -> t -> 'a
fold_two f a m1 m2 fold the two maps m1 and m2 together. For all key \in \dom(m1) \cap \dom(m2) the function gets two Some img parameters, where img is the result of find key m of the corresponding map. If key is only in one of the domains, the image parameter of the other map is set to None.
val restrict : key list -> t -> t
restrict kl m returns a new map, from which all bindings x from m are removed, if they are not part of the key list kl.