API / Belt / HashMapInt

HashMapInt

Specialized when key type is int, more efficient than the generic type

key

RES
type key = int

Type of the Belt.HashMap.Int key.

t

RES
type t<'b>

Type of the Belt.HashMap.Int

make

RES
let make: (~hintSize: int) => t<'b>

make(~hintSize=10) creates a new hash map by taking the hintSize.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "a")

clear

RES
let clear: t<'b> => unit

Clears a hash table.

RES
let hMap = Belt.HashMap.Int.fromArray([(1, "1")]) Belt.HashMap.Int.clear(hMap) Belt.HashMap.Int.isEmpty(hMap) == true

isEmpty

RES
let isEmpty: t<'a> => bool

isEmpty(m) checks whether a hash map is empty.

RES
let hMap = Belt.HashMap.Int.fromArray([(1, "1")]) Belt.HashMap.Int.isEmpty(hMap) == false

set

RES
let set: (t<'a>, key, 'a) => unit

set(tbl, k, v) if k does not exist, add the binding k,v, otherwise, update the old value with the new v.

RES
let hMap = Belt.HashMap.Int.fromArray([(2, "2")]) Belt.HashMap.Int.set(hMap, 1, "1") Belt.HashMap.Int.valuesToArray(hMap) == ["1", "2"]

copy

RES
let copy: t<'a> => t<'a>

Creates copy of a hash map.

RES
let hMap1 = Belt.HashMap.Int.fromArray([(1, "1"), (2, "2")]) let hMap2 = Belt.HashMap.Int.copy(hMap1) Belt.HashMap.Int.set(hMap2, 2, "3") Belt.HashMap.Int.get(hMap1, 2) != Belt.HashMap.Int.get(hMap2, 2)

get

RES
let get: (t<'a>, key) => option<'a>

has

RES
let has: (t<'b>, key) => bool

Returns value bound under specific key. If values not exist returns None.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.get(hMap, 1) == Some("value1") Belt.HashMap.Int.get(hMap, 2) == None

remove

RES
let remove: (t<'a>, key) => unit

If bound exists, removes it from the hash map.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.remove(hMap, 1) Belt.HashMap.Int.has(hMap, 1) == false

forEachU

RES
let forEachU: (t<'b>, (. key, 'b) => unit) => unit

Same as forEach but takes uncurried functon.

forEach

RES
let forEach: (t<'b>, (key, 'b) => unit) => unit

forEach(tbl, f) applies f to all bindings in table tbl. f receives the key as first argument, and the associated value as second argument. Each binding is presented exactly once to f.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.forEach(hMap, (key, value) => Js.log2(key, value)) // prints ("1", "value1")

reduceU

RES
let reduceU: (t<'b>, 'c, (. 'c, key, 'b) => 'c) => 'c

Same as reduce but takes uncurried functon.

reduce

RES
let reduce: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c

reduce(tbl, init, f) computes (f(kN, dN) ... (f(k1, d1, init))...), where k1 ... kN are the keys of all bindings in tbl, and d1 ... dN are the associated values. Each binding is presented exactly once to f.

The order in which the bindings are passed to f is unspecified. However, if the table contains several bindings for the same key, they are passed to f in reverse order of introduction, that is, the most recent binding is passed first.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.reduce(hMap, "", (acc, key, value) => acc ++ (", " ++ value)) == "value1, value2"

keepMapInPlaceU

RES
let keepMapInPlaceU: (t<'a>, (. key, 'a) => option<'a>) => unit

Same as keepMapInPlace but takes uncurried functon.

keepMapInPlace

RES
let keepMapInPlace: (t<'a>, (key, 'a) => option<'a>) => unit

Filters out values for which function f returned None.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.keepMapInPlace(hMap, (key, value) => mod(key, 1) == 0 ? None : Some(value))

size

RES
let size: t<'a> => int

size(tbl) returns the number of bindings in tbl. It takes constant time.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.size(hMap) == 2

toArray

RES
let toArray: t<'a> => array<(key, 'a)>

Returns array of key value pairs.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.toArray(hMap) == [(1, "value1"), (2, "value2")]

keysToArray

RES
let keysToArray: t<'a> => array<key>

Returns array of keys.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.keysToArray(hMap) == [1, 2]

valuesToArray

RES
let valuesToArray: t<'a> => array<'a>

Returns array of values.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "value1") Belt.HashMap.Int.set(hMap, 2, "value2") Belt.HashMap.Int.valuesToArray(hMap) == ["value1", "value2"]

fromArray

RES
let fromArray: array<(key, 'a)> => t<'a>

Creates new hash map from array of pairs.

Returns array of values.

RES
let hMap = Belt.HashMap.Int.fromArray([(1, "value1"), (1, "value2")]) Belt.HashMap.Int.toArray(hMap) == [(1, "value1"), (2, "value2")]

mergeMany

RES
let mergeMany: (t<'a>, array<(key, 'a)>) => unit

Merges many key value pairs into hash map.

RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.mergeMany(hMap, [(1, "value1"), (2, "value2")])

getBucketHistogram

RES
let getBucketHistogram: t<'a> => array<int>
RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "1") Belt.HashMap.Int.getBucketHistogram(hMap)

logStats

RES
let logStats: t<'a> => unit
RES
let hMap = Belt.HashMap.Int.make(~hintSize=10) Belt.HashMap.Int.set(hMap, 1, "1") Belt.HashMap.Int.logStats(hMap)