Skip to content

Commit 43e3181

Browse files
committed
dogfood deriving abstract
1 parent 8029a5a commit 43e3181

17 files changed

+1152
-538
lines changed

jscomp/others/.depend

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ js_date.cmj :
3939
js_global.cmj :
4040
js_cast.cmj : js_cast.cmi
4141
js_promise.cmj :
42-
bs_HashMapInt.cmj : bs_internalBuckets.cmj bs_Array.cmj
43-
bs_HashMapString.cmj : bs_internalBuckets.cmj bs_Array.cmj
42+
bs_HashMapInt.cmj : bs_internalBuckets.cmj bs_Array.cmj bs_HashMapInt.cmi
43+
bs_HashMapString.cmj : bs_internalBuckets.cmj bs_Array.cmj \
44+
bs_HashMapString.cmi
4445
node_process.cmi : js_dict.cmi
4546
js_re.cmi :
4647
js_null_undefined.cmi :
@@ -66,3 +67,5 @@ js_dict.cmi :
6667
js_cast.cmi :
6768
dom.cmi : dom_storage.cmi
6869
dom_storage.cmi :
70+
bs_HashMapInt.cmi :
71+
bs_HashMapString.cmi :

jscomp/others/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ bs_HashMapString.ml: hashmap.cppo.ml
6262
cppo -D TYPE_STRING $^ > $@
6363
bs_HashMapInt.ml: hashmap.cppo.ml
6464
cppo -D TYPE_INT $^ > $@
65+
bs_HashMapString.mli: hashmap.cppo.mli
66+
cppo -D TYPE_STRING $^ > $@
67+
bs_HashMapInt.mli: hashmap.cppo.mli
68+
cppo -D TYPE_INT $^ > $@
6569
bs_MapString.ml: map.cppo.ml
6670
cppo -D TYPE_STRING $^ > $@
6771
bs_MapInt.ml: map.cppo.ml

jscomp/others/bs_HashMap.ml

+65-62
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
(* *)
1212
(***********************************************************************)
1313
(** Adapted by Authors of BuckleScript 2017 *)
14-
type ('a, 'b,'id) t0 = ('a,'b,'id) Bs_internalBuckets.t0 =
14+
15+
module N = Bs_internalBuckets
16+
17+
type ('a, 'b,'id) t0 = ('a,'b,'id) N.t0 =
1518
{
1619
mutable size: int; (* number of entries *)
17-
mutable buckets: ('a, 'b) Bs_internalBuckets.bucketlist array; (* the buckets *)
20+
mutable buckets: ('a, 'b) N.bucketlist array; (* the buckets *)
1821
initial_size: int; (* initial array size *)
1922
}
2023

2124

22-
type ('a,'b) buckets = ('a,'b) Bs_internalBuckets.buckets
25+
type ('a,'b) buckets = ('a,'b) N.buckets
2326

2427
type ('a,'b,'id) t = {
2528
dict : ('a, 'id) Bs_Hash.t;
@@ -28,36 +31,36 @@ type ('a,'b,'id) t = {
2831

2932

3033
let rec insert_bucket ~hash ~h_buckets ~ndata_tail h old_bucket =
31-
match Bs_internalBuckets.toOpt old_bucket with
34+
match N.toOpt old_bucket with
3235
| None -> ()
3336
| Some cell ->
34-
let nidx = (Bs_Hash.getHash hash) (Bs_internalBuckets.key cell) [@bs] land (Array.length h_buckets - 1) in
35-
let v = Bs_internalBuckets.return cell in
36-
begin match Bs_internalBuckets.toOpt (Bs_Array.unsafe_get ndata_tail nidx) with
37+
let nidx = (Bs_Hash.getHash hash) (N.key cell) [@bs] land (Array.length h_buckets - 1) in
38+
let v = N.return cell in
39+
begin match N.toOpt (Bs_Array.unsafe_get ndata_tail nidx) with
3740
| None ->
3841
Bs_Array.unsafe_set h_buckets nidx v
3942
| Some tail ->
40-
Bs_internalBuckets.nextSet tail v (* cell put at the end *)
43+
N.nextSet tail v (* cell put at the end *)
4144
end;
4245
Bs_Array.unsafe_set ndata_tail nidx v;
43-
insert_bucket ~hash ~h_buckets ~ndata_tail h (Bs_internalBuckets.next cell)
46+
insert_bucket ~hash ~h_buckets ~ndata_tail h (N.next cell)
4447

4548

4649
let resize ~hash h =
4750
let odata = h.buckets in
4851
let osize = Array.length odata in
4952
let nsize = osize * 2 in
5053
if nsize >= osize then begin (* no overflow *)
51-
let h_buckets = Bs_internalBuckets.makeSize nsize in
52-
let ndata_tail = Bs_internalBuckets.makeSize nsize in (* keep track of tail *)
54+
let h_buckets = N.makeSize nsize in
55+
let ndata_tail = N.makeSize nsize in (* keep track of tail *)
5356
h.buckets <- h_buckets; (* so that indexfun sees the new bucket count *)
5457
for i = 0 to osize - 1 do
5558
insert_bucket ~hash ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
5659
done;
5760
for i = 0 to nsize - 1 do
58-
match Bs_internalBuckets.toOpt (Bs_Array.unsafe_get ndata_tail i) with
61+
match N.toOpt (Bs_Array.unsafe_get ndata_tail i) with
5962
| None -> ()
60-
| Some tail -> Bs_internalBuckets.nextSet tail Bs_internalBuckets.emptyOpt
63+
| Some tail -> N.nextSet tail N.emptyOpt
6164
done
6265
end
6366

@@ -67,150 +70,150 @@ let add0 ~hash h key value =
6770
let h_buckets_lenth = Array.length h_buckets in
6871
let i = (Bs_Hash.getHash hash) key [@bs] land (h_buckets_lenth - 1) in
6972
let bucket =
70-
Bs_internalBuckets.newBuckets ~key ~value ~next:(Bs_Array.unsafe_get h_buckets i) in
71-
Bs_Array.unsafe_set h_buckets i (Bs_internalBuckets.return bucket);
73+
N.buckets ~key ~value ~next:(Bs_Array.unsafe_get h_buckets i) in
74+
Bs_Array.unsafe_set h_buckets i (N.return bucket);
7275
let h_new_size = h.size + 1 in
7376
h.size <- h_new_size;
7477
if h_new_size > h_buckets_lenth lsl 1 then resize ~hash h
7578

7679

7780
let rec remove_bucket ~eq h h_buckets i key prec buckets =
78-
match Bs_internalBuckets.toOpt buckets with
81+
match N.toOpt buckets with
7982
| None -> ()
8083
| Some cell ->
81-
let cell_next = Bs_internalBuckets.next cell in
82-
if (Bs_Hash.getEq eq) (Bs_internalBuckets.key cell) key [@bs]
84+
let cell_next = N.next cell in
85+
if (Bs_Hash.getEq eq) (N.key cell) key [@bs]
8386
then
8487
begin
85-
(match Bs_internalBuckets.toOpt prec with
88+
(match N.toOpt prec with
8689
| None -> Bs_Array.unsafe_set h_buckets i cell_next
87-
| Some c -> Bs_internalBuckets.nextSet c cell_next);
90+
| Some c -> N.nextSet c cell_next);
8891
h.size <- h.size - 1;
8992
end
9093
else remove_bucket ~eq h h_buckets i key buckets cell_next
9194

9295
let remove0 ~hash ~eq h key =
9396
let h_buckets = h.buckets in
9497
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
95-
remove_bucket ~eq h h_buckets i key Bs_internalBuckets.emptyOpt (Bs_Array.unsafe_get h_buckets i)
98+
remove_bucket ~eq h h_buckets i key N.emptyOpt (Bs_Array.unsafe_get h_buckets i)
9699

97100
let rec removeAllBuckets ~eq h h_buckets i key prec buckets =
98-
match Bs_internalBuckets.toOpt buckets with
101+
match N.toOpt buckets with
99102
| None -> ()
100103
| Some cell ->
101-
let cell_next = Bs_internalBuckets.next cell in
102-
if (Bs_Hash.getEq eq) (Bs_internalBuckets.key cell) key [@bs]
104+
let cell_next = N.next cell in
105+
if (Bs_Hash.getEq eq) (N.key cell) key [@bs]
103106
then
104107
begin
105-
(match Bs_internalBuckets.toOpt prec with
108+
(match N.toOpt prec with
106109
| None -> Bs_Array.unsafe_set h_buckets i cell_next
107-
| Some c -> Bs_internalBuckets.nextSet c cell_next);
110+
| Some c -> N.nextSet c cell_next);
108111
h.size <- h.size - 1;
109112
end;
110113
removeAllBuckets ~eq h h_buckets i key buckets cell_next
111114

112115
let removeAll0 ~hash ~eq h key =
113116
let h_buckets = h.buckets in
114117
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
115-
removeAllBuckets ~eq h h_buckets i key Bs_internalBuckets.emptyOpt (Bs_Array.unsafe_get h_buckets i)
118+
removeAllBuckets ~eq h h_buckets i key N.emptyOpt (Bs_Array.unsafe_get h_buckets i)
116119

117120

118121
let rec find_rec ~eq key buckets =
119-
match Bs_internalBuckets.toOpt buckets with
122+
match N.toOpt buckets with
120123
| None ->
121124
None
122125
| Some cell ->
123-
if (Bs_Hash.getEq eq) key (Bs_internalBuckets.key cell) [@bs] then Some (Bs_internalBuckets.value cell)
124-
else find_rec ~eq key (Bs_internalBuckets.next cell)
126+
if (Bs_Hash.getEq eq) key (N.key cell) [@bs] then Some (N.value cell)
127+
else find_rec ~eq key (N.next cell)
125128

126129
let findOpt0 ~hash ~eq h key =
127130
let h_buckets = h.buckets in
128131
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
129-
match Bs_internalBuckets.toOpt @@ Bs_Array.unsafe_get h_buckets nid with
132+
match N.toOpt @@ Bs_Array.unsafe_get h_buckets nid with
130133
| None -> None
131134
| Some cell1 ->
132-
if (Bs_Hash.getEq eq) key (Bs_internalBuckets.key cell1) [@bs] then
133-
Some (Bs_internalBuckets.value cell1)
135+
if (Bs_Hash.getEq eq) key (N.key cell1) [@bs] then
136+
Some (N.value cell1)
134137
else
135-
match Bs_internalBuckets.toOpt (Bs_internalBuckets.next cell1) with
138+
match N.toOpt (N.next cell1) with
136139
| None -> None
137140
| Some cell2 ->
138141
if (Bs_Hash.getEq eq) key
139-
(Bs_internalBuckets.key cell2) [@bs] then
140-
Some (Bs_internalBuckets.value cell2) else
141-
match Bs_internalBuckets.toOpt (Bs_internalBuckets.next cell2) with
142+
(N.key cell2) [@bs] then
143+
Some (N.value cell2) else
144+
match N.toOpt (N.next cell2) with
142145
| None -> None
143146
| Some cell3 ->
144147
if (Bs_Hash.getEq eq) key
145-
(Bs_internalBuckets.key cell3) [@bs] then
146-
Some (Bs_internalBuckets.value cell3)
148+
(N.key cell3) [@bs] then
149+
Some (N.value cell3)
147150
else
148-
find_rec ~eq key (Bs_internalBuckets.next cell3)
151+
find_rec ~eq key (N.next cell3)
149152

150153

151154
let findAll0 ~hash ~eq h key =
152155
let rec find_in_bucket buckets =
153-
match Bs_internalBuckets.toOpt buckets with
156+
match N.toOpt buckets with
154157
| None ->
155158
[]
156159
| Some cell ->
157160
if (Bs_Hash.getEq eq)
158-
(Bs_internalBuckets.key cell) key [@bs]
159-
then (Bs_internalBuckets.value cell) :: find_in_bucket (Bs_internalBuckets.next cell)
160-
else find_in_bucket (Bs_internalBuckets.next cell) in
161+
(N.key cell) key [@bs]
162+
then (N.value cell) :: find_in_bucket (N.next cell)
163+
else find_in_bucket (N.next cell) in
161164
let h_buckets = h.buckets in
162165
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
163166
find_in_bucket (Bs_Array.unsafe_get h_buckets nid)
164167

165168
let rec replace_bucket ~eq key info buckets =
166-
match Bs_internalBuckets.toOpt buckets with
169+
match N.toOpt buckets with
167170
| None ->
168171
true
169172
| Some cell ->
170-
if (Bs_Hash.getEq eq) (Bs_internalBuckets.key cell) key [@bs]
173+
if (Bs_Hash.getEq eq) (N.key cell) key [@bs]
171174
then
172175
begin
173-
Bs_internalBuckets.keySet cell key;
174-
Bs_internalBuckets.valueSet cell info;
176+
N.keySet cell key;
177+
N.valueSet cell info;
175178
false
176179
end
177180
else
178-
replace_bucket ~eq key info (Bs_internalBuckets.next cell)
181+
replace_bucket ~eq key info (N.next cell)
179182

180183
let replace0 ~hash ~eq h key info =
181184
let h_buckets = h.buckets in
182185
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
183186
let l = Array.unsafe_get h_buckets i in
184187
if replace_bucket ~eq key info l then begin
185-
Bs_Array.unsafe_set h_buckets i (Bs_internalBuckets.return
186-
(Bs_internalBuckets.newBuckets ~key ~value:info ~next:l));
188+
Bs_Array.unsafe_set h_buckets i (N.return
189+
(N.buckets ~key ~value:info ~next:l));
187190
h.size <- h.size + 1;
188191
if h.size > Array.length h.buckets lsl 1 then resize ~hash h
189192
end
190193

191194
let rec mem_in_bucket ~eq key buckets =
192-
match Bs_internalBuckets.toOpt buckets with
195+
match N.toOpt buckets with
193196
| None ->
194197
false
195198
| Some cell ->
196199
(Bs_Hash.getEq eq)
197-
(Bs_internalBuckets.key cell) key [@bs] ||
198-
mem_in_bucket ~eq key (Bs_internalBuckets.next cell)
200+
(N.key cell) key [@bs] ||
201+
mem_in_bucket ~eq key (N.next cell)
199202

200203
let mem0 ~hash ~eq h key =
201204
let h_buckets = h.buckets in
202205
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
203206
mem_in_bucket ~eq key (Bs_Array.unsafe_get h_buckets nid)
204207

205208

206-
let create0 = Bs_internalBuckets.create0
207-
let clear0 = Bs_internalBuckets.clear0
208-
let reset0 = Bs_internalBuckets.reset0
209-
let length0 = Bs_internalBuckets.length0
210-
let iter0 = Bs_internalBuckets.iter0
211-
let fold0 = Bs_internalBuckets.fold0
212-
let logStats0 = Bs_internalBuckets.logStats0
213-
let filterMapInplace0 = Bs_internalBuckets.filterMapInplace0
209+
let create0 = N.create0
210+
let clear0 = N.clear0
211+
let reset0 = N.reset0
212+
let length0 = N.length0
213+
let iter0 = N.iter0
214+
let fold0 = N.fold0
215+
let logStats0 = N.logStats0
216+
let filterMapInplace0 = N.filterMapInplace0
214217

215218
(* Wrapper *)
216219
let create dict initialize_size =

0 commit comments

Comments
 (0)