package server-reason-react

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file Belt_internalBucketsType.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
type 'a opt = 'a Js.undefined

include (
  struct
    type ('hash, 'eq, 'c) container = {
      mutable size : int;
      mutable buckets : 'c opt array;
      hash : 'hash;
      eq : 'eq;
    }

    let container :
        size:int ->
        buckets:'c opt array ->
        hash:'hash ->
        eq:'eq ->
        ('hash, 'eq, 'c) container =
     fun ~size ~buckets ~hash ~eq -> { size; buckets; hash; eq }

    let sizeSet : ('hash, 'eq, 'c) container -> int -> unit =
     fun o v -> o.size <- v

    let size : ('hash, 'eq, 'c) container -> int = fun o -> o.size

    let bucketsSet : ('hash, 'eq, 'c) container -> 'c opt array -> unit =
     fun o v -> o.buckets <- v

    let buckets : ('hash, 'eq, 'c) container -> 'c opt array =
     fun o -> o.buckets

    let hash : ('hash, 'eq, 'c) container -> 'hash = fun o -> o.hash
    let eq : ('hash, 'eq, 'c) container -> 'eq = fun o -> o.eq
  end :
    sig
      type ('hash, 'eq, 'c) container

      val container :
        size:int ->
        buckets:'c opt array ->
        hash:'hash ->
        eq:'eq ->
        ('hash, 'eq, 'c) container

      val sizeSet : ('hash, 'eq, 'c) container -> int -> unit
      val size : ('hash, 'eq, 'c) container -> int
      val bucketsSet : ('hash, 'eq, 'c) container -> 'c opt array -> unit
      val buckets : ('hash, 'eq, 'c) container -> 'c opt array
      val hash : ('hash, 'eq, 'c) container -> 'hash
      val eq : ('hash, 'eq, 'c) container -> 'eq
    end)

module A = Belt_Array

let toOpt = Js.undefinedToOption
let return = Js.Undefined.return
let emptyOpt = Js.undefined

let rec power_2_above x n =
  if x >= n then x else if x * 2 < x then x else power_2_above (x * 2) n

let make ~hash ~eq ~hintSize =
  let s = power_2_above 16 hintSize in
  container ~size:0 ~buckets:(A.makeUninitialized s) ~hash ~eq

let clear h =
  sizeSet h 0;
  let h_buckets = buckets h in
  let len = A.length h_buckets in
  for i = 0 to len - 1 do
    A.setUnsafe h_buckets i emptyOpt
  done

let isEmpty h = size h = 0
OCaml

Innovation. Community. Security.