API / Belt / MapInt

# MapInt

Specalized when key type is `int`, more efficient than the generic type, its compare behavior is fixed using the built-in comparison

## key

```RES```type key = int
``````

## t

```RES```type t<'value>
``````

The type of maps from type `key` to type `'value`.

## empty

``````let empty: t<'v>
``````

## isEmpty

``````let isEmpty: t<'v> => bool
``````

## has

``````let has: (t<'v>, key) => bool
``````

## cmpU

``````let cmpU: (t<'v>, t<'v>, (. 'v, 'v) => int) => int
``````

## cmp

``````let cmp: (t<'v>, t<'v>, ('v, 'v) => int) => int
``````

## eqU

``````let eqU: (t<'v>, t<'v>, (. 'v, 'v) => bool) => bool
``````

## eq

``````let eq: (t<'v>, t<'v>, ('v, 'v) => bool) => bool
``````

`eq(m1,m2)` tests whether the maps `m1` and `m2` are equal, that is, contain equal keys and associate them with equal data.

## findFirstByU

``````let findFirstByU: (t<'v>, (. key, 'v) => bool) => option<(key, 'v)>
``````

## findFirstBy

``````let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)>
``````

`findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`.

```RES```let s0 = Belt.Map.Int.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")])

Belt.Map.Int.findFirstBy(s0, (k, v) => k == 4) == Some((4, "4"))
``````

## forEachU

``````let forEachU: (t<'v>, (. key, 'v) => unit) => unit
``````

## forEach

``````let forEach: (t<'v>, (key, 'v) => unit) => unit
``````

`forEach(m, f)` 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.

## reduceU

``````let reduceU: (t<'v>, 'v2, (. 'v2, key, 'v) => 'v2) => 'v2
``````

## reduce

``````let reduce: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2
``````

`reduce(m, a, f)` 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.

## everyU

``````let everyU: (t<'v>, (. key, 'v) => bool) => bool
``````

## every

``````let every: (t<'v>, (key, 'v) => bool) => bool
``````

`every(m, p)` checks if all the bindings of the map satisfy the predicate `p`. Order unspecified

## someU

``````let someU: (t<'v>, (. key, 'v) => bool) => bool
``````

## some

``````let some: (t<'v>, (key, 'v) => bool) => bool
``````

`some(m, p)` checks if at least one binding of the map satisfy the predicate `p`. Order unspecified

## size

``````let size: t<'v> => int
``````

## toList

``````let toList: t<'v> => list<(key, 'v)>
``````

In increasing order.

## toArray

``````let toArray: t<'v> => array<(key, 'v)>
``````

## fromArray

``````let fromArray: array<(key, 'v)> => t<'v>
``````

## keysToArray

``````let keysToArray: t<'v> => array<key>
``````

## valuesToArray

``````let valuesToArray: t<'v> => array<'v>
``````

## minKey

``````let minKey: t<'a> => option<key>
``````

## minKeyUndefined

``````let minKeyUndefined: t<'a> => Js.undefined<key>
``````

## maxKey

``````let maxKey: t<'a> => option<key>
``````

## maxKeyUndefined

``````let maxKeyUndefined: t<'a> => Js.undefined<key>
``````

## minimum

``````let minimum: t<'v> => option<(key, 'v)>
``````

## minUndefined

``````let minUndefined: t<'v> => Js.undefined<(key, 'v)>
``````

## maximum

``````let maximum: t<'v> => option<(key, 'v)>
``````

## maxUndefined

``````let maxUndefined: t<'v> => Js.undefined<(key, 'v)>
``````

## get

``````let get: (t<'v>, key) => option<'v>
``````

## getUndefined

``````let getUndefined: (t<'v>, key) => Js.undefined<'v>
``````

## getWithDefault

``````let getWithDefault: (t<'v>, key, 'v) => 'v
``````

## getExn

``````let getExn: (t<'v>, key) => 'v
``````

## checkInvariantInternal

``````let checkInvariantInternal: t<'a> => unit
``````

raise when invariant is not held

## remove

``````let remove: (t<'v>, key) => t<'v>
``````

`remove(m, x)` returns a map containing the same bindings as `m`, except for `x` which is unbound in the returned map.

## removeMany

``````let removeMany: (t<'v>, array<key>) => t<'v>
``````

## set

``````let set: (t<'v>, key, 'v) => t<'v>
``````

`set(m, x, y)` 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.

## updateU

``````let updateU: (t<'v>, key, (. option<'v>) => option<'v>) => t<'v>
``````

## update

``````let update: (t<'v>, key, option<'v> => option<'v>) => t<'v>
``````

## mergeU

``````let mergeU: (t<'v>, t<'v2>, (. key, option<'v>, option<'v2>) => option<'c>) => t<'c>
``````

## merge

``````let merge: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c>
``````

`merge(m1, m2, f)` computes a map whose keys is a subset of keys of `m1` and of `m2`. The presence of each such binding, and the corresponding value, is determined with the function `f`.

## mergeMany

``````let mergeMany: (t<'v>, array<(key, 'v)>) => t<'v>
``````

## keepU

``````let keepU: (t<'v>, (. key, 'v) => bool) => t<'v>
``````

## keep

``````let keep: (t<'v>, (key, 'v) => bool) => t<'v>
``````

## partitionU

``````let partitionU: (t<'v>, (. key, 'v) => bool) => (t<'v>, t<'v>)
``````

## partition

``````let partition: (t<'v>, (key, 'v) => bool) => (t<'v>, t<'v>)
``````

`partition(m, p)` returns a pair of maps `(m1, m2)`, where `m1` contains all the bindings of `s` that satisfy the predicate `p`, and `m2` is the map with all the bindings of `s` that do not satisfy `p`.

## split

``````let split: (key, t<'v>) => (t<'v>, option<'v>, t<'v>)
``````

`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`.

## mapU

``````let mapU: (t<'v>, (. 'v) => 'v2) => t<'v2>
``````

## map

``````let map: (t<'v>, 'v => 'v2) => t<'v2>
``````

`map(m, f)` 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.

## mapWithKeyU

``````let mapWithKeyU: (t<'v>, (. key, 'v) => 'v2) => t<'v2>
``````

## mapWithKey

``````let mapWithKey: (t<'v>, (key, 'v) => 'v2) => t<'v2>
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.5138328,"math_prob":0.95418733,"size":5334,"snap":"2023-40-2023-50","text_gpt3_token_len":1897,"char_repetition_ratio":0.215197,"word_repetition_ratio":0.15509762,"special_character_ratio":0.36839145,"punctuation_ratio":0.20329218,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9969461,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-28T01:35:18Z\",\"WARC-Record-ID\":\"<urn:uuid:1f0ef80b-6a8f-4b62-a5e3-d98e2693f736>\",\"Content-Length\":\"155302\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:66e4ef67-5970-4ce5-a505-b412cd54ee0a>\",\"WARC-Concurrent-To\":\"<urn:uuid:23cf472e-72ea-41a0-aff3-8c1e4297e230>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"https://rescript-lang.org.cn/docs/manual/latest/api/belt/map-int\",\"WARC-Payload-Digest\":\"sha1:4EBIRW45CGEBRJXI5UDCPQQNR74F7Y6L\",\"WARC-Block-Digest\":\"sha1:HEM2OS5CEN6RXPK5PNBWLKWGEUXWGWDQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510334.9_warc_CC-MAIN-20230927235044-20230928025044-00769.warc.gz\"}"}