Module Belt_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.

For example:

type t = int
module I0 =
  (val Belt.Id.hashableU
      ~hash:(fun[\@bs] (a : t)  -> a & 0xff_ff)
      ~eq:(fun[\@bs] a b -> a = b)
  )
let s0 = make ~id:(module I0) ~hintSize:40
module I1 =
  (val Belt.Id.hashableU
      ~hash:(fun[\@bs] (a : t)  -> a & 0xff)
      ~eq:(fun[\@bs] a b -> a = b)
  )
let s1 = make ~id:(module I1) ~hintSize:40

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.

val s0 :  (int, I0.identity) t
val s1 :  (int, I1.identity) t

We can add elements to the collection:

let () =
  add s1 0;
  add s1 1

Since this is an mutable data strucure, s1 will contain two pairs.

module Int = Belt_HashSetInt;

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

module String = Belt_HashSetString;

Specalized when key type is string, more efficient than the generic type

type t('a, 'id);

The type of hash tables from type 'a to type 'b.

type id('a, 'id) = Belt_Id.hashable('a, 'id);
let make: hintSize:int => id:id('a, 'id) => t('a, 'id);
let clear: t('a, 'id) => unit;
let isEmpty: t(_, _) => bool;
let add: t('a, 'id) => 'a => unit;
let copy: t('a, 'id) => t('a, 'id);
let has: t('a, 'id) => 'a => bool;
let remove: t('a, 'id) => 'a => unit;
let forEachU: t('a, 'id) => Js.Fn.arity1(('a => unit)) => unit;
let forEach: t('a, 'id) => ('a => unit) => unit;

Order unspecified.

let reduceU: t('a, 'id) => 'c => Js.Fn.arity2(('c => 'a => 'c)) => 'c;
let reduce: t('a, 'id) => 'c => ('c => 'a => 'c) => 'c;

Order unspecified.

let size: t('a, 'id) => int;
let logStats: t(_, _) => unit;
let toArray: t('a, 'id) => array('a);
let fromArray: array('a) => id:id('a, 'id) => t('a, 'id);
let mergeMany: t('a, 'id) => array('a) => unit;
let getBucketHistogram: t(_, _) => array(int);