HashSet
A mutable Hash set which allows customized hash behavior.
All data are parameterized by not its only type but also a unique identity in the time of initialization, so that two HashSets of ints initialized with different hash functions will have different type.
Examples
RESmodule I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b))
let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40)
module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b))
let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40)
Belt.HashSet.add(s1, 0)
Belt.HashSet.add(s1, 1)
The invariant must be held: for two elements who are equal, their hashed value should be the same.
Here the compiler would infer s0 and s1 having different type so that it
would not mix.
Signatures:
let s0: Belt.HashSet.t<int, I0.identity> let s1: Belt.HashSet.t<int, I1.identity>
We can add elements to the collection (see last two lines in the example
above). Since this is an mutable data structure, s1 will contain two pairs.
add
RES
let add: (t<'a, 'id>, 'a) => unitclear
RES
let clear: t<'a, 'id> => unitcopy
RES
let copy: t<'a, 'id> => t<'a, 'id>forEach
RES
let forEach: (t<'a, 'id>, 'a => unit) => unitOrder unspecified.
forEachU
Deprecated
Use forEach instead
RES
let forEachU: (t<'a, 'id>, 'a => unit) => unitfromArray
RES
let fromArray: (array<'a>, ~id: id<'a, 'id>) => t<'a, 'id>getBucketHistogram
RES
let getBucketHistogram: t<'a, 'b> => array<int>has
RES
let has: (t<'a, 'id>, 'a) => boolid
RES
type id<'a, 'id> = Belt_Id.hashable<'a, 'id>The type of hash tables from type 'a to type 'b.
isEmpty
RES
let isEmpty: t<'a, 'b> => boollogStats
RES
let logStats: t<'a, 'b> => unitmake
RES
let make: (~hintSize: int, ~id: id<'a, 'id>) => t<'a, 'id>mergeMany
RES
let mergeMany: (t<'a, 'id>, array<'a>) => unitreduce
RES
let reduce: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'cOrder unspecified.
reduceU
Deprecated
Use reduce instead
RES
let reduceU: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'cremove
RES
let remove: (t<'a, 'id>, 'a) => unitsize
RES
let size: t<'a, 'id> => intt
RES
type t<'a, 'id>toArray
RES
let toArray: t<'a, 'id> => array<'a>