logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MoreLabels.Map.Make - Functor building an implementation of the map structure given a totally ordered

Documentation

       Module Make
        : (Ord:OrderedType)->sigend

       Functor building an implementation of the map structure given a totally ordered type.

       Parameters:

       "Ord"

       MoreLabels.Map.OrderedTypeMapstypekey

       The type of the map keys.

       type!+'at

       The type of maps from type key to type 'a .

       valempty : 'at

       The empty map.

       valadd : key:key->data:'a->'at->'atadd~key~datam returns a map containing the same bindings as m , plus a binding of key to data . If key
       was already bound in m to a value that is physically equal to data , m is returned unchanged (the  result
       of the function is then physically equal to m ). Otherwise, the previous binding of key in m disappears.

       Before4.03 Physical equality was not ensured.

       valadd_to_list : key:key->data:'a->'alistt->'alisttadd_to_list~key~datam is m with key mapped to l such that l is data::Map.findkeym if key was bound
       in m and [v] otherwise.

       Since 5.1

       valupdate : key:key->f:('aoption->'aoption)->'at->'atupdate~key~fm  returns  a  map  containing the same bindings as m , except for the binding of key .
       Depending on the value of y where y is f(find_optkeym) , the binding  of  key  is  added,  removed  or
       updated.  If  y  is  None  ,  the  binding is removed if it exists; otherwise, if y is Somez then key is
       associated to z in the resulting map.  If key was already bound in m to a value that is physically  equal
       to z , m is returned unchanged (the result of the function is then physically equal to m ).

       Since 4.06

       valsingleton : key->'a->'atsingletonxy returns the one-element map that contains a binding y for x .

       Since 3.12

       valremove : key->'at->'atremovexm  returns  a  map  containing  the  same bindings as m , except for x which is unbound in the
       returned map.  If x was not in m , m is returned unchanged (the result of the function is then physically
       equal to m ).

       Before4.03 Physical equality was not ensured.

       valmerge : f:(key->'aoption->'boption->'coption)->'at->'bt->'ctmerge~fm1m2 computes a map whose keys are a subset of the keys of m1 and of m2 . The presence of  each
       such  binding, and the corresponding value, is determined with the function f .  In terms of the find_opt
       operation, we have find_optx(mergefm1m2)=fx(find_optxm1)(find_optxm2)  for  any  key  x  ,
       provided that fxNoneNone=None .

       Since 3.12

       valunion : f:(key->'a->'a->'aoption)->'at->'at->'atunion~fm1m2  computes  a  map  whose keys are a subset of the keys of m1 and of m2 .  When the same
       binding is defined in both arguments, the function f is used to combine them.  This is a special case  of
       merge : unionfm1m2 is equivalent to mergef'm1m2 , where

       - f'_keyNoneNone=None

       - f'_key(Somev)None=Somev

       - f'_keyNone(Somev)=Somev

       - f'key(Somev1)(Somev2)=fkeyv1v2Since 4.03

       valcardinal : 'at->int

       Return the number of bindings of a map.

       Since 3.12

   Bindingsvalbindings : 'at->(key*'a)list

       Return  the  list  of  all bindings of the given map.  The returned list is sorted in increasing order of
       keys with respect to the ordering Ord.compare , where Ord is the argument given to MoreLabels.Map.Make .

       Since 3.12

       valmin_binding : 'at->key*'a

       Return the binding with the smallest key in a given map (with respect to the  Ord.compare  ordering),  or
       raise Not_found if the map is empty.

       Since 3.12

       valmin_binding_opt : 'at->(key*'a)option

       Return  the binding with the smallest key in the given map (with respect to the Ord.compare ordering), or
       None if the map is empty.

       Since 4.05

       valmax_binding : 'at->key*'a

       Same as MoreLabels.Map.S.min_binding , but returns the binding with the largest key in the given map.

       Since 3.12

       valmax_binding_opt : 'at->(key*'a)option

       Same as MoreLabels.Map.S.min_binding_opt , but returns the binding with the largest key in the given map.

       Since 4.05

       valchoose : 'at->key*'a

       Return one binding of the given map, or raise Not_found if the map is empty. Which binding is  chosen  is
       unspecified, but equal bindings will be chosen for equal maps.

       Since 3.12

       valchoose_opt : 'at->(key*'a)option

       Return one binding of the given map, or None if the map is empty. Which binding is chosen is unspecified,
       but equal bindings will be chosen for equal maps.

       Since 4.05

   Searchingvalfind : key->'at->'afindxm returns the current value of x in m , or raises Not_found if no binding for x exists.

       valfind_opt : key->'at->'aoptionfind_optxm returns Somev if the current value of x in m is v , or None if no binding for x exists.

       Since 4.05

       valfind_first : f:(key->bool)->'at->key*'afind_first~fm  ,  where  f  is a monotonically increasing function, returns the binding of m with the
       lowest key k such that fk , or raises Not_found if no such key exists.

       For example, find_first(funk->Ord.comparekx>=0)m will return the first binding k,v of  m  where
       Ord.comparekx>=0 (intuitively: k>=x ), or raise Not_found if x is greater than any element of m .

       Since 4.05

       valfind_first_opt : f:(key->bool)->'at->(key*'a)optionfind_first_opt~fm  , where f is a monotonically increasing function, returns an option containing the
       binding of m with the lowest key k such that fk , or None if no such key exists.

       Since 4.05

       valfind_last : f:(key->bool)->'at->key*'afind_last~fm , where f is a monotonically decreasing function,  returns  the  binding  of  m  with  the
       highest key k such that fk , or raises Not_found if no such key exists.

       Since 4.05

       valfind_last_opt : f:(key->bool)->'at->(key*'a)optionfind_last_opt~fm  ,  where f is a monotonically decreasing function, returns an option containing the
       binding of m with the highest key k such that fk , or None if no such key exists.

       Since 4.05

   Traversingvaliter : f:(key:key->data:'a->unit)->'at->unititer~fm 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.

       valfold : f:(key:key->data:'a->'acc->'acc)->'at->init:'acc->'accfold~fm~init computes (fkNdN...(fk1d1init)...)  , where k1...kN are the keys of all  bindings
       in m (in increasing order), and d1...dN are the associated data.

   Transformingvalmap : f:('a->'b)->'at->'btmap~fm 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.

       valmapi : f:(key->'a->'b)->'at->'bt

       Same as MoreLabels.Map.S.map , but the function receives as arguments both the  key  and  the  associated
       value for each binding of the map.

       valfilter : f:(key->'a->bool)->'at->'atfilter~fm returns the map with all the bindings in m that satisfy predicate p . If every binding in m
       satisfies f , m is returned unchanged (the result of the function is then physically equal to m )

       Before4.03 Physical equality was not ensured.

       Since 3.12

       valfilter_map : f:(key->'a->'boption)->'at->'btfilter_map~fm applies the function f to every binding of m , and builds a map  from  the  results.  For
       each binding (k,v) in the input map:

       -if fkv is None then k is not in the result,

       -if fkv is Somev' then the binding (k,v') is in the output map.

       For example, the following function on maps whose values are lists
                 filter_map(fun_kli->matchliwith[]->None|_::tl->Sometl)m

       drops  all  bindings  of m whose value is an empty list, and pops the first element of each value that is
       non-empty.

       Since 4.11

       valpartition : f:(key->'a->bool)->'at->'at*'atpartition~fm returns a pair of maps (m1,m2) , where m1 contains all the bindings of m that satisfy the
       predicate f , and m2 is the map with all the bindings of m that do not satisfy f .

       Since 3.12

       valsplit : key->'at->'at*'aoption*'atsplitxm returns a triple (l,data,r) , where l is the map with all the bindings  of  m  whose  key  is
       strictly  less  than  x  ; r is the map with all the bindings of m whose key is strictly greater than x ;
       data is None if m contains no binding for x , or Somev if m binds v to x .

       Since 3.12

   Predicatesandcomparisonsvalis_empty : 'at->bool

       Test whether a map is empty or not.

       valmem : key->'at->boolmemxm returns true if m contains a binding for x , and false otherwise.

       valequal : cmp:('a->'a->bool)->'at->'at->boolequal~cmpm1m2 tests whether the maps m1 and m2 are equal, that is, contain equal  keys  and  associate
       them with equal data.  cmp is the equality predicate used to compare the data associated with the keys.

       valcompare : cmp:('a->'a->int)->'at->'at->int

       Total ordering between maps.  The first argument is a total ordering used to compare data associated with
       equal keys in the two maps.

       valfor_all : f:(key->'a->bool)->'at->boolfor_all~fm checks if all the bindings of the map satisfy the predicate f .

       Since 3.12

       valexists : f:(key->'a->bool)->'at->boolexists~fm checks if at least one binding of the map satisfies the predicate f .

       Since 3.12

   Convertingvalto_list : 'at->(key*'a)listto_listm is MoreLabels.Map.S.bindingsm .

       Since 5.1

       valof_list : (key*'a)list->'atof_listbs  adds  the  bindings of bs to the empty map, in list order (if a key is bound twice in bs the
       last one takes over).

       Since 5.1

       valto_seq : 'at->(key*'a)Seq.t

       Iterate on the whole map, in ascending order of keys

       Since 4.07

       valto_rev_seq : 'at->(key*'a)Seq.t

       Iterate on the whole map, in descending order of keys

       Since 4.12

       valto_seq_from : key->'at->(key*'a)Seq.tto_seq_fromkm iterates on a subset of the bindings of m , in ascending order of keys,  from  key  k  or
       above.

       Since 4.07

       valadd_seq : (key*'a)Seq.t->'at->'at

       Add the given bindings to the map, in order.

       Since 4.07

       valof_seq : (key*'a)Seq.t->'at

       Build a map from the given bindings

       Since 4.07

OCamldoc                                           2025-06-12                            MoreLabels.Map.Make(3o)

Module

       Module   MoreLabels.Map.Make

Name

       MoreLabels.Map.Make  -  Functor  building  an implementation of the map structure given a totally ordered
       type.

See Also