-
Notifications
You must be signed in to change notification settings - Fork 460
/
Copy pathhashtblLabels.res
129 lines (110 loc) · 3.61 KB
/
hashtblLabels.res
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* ************************************************************************ */
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/* ************************************************************************ */
/* Hash tables */
type t<'a, 'b> = Hashtbl.t<'a, 'b>
let {
create,
clear,
reset,
copy,
add,
find,
find_opt,
find_all,
mem,
remove,
replace,
iter,
filter_map_inplace,
fold,
length,
randomize,
is_randomized,
stats,
hash,
seeded_hash,
hash_param,
seeded_hash_param,
} = module(Hashtbl)
let add = (tbl, ~key, ~data) => add(tbl, key, data)
let replace = (tbl, ~key, ~data) => replace(tbl, key, data)
let iter = (~f, tbl) => iter((key, data) => f(~key, ~data), tbl)
let filter_map_inplace = (~f, tbl) => filter_map_inplace((key, data) => f(~key, ~data), tbl)
let fold = (~f, tbl, ~init) => fold((key, data, acc) => f(~key, ~data, acc), tbl, init)
type statistics = Hashtbl.statistics = {
num_bindings: int,
num_buckets: int,
max_bucket_length: int,
bucket_histogram: array<int>,
}
/* Functorial interface */
module type HashedType = Hashtbl.HashedType
module type SeededHashedType = Hashtbl.SeededHashedType
module type S = {
type rec key
and t<'a>
let create: int => t<'a>
let clear: t<'a> => unit
let reset: t<'a> => unit
let copy: t<'a> => t<'a>
let add: (t<'a>, ~key: key, ~data: 'a) => unit
let remove: (t<'a>, key) => unit
let find: (t<'a>, key) => 'a
let find_opt: (t<'a>, key) => option<'a>
let find_all: (t<'a>, key) => list<'a>
let replace: (t<'a>, ~key: key, ~data: 'a) => unit
let mem: (t<'a>, key) => bool
let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit
let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit
let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b
let length: t<'a> => int
let stats: t<'a> => statistics
}
module type SeededS = {
type rec key
and t<'a>
let create: (~random: bool=?, int) => t<'a>
let clear: t<'a> => unit
let reset: t<'a> => unit
let copy: t<'a> => t<'a>
let add: (t<'a>, ~key: key, ~data: 'a) => unit
let remove: (t<'a>, key) => unit
let find: (t<'a>, key) => 'a
let find_opt: (t<'a>, key) => option<'a>
let find_all: (t<'a>, key) => list<'a>
let replace: (t<'a>, ~key: key, ~data: 'a) => unit
let mem: (t<'a>, key) => bool
let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit
let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit
let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b
let length: t<'a> => int
let stats: t<'a> => statistics
}
module MakeSeeded = (H: SeededHashedType): (SeededS with type key = H.t) => {
include Hashtbl.MakeSeeded(H)
let add = (tbl, ~key, ~data) => add(tbl, key, data)
let replace = (tbl, ~key, ~data) => replace(tbl, key, data)
let iter = (~f, tbl) => iter((key, data) => f(~key, ~data), tbl)
let filter_map_inplace = (~f, tbl) => filter_map_inplace((key, data) => f(~key, ~data), tbl)
let fold = (~f, tbl, ~init) => fold((key, data, acc) => f(~key, ~data, acc), tbl, init)
}
module Make = (H: HashedType): (S with type key = H.t) => {
include MakeSeeded({
type t = H.t
let equal = H.equal
let hash = (_seed: int, x) => H.hash(x)
})
let create = sz => create(~random=false, sz)
}