API / Belt / HashSet

You are currently looking at the < v8.2.0 docs (Reason v3.6 syntax edition). You can find the latest API docs here.

(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)

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.

RE
type t = int; module I0 = ( val Belt.Id.hashableU( ~hash=(. a: t) => a land 65535, ~eq=(. a, b) => a == b, ) ); let s0 = Belt.HashSet.make(~id=(module I0), ~hintSize=40); module I1 = ( val Belt.Id.hashableU( ~hash=(. a: t) => a land 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.

RE
let s0: t(int, I0.identity); let s1: 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.

t

RE
type t('a, 'id);

id

RE
type id('a, 'id) = BeltId.hashable('a, 'id);

make

RE
let make: (~hintSize: int, ~id: id('a, 'id)) => t('a, 'id);

clear

RE
let clear: t('a, 'id) => unit;

isEmpty

RE
let isEmpty: t('a, 'b) => bool;

add

RE
let add: (t('a, 'id), 'a) => unit;

copy

RE
let copy: t('a, 'id) => t('a, 'id);

has

RE
let has: (t('a, 'id), 'a) => bool;

remove

RE
let remove: (t('a, 'id), 'a) => unit;

forEachU

RE
let forEachU: (t('a, 'id), [@bs] ('a => unit)) => unit;

forEach

RE
let forEach: (t('a, 'id), 'a => unit) => unit;

Order unspecified.

reduceU

RE
let reduceU: (t('a, 'id), 'c, [@bs] (('c, 'a) => 'c)) => 'c;

reduce

RE
let reduce: (t('a, 'id), 'c, ('c, 'a) => 'c) => 'c;

Order unspecified.

size

RE
let size: t('a, 'id) => int;

logStats

RE
let logStats: t('a, 'b) => unit;

toArray

RE
let toArray: t('a, 'id) => array('a);

fromArray

RE
let fromArray: (array('a), ~id: id('a, 'id)) => t('a, 'id);

mergeMany

RE
let mergeMany: (t('a, 'id), array('a)) => unit;

getBucketHistogram

RE
let getBucketHistogram: t('a, 'b) => array(int);