Module type Map.S

Contents

Instructions: Use this module in your project

In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:

  1. Add the following to your project's dependencies/CMakeLists.txt:

    Copy
    DkSDKProject_DeclareAvailable(ocaml
        CONSTRAINT "= 4.14.0"
        FINDLIBS str unix runtime_events threads dynlink)
    DkSDKProject_MakeAvailable(ocaml)
  2. Add the Findlib::ocaml library to any desired targets in src/*/CMakeLists.txt:

    Copy
    target_link_libraries(YourPackage_YourLibraryName
         # ... existing libraries, if any ...
         Findlib::ocaml)
  3. Click your IDE's Build button

Not using DkSDK?

FIRST, do one or all of the following:

  1. Run:

    Copy
    opam install ocaml.4.14.0
  2. Edit your dune-project and add:

    Copy
    (package
      (name YourExistingPackage)
      (depends
      ; ... existing dependenices ...
      (ocaml (>= 4.14.0))))

    Then run:

    Copy
    dune build *.opam # if this fails, run: dune build
  3. Edit your <package>.opam file and add:

    Copy
    depends: [
      # ... existing dependencies ...
      "ocaml" {>= "4.14.0"}
    ]

    Then run:

    Copy
    opam install . --deps-only

FINALLY, add the library to any desired (library)and/or (executable) targets in your **/dune files:

Copy
(library
  (name YourLibrary)
  ; ... existing library options ...
  (libraries
    ; ... existing libraries ...
    ))

(executable
  (name YourExecutable)
  ; ... existing executable options ...
  (libraries
    ; ... existing libraries ...
    ))
type key

The type of the map keys.

type ``!+'a t

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

valempty :'a t

The empty map.

valis_empty :'a t -> bool

Test whether a map is empty or not.

valmem :key -> 'a t -> bool

mem x m returns true if m contains a binding for x, and false otherwise.

val add : ``key:key -> ``data:'a -> 'a t -> 'a t

add ~key ~data m 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.

  • before 4.03

    Physical equality was not ensured.

val update : ``key:key -> ``f:``('aoption``-> 'aoption``)``-> 'a t -> 'a t

update ~key ~f m 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_opt key m), the binding of key is added, removed or updated. If y is None, the binding is removed if it exists; otherwise, if y is Some z 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.0
valsingleton :key -> 'a -> 'a t

singleton x y returns the one-element map that contains a binding y for x.

  • since 3.12.0
valremove :key -> 'a t -> 'a t

remove x m 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).

  • before 4.03

    Physical equality was not ensured.

val merge : ``f:``(key -> 'aoption``-> 'boption``-> 'coption``)``-> 'a t -> 'b t -> 'c t

merge ~f m1 m2 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_opt x (merge f m1 m2) = f x (find_opt x m1) (find_opt x m2) for any key x, provided that f x None None = None.

  • since 3.12.0
val union : ``f:``(key -> 'a -> 'a -> 'aoption``)``-> 'a t -> 'a t -> 'a t

union ~f m1 m2 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: union f m1 m2 is equivalent to merge f' m1 m2, where

  • f' _key None None = None

  • f' _key (Some v) None = Some v

  • f' _key None (Some v) = Some v

  • f' key (Some v1) (Some v2) = f key v1 v2

  • since 4.03.0

val compare : ``cmp:``('a -> 'a ->int)``-> 'a t -> 'a t -> int

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

val equal : ``cmp:``('a -> 'a ->bool)``-> 'a t -> 'a t -> bool

equal ~cmp m1 m2 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.

val iter : ``f:``(``key:key -> ``data:'a ->unit)``-> 'a 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.

val fold : ``f:``(``key:key -> ``data:'a -> 'b -> 'b)`` -> 'a t -> ``init:'b -> 'b

fold ~f m ~init computes (f kN dN ... (f k1 d1 init)...), where k1 ... kN are the keys of all bindings in m (in increasing order), and d1 ... dN are the associated data.

val for_all : ``f:``(key -> 'a ->bool)``-> 'a t -> bool

for_all ~f m checks if all the bindings of the map satisfy the predicate f.

  • since 3.12.0
val exists : ``f:``(key -> 'a ->bool)``-> 'a t -> bool

exists ~f m checks if at least one binding of the map satisfies the predicate f.

  • since 3.12.0
val filter : ``f:``(key -> 'a ->bool)``-> 'a t -> 'a t

filter ~f m 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)

  • since 3.12.0

  • before 4.03

    Physical equality was not ensured.

val filter_map : ``f:``(key -> 'a -> 'boption``)``-> 'a t -> 'b t

filter_map ~f m 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 f k v is None then k is not in the result,
  • if f k v is Some v' then the binding (k, v') is in the output map.

For example, the following function on maps whose values are lists

Copy
filter_map
  (fun _k li -> match li with [] -> None | _::tl -> Some tl)
  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.0
val partition : ``f:``(key -> 'a ->bool)``-> 'a t -> 'a t*'a t

partition ~f m 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.0
valcardinal :'a t -> int

Return the number of bindings of a map.

  • since 3.12.0
valbindings :'a t -> ``(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 Stdlib.Map.Make.

  • since 3.12.0
valmin_binding :'a t -> 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.0
valmin_binding_opt :'a t -> ``(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 :'a t -> key*'a

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

  • since 3.12.0
valmax_binding_opt :'a t -> ``(key*'a)`` option

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

  • since 4.05
valchoose :'a t -> 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.0
valchoose_opt :'a t -> ``(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
valsplit :key -> 'a t -> 'a t*'aoption`` *'a t

split x m 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 Some v if m binds v to x.

  • since 3.12.0
valfind :key -> 'a t -> 'a

find x m returns the current value of x in m, or raises Not_found if no binding for x exists.

valfind_opt :key -> 'a t -> 'a option

find_opt x m returns Some v if the current value of x in m is v, or None if no binding for x exists.

  • since 4.05
val find_first : ``f:``(key ->bool)``-> 'a t -> key*'a

find_first ~f m, where f is a monotonically increasing function, returns the binding of m with the lowest key k such that f k, or raises Not_found if no such key exists.

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

  • since 4.05
val find_first_opt : ``f:``(key ->bool)``-> 'a t -> ``(key*'a)`` option

find_first_opt ~f m, where f is a monotonically increasing function, returns an option containing the binding of m with the lowest key k such that f k, or None if no such key exists.

  • since 4.05
val find_last : ``f:``(key ->bool)``-> 'a t -> key*'a

find_last ~f m, where f is a monotonically decreasing function, returns the binding of m with the highest key k such that f k, or raises Not_found if no such key exists.

  • since 4.05
val find_last_opt : ``f:``(key ->bool)``-> 'a t -> ``(key*'a)`` option

find_last_opt ~f m, where f is a monotonically decreasing function, returns an option containing the binding of m with the highest key k such that f k, or None if no such key exists.

  • since 4.05
val map : ``f:``('a -> 'b)`` -> 'a t -> 'b 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 : ``f:``(key -> 'a -> 'b)`` -> 'a t -> 'b t

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

Maps and Sequences

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

Iterate on the whole map, in ascending order of keys

  • since 4.07
valto_rev_seq :'a t -> ``(key*'a)`` Seq.t

Iterate on the whole map, in descending order of keys

  • since 4.12
valto_seq_from :key -> 'a t -> ``(key*'a)`` Seq.t

to_seq_from k m iterates on a subset of the bindings of m, in ascending order of keys, from key k or above.

  • since 4.07
val add_seq : ``(key*'a)`` Seq.t -> 'a t -> 'a t

Add the given bindings to the map, in order.

  • since 4.07
val of_seq : ``(key*'a)`` Seq.t -> 'a t

Build a map from the given bindings

  • since 4.07

More from the DkSDK Book

    1. DkSDK
      1. Package capnp
        1. Module Capnp
          1. Module Capnp.Array
          1. Module Capnp.BytesStorage
          1. Module Capnp.Codecs
            1. Module Codecs.FramedStream
            1. Module Codecs.FramingError
          1. Module Capnp.Message
            1. Module Message.BytesMessage
              1. Module BytesMessage.ListStorage
              1. Module BytesMessage.Message
              1. Module BytesMessage.Object
              1. Module BytesMessage.Segment
              1. Module BytesMessage.Slice
              1. Module BytesMessage.StructStorage
            1. Module Message.Make
              1. Module Make.ListStorage
              1. Module Make.Message
              1. Module Make.Object
              1. Module Make.Segment
              1. Module Make.Slice
              1. Module Make.StructStorage
          1. Module Capnp.MessageSig
            1. Module type MessageSig.MESSAGE
            1. Module type MessageSig.S
            1. Module type MessageSig.SEGMENT
            1. Module type MessageSig.SLICE
          1. Module Capnp.RPC
            1. Module RPC.MethodID
              1. Module type RPC.S
            1. Module RPC.None
            1. Module RPC.Registry
          1. Module Capnp.Runtime
            1. Module Runtime.BuilderInc
              1. Module BuilderInc.Make
                1. Module NM.Capability
                1. Module NM.ListStorage
                1. Module NM.Message
                1. Module NM.Object
                1. Module NM.Segment
                1. Module NM.Service
                1. Module NM.Slice
                1. Module NM.StructRef
                1. Module NM.StructStorage
                1. Module NM.Untyped
                1. ...
            1. Module Runtime.BuilderOps
              1. Module BuilderOps.Make
                1. Module ROM.ListStorage
                1. Module ROM.Message
                1. Module ROM.Object
                1. Module ROM.Segment
                1. Module ROM.Slice
                1. Module ROM.StructStorage
                1. Module RWM.Capability
                1. Module RWM.ListStorage
                1. Module RWM.Message
                1. Module RWM.Object
                1. Module RWM.Segment
                1. Module RWM.Service
                1. Module RWM.Slice
                1. Module RWM.StructRef
                1. Module RWM.StructStorage
                1. Module RWM.Untyped
                1. ...
              1. Module BuilderOps.StructSizes
            1. Module Runtime.FarPointer
            1. Module Runtime.FragmentBuffer
            1. Module Runtime.InnerArray
            1. Module Runtime.ListPointer
            1. Module Runtime.ListStorageType
            1. Module Runtime.OtherPointer
            1. Module Runtime.Packing
              1. Module Packing.MixedContext
            1. Module Runtime.Pointer
              1. Module Pointer.Bitfield
            1. Module Runtime.ReaderInc
              1. Module ReaderInc.Make
                1. Module MessageWrapper.Capability
                1. Module MessageWrapper.ListStorage
                1. Module MessageWrapper.Message
                1. Module MessageWrapper.Object
                1. Module MessageWrapper.Segment
                1. Module MessageWrapper.Service
                1. Module MessageWrapper.Slice
                1. Module MessageWrapper.StructRef
                1. Module MessageWrapper.StructStorage
                1. Module MessageWrapper.Untyped
                1. ...
            1. Module Runtime.StructPointer
            1. Module Runtime.Util
        1. Module Capnp_unix
          1. Module Capnp_unix.IO
            1. Module IO.ReadContext
            1. Module IO.WriteContext
      1. Package cmdliner
        1. Module Cmdliner
          1. Module Cmdliner.Arg
          1. Module Cmdliner.Cmd
            1. Module Cmd.Env
            1. Module Cmd.Exit
          1. Module Cmdliner.Manpage
          1. Module Cmdliner.Term
        1. Module Cmdliner_arg
        1. Module Cmdliner_base
        1. Module Cmdliner_cline
        1. Module Cmdliner_cmd
        1. Module Cmdliner_docgen
        1. Module Cmdliner_eval
        1. Module Cmdliner_info
          1. Module Cmdliner_info.Arg
            1. Module Arg.Set
          1. Module Cmdliner_info.Cmd
          1. Module Cmdliner_info.Env
            1. Module Env.Set
          1. Module Cmdliner_info.Eval
          1. Module Cmdliner_info.Exit
        1. Module Cmdliner_manpage
        1. Module Cmdliner_msg
        1. Module Cmdliner_term
        1. Module Cmdliner_term_deprecated
        1. Module Cmdliner_trie
      1. Package fmt
        1. Module Fmt
          1. Module Fmt.Dump
        1. Module Fmt_cli
        1. Module Fmt_tty
      1. Package logs
        1. Module Logs
          1. Module type Logs.LOG
          1. ...
        1. Module Logs_cli
        1. Module Logs_fmt
        1. Module Logs_lwt
          1. Module type Logs_lwt.LOG
        1. Module Logs_threaded
      1. Package lwt
        1. Module Lwt
          1. Module Lwt.Infix
            1. Module Infix.Let_syntax
          1. Module Lwt.Let_syntax
            1. Module Let_syntax.Let_syntax
          1. Module Lwt.Syntax
        1. Module Lwt_bytes
        1. Module Lwt_condition
        1. Module Lwt_config
        1. Module Lwt_engine
          1. Module Lwt_engine.Ev_backend
          1. Module Lwt_engine.Versioned
        1. Module Lwt_features
        1. Module Lwt_fmt
        1. Module Lwt_gc
        1. Module Lwt_io
          1. Module Lwt_io.BE
          1. Module Lwt_io.LE
            1. Module type Lwt_io.NumberIO
          1. Module Lwt_io.Versioned
        1. Module Lwt_list
        1. Module Lwt_main
          1. Module Lwt_main.Enter_iter_hooks
          1. Module Lwt_main.Exit_hooks
          1. Module Lwt_main.Leave_iter_hooks
            1. Module type Lwt_main.Hooks
        1. Module Lwt_mutex
        1. Module Lwt_mvar
        1. Module Lwt_pool
        1. Module Lwt_pqueue
          1. Module Lwt_pqueue.Make
            1. Module type Lwt_pqueue.OrderedType
            1. Module type Lwt_pqueue.S
        1. Module Lwt_preemptive
        1. Module Lwt_process
        1. Module Lwt_result
          1. Module Lwt_result.Infix
          1. Module Lwt_result.Let_syntax
            1. Module Let_syntax.Let_syntax
          1. Module Lwt_result.Syntax
        1. Module Lwt_seq
        1. Module Lwt_sequence
        1. Module Lwt_stream
        1. Module Lwt_switch
        1. Module Lwt_sys
        1. Module Lwt_throttle
          1. Module Lwt_throttle.Make
            1. Module type Lwt_throttle.S
        1. Module Lwt_timeout
        1. Module Lwt_unix
          1. Module Lwt_unix.IO_vectors
          1. Module Lwt_unix.LargeFile
          1. Module Lwt_unix.Versioned
      1. Package mtime
        1. Module Mtime
          1. Module Mtime.Span
        1. Module Mtime_clock
      1. Package ocaml
        1. Module Bigarray
        1. Module Condition
        1. Module Dynlink
        1. Module Event
        1. Module Mutex
        1. Module Profiling
        1. Module Semaphore
          1. Module Semaphore.Binary
          1. Module Semaphore.Counting
        1. Module Stdlib
          1. Module Stdlib.Arg
          1. Module Stdlib.Array
          1. Module Stdlib.ArrayLabels
          1. Module Stdlib.Atomic
          1. Module Stdlib.Bigarray
            1. Module Bigarray.Array0
            1. Module Bigarray.Array1
            1. Module Bigarray.Array2
            1. Module Bigarray.Array3
            1. Module Bigarray.Genarray
          1. Module Stdlib.Bool
          1. Module Stdlib.Buffer
          1. Module Stdlib.Bytes
          1. Module Stdlib.BytesLabels
          1. Module Stdlib.Callback
          1. Module Stdlib.Char
          1. Module Stdlib.Complex
          1. Module Stdlib.Digest
          1. Module Stdlib.Either
          1. Module Stdlib.Ephemeron
            1. Module Ephemeron.GenHashTable
              1. Module GenHashTable.MakeSeeded
            1. Module Ephemeron.K1
              1. Module K1.Bucket
              1. Module K1.Make
              1. Module K1.MakeSeeded
            1. Module Ephemeron.K2
              1. Module K2.Bucket
              1. Module K2.Make
              1. Module K2.MakeSeeded
            1. Module Ephemeron.Kn
              1. Module Kn.Bucket
              1. Module Kn.Make
              1. Module Kn.MakeSeeded
                1. Module type Ephemeron.S
                1. Module type Ephemeron.SeededS
          1. Module Stdlib.Filename
          1. Module Stdlib.Float
            1. Module Float.Array
            1. Module Float.ArrayLabels
          1. Module Stdlib.Format
          1. Module Stdlib.Fun
          1. Module Stdlib.Gc
            1. Module Gc.Memprof
          1. Module Stdlib.Genlex
          1. Module Stdlib.Hashtbl
            1. Module Hashtbl.Make
            1. Module Hashtbl.MakeSeeded
              1. Module type Hashtbl.HashedType
              1. Module type Hashtbl.S
              1. Module type Hashtbl.SeededHashedType
              1. Module type Hashtbl.SeededS
          1. Module Stdlib.In_channel
          1. Module Stdlib.Int
          1. Module Stdlib.Int32
          1. Module Stdlib.Int64
          1. Module Stdlib.LargeFile
          1. Module Stdlib.Lazy
          1. Module Stdlib.Lexing
          1. Module Stdlib.List
          1. Module Stdlib.ListLabels
          1. Module Stdlib.Map
            1. Module Map.Make
              1. Module type Map.OrderedType
              1. Module type Map.S
          1. Module Stdlib.Marshal
          1. Module Stdlib.MoreLabels
            1. Module MoreLabels.Hashtbl
              1. Module Hashtbl.Make
              1. Module Hashtbl.MakeSeeded
            1. Module MoreLabels.Map
              1. Module Map.Make
                1. ...
                1. Module type Map.S
                1. ...
            1. Module MoreLabels.Set
              1. Module Set.Make
          1. Module Stdlib.Nativeint
          1. Module Stdlib.Obj
            1. Module Obj.Closure
            1. Module Obj.Ephemeron
            1. Module Obj.Extension_constructor
          1. Module Stdlib.Oo
          1. Module Stdlib.Option
          1. Module Stdlib.Out_channel
          1. Module Stdlib.Parsing
          1. Module Stdlib.Pervasives
          1. Module Stdlib.Printexc
            1. Module Printexc.Slot
          1. Module Stdlib.Printf
          1. Module Stdlib.Queue
          1. Module Stdlib.Random
            1. Module Random.State
          1. Module Stdlib.Result
          1. Module Stdlib.Scanf
            1. Module Scanf.Scanning
          1. Module Stdlib.Seq
          1. Module Stdlib.Set
            1. Module Set.Make
              1. Module type Set.OrderedType
              1. Module type Set.S
          1. Module Stdlib.Stack
          1. Module Stdlib.StdLabels
          1. Module Stdlib.Stream
          1. Module Stdlib.String
          1. Module Stdlib.StringLabels
          1. Module Stdlib.Sys
            1. Module Sys.Immediate64
              1. Module Immediate64.Make
          1. Module Stdlib.Uchar
          1. Module Stdlib.Unit
          1. Module Stdlib.Weak
            1. Module Weak.Make
              1. Module type Weak.S
        1. Module Str
        1. Module Thread
        1. Module ThreadUnix
        1. Module Topdirs
        1. Module Unix
          1. Module Unix.LargeFile
        1. Module UnixLabels
          1. Module UnixLabels.LargeFile
          1. Module EndianBigstring
            1. Module EndianBigstring.BigEndian
            1. Module EndianBigstring.BigEndian_unsafe
            1. Module EndianBigstring.LittleEndian
            1. Module EndianBigstring.LittleEndian_unsafe
              1. Module type EndianBigstring.EndianBigstringSig
            1. Module EndianBigstring.NativeEndian
            1. Module EndianBigstring.NativeEndian_unsafe
          1. Module EndianBytes
            1. Module EndianBytes.BigEndian
            1. Module EndianBytes.BigEndian_unsafe
            1. Module EndianBytes.LittleEndian
            1. Module EndianBytes.LittleEndian_unsafe
              1. Module type EndianBytes.EndianBytesSig
            1. Module EndianBytes.NativeEndian
            1. Module EndianBytes.NativeEndian_unsafe
          1. Module EndianString
            1. Module EndianString.BigEndian
            1. Module EndianString.BigEndian_unsafe
            1. Module EndianString.LittleEndian
            1. Module EndianString.LittleEndian_unsafe
              1. Module type EndianString.EndianStringSig
            1. Module EndianString.NativeEndian
            1. Module EndianString.NativeEndian_unsafe
      1. Package
      1. Package result
        1. Module Result
      1. Package stdint
        1. Module Stdint
          1. Module Stdint.Int128
          1. Module Stdint.Int16
          1. Module Stdint.Int24
          1. Module Stdint.Int32
          1. Module Stdint.Int40
          1. Module Stdint.Int48
          1. Module Stdint.Int56
          1. Module Stdint.Int64
          1. Module Stdint.Int8
            1. Module type Stdint.Int
          1. Module Stdint.Uint128
          1. Module Stdint.Uint16
          1. Module Stdint.Uint24
          1. Module Stdint.Uint32
          1. Module Stdint.Uint40
          1. Module Stdint.Uint48
          1. Module Stdint.Uint56
          1. Module Stdint.Uint64
          1. Module Stdint.Uint8