@@ -26,7 +26,7 @@ type ('a,'b,'id) t =
26
26
27
27
28
28
let clear = C. clear
29
- let size = C. sizeGet
29
+ let size h = h. C. size
30
30
let forEach = N. forEach
31
31
let forEachU = N. forEachU
32
32
let reduce = N. reduce
@@ -46,162 +46,162 @@ let rec copyBucketReHash ~hash ~h_buckets ~ndata_tail old_bucket =
46
46
match C. toOpt old_bucket with
47
47
| None -> ()
48
48
| Some cell ->
49
- let nidx = hash ( N. keyGet cell) [@ bs] land (A. length h_buckets - 1 ) in
49
+ let nidx = hash cell. N. key [@ bs] land (A. length h_buckets - 1 ) in
50
50
let v = C. return cell in
51
51
begin match C. toOpt (A. getUnsafe ndata_tail nidx) with
52
52
| None ->
53
53
A. setUnsafe h_buckets nidx v
54
54
| Some tail ->
55
- N. nextSet tail v (* cell put at the end *)
55
+ tail. N. next < - v (* cell put at the end *)
56
56
end ;
57
57
A. setUnsafe ndata_tail nidx v;
58
- copyBucketReHash ~hash ~h_buckets ~ndata_tail ( N. nextGet cell)
58
+ copyBucketReHash ~hash ~h_buckets ~ndata_tail cell. N. next
59
59
60
60
61
61
let resize ~hash h =
62
- let odata = C. bucketsGet h in
62
+ let odata = h. C. buckets in
63
63
let osize = A. length odata in
64
64
let nsize = osize * 2 in
65
65
if nsize > = osize then begin (* no overflow *)
66
66
let h_buckets = A. makeUninitialized nsize in
67
67
let ndata_tail = A. makeUninitialized nsize in (* keep track of tail *)
68
- C. bucketsSet h h_buckets; (* so that indexfun sees the new bucket count *)
68
+ h. C. buckets < - h_buckets; (* so that indexfun sees the new bucket count *)
69
69
for i = 0 to osize - 1 do
70
70
copyBucketReHash ~hash ~h_buckets ~ndata_tail (A. getUnsafe odata i)
71
71
done ;
72
72
for i = 0 to nsize - 1 do
73
73
match C. toOpt (A. getUnsafe ndata_tail i) with
74
74
| None -> ()
75
- | Some tail -> N. nextSet tail C. emptyOpt
75
+ | Some tail -> tail. N. next < - C. emptyOpt
76
76
done
77
77
end
78
78
79
79
let rec replaceInBucket ~eq key info cell =
80
- if eq ( N. keyGet cell) key [@ bs]
80
+ if eq cell. N. key key [@ bs]
81
81
then
82
82
begin
83
- N. valueSet cell info;
83
+ cell. N. value < - info;
84
84
false
85
85
end
86
86
else
87
- match C. toOpt ( N. nextGet cell) with
87
+ match C. toOpt cell. N. next with
88
88
| None -> true
89
89
| Some cell ->
90
90
replaceInBucket ~eq key info cell
91
91
92
92
let set0 h key value ~eq ~hash =
93
- let h_buckets = C. bucketsGet h in
93
+ let h_buckets = h. C. buckets in
94
94
let buckets_len = A. length h_buckets in
95
95
let i = hash key [@ bs] land (buckets_len - 1 ) in
96
96
let l = A. getUnsafe h_buckets i in
97
97
(match C. toOpt l with
98
98
| None ->
99
- A. setUnsafe h_buckets i (C. return ( N. bucket ~ key ~ value ~ next: C. emptyOpt) );
100
- C. sizeSet h ( C. sizeGet h + 1 );
99
+ A. setUnsafe h_buckets i (C. return { N. key; value; next = C. emptyOpt} );
100
+ h. C. size < - (h. C. size + 1 );
101
101
| Some bucket ->
102
102
if replaceInBucket ~eq key value bucket then begin
103
- A. setUnsafe h_buckets i (C. return ( N. bucket ~ key ~ value ~ next: l) );
104
- C. sizeSet h ( C. sizeGet h + 1 );
103
+ A. setUnsafe h_buckets i (C. return { N. key; value; next = l} );
104
+ h. C. size < - (h. C. size + 1 );
105
105
end
106
106
);
107
- if C. sizeGet h > buckets_len lsl 1 then resize ~hash h
107
+ if h. C. size > buckets_len lsl 1 then resize ~hash h
108
108
109
109
(* if [key] already exists, replace it, otherwise add it
110
110
Here we add it to the head, it could be tail
111
111
*)
112
112
let set h key value =
113
113
set0 h key value
114
- ~eq: (Belt_Id. getEqInternal ( C. eqGet h) )
115
- ~hash: (Belt_Id. getHashInternal ( C. hashGet h) )
114
+ ~eq: (Belt_Id. getEqInternal h. C. eq )
115
+ ~hash: (Belt_Id. getHashInternal h. C. hash )
116
116
117
117
let rec removeInBucket h h_buckets i key prec bucket ~eq =
118
118
match C. toOpt bucket with
119
119
| None -> ()
120
120
| Some cell ->
121
- let cell_next = N. nextGet cell in
122
- if eq ( N. keyGet cell) key [@ bs]
121
+ let cell_next = cell. N. next in
122
+ if eq cell. N. key key [@ bs]
123
123
then
124
124
begin
125
- N. nextSet prec cell_next ;
126
- C. sizeSet h ( C. sizeGet h - 1 );
125
+ prec. N. next < - cell_next ;
126
+ h. C. size < - (h. C. size - 1 );
127
127
end
128
128
else removeInBucket ~eq h h_buckets i key cell cell_next
129
129
130
130
131
131
let remove h key =
132
- let h_buckets = C. bucketsGet h in
133
- let i = (Belt_Id. getHashInternal ( C. hashGet h) ) key [@ bs] land (A. length h_buckets - 1 ) in
132
+ let h_buckets = h. C. buckets in
133
+ let i = (Belt_Id. getHashInternal h. C. hash ) key [@ bs] land (A. length h_buckets - 1 ) in
134
134
let bucket = A. getUnsafe h_buckets i in
135
135
match C. toOpt bucket with
136
136
| None -> ()
137
137
| Some cell ->
138
- let eq = (Belt_Id. getEqInternal ( C. eqGet h) ) in
139
- if eq ( N. keyGet cell ) key [@ bs] then
138
+ let eq = (Belt_Id. getEqInternal h. C. eq ) in
139
+ if eq cell. N. key key [@ bs] then
140
140
begin
141
- A. setUnsafe h_buckets i ( N. nextGet cell) ;
142
- C. sizeSet h ( C. sizeGet h - 1 )
141
+ A. setUnsafe h_buckets i cell. N. next ;
142
+ h. C. size < - (h. C. size - 1 )
143
143
end
144
144
else
145
- removeInBucket ~eq h h_buckets i key cell ( N. nextGet cell)
145
+ removeInBucket ~eq h h_buckets i key cell cell. N. next
146
146
147
147
148
148
let rec getAux ~eq key buckets =
149
149
match C. toOpt buckets with
150
150
| None ->
151
151
None
152
152
| Some cell ->
153
- if eq key ( N. keyGet cell) [@ bs] then Some ( N. valueGet cell)
154
- else getAux ~eq key ( N. nextGet cell)
153
+ if eq key cell. N. key [@ bs] then Some cell. N. value
154
+ else getAux ~eq key cell. N. next
155
155
156
156
let get h key =
157
- let h_buckets = C. bucketsGet h in
158
- let nid = (Belt_Id. getHashInternal ( C. hashGet h) ) key [@ bs] land (A. length h_buckets - 1 ) in
157
+ let h_buckets = h. C. buckets in
158
+ let nid = (Belt_Id. getHashInternal h. C. hash ) key [@ bs] land (A. length h_buckets - 1 ) in
159
159
match C. toOpt @@ A. getUnsafe h_buckets nid with
160
160
| None -> None
161
- | Some cell1 ->
162
- let eq = Belt_Id. getEqInternal ( C. eqGet h) in
163
- if eq key ( N. keyGet cell1) [@ bs] then
164
- Some ( N. valueGet cell1)
161
+ | Some ( cell1 : _ N.bucket ) ->
162
+ let eq = Belt_Id. getEqInternal h. C. eq in
163
+ if eq key cell1.key [@ bs] then
164
+ Some cell1.value
165
165
else
166
- match C. toOpt ( N. nextGet cell1) with
166
+ match C. toOpt cell1. N. next with
167
167
| None -> None
168
168
| Some cell2 ->
169
- if eq key ( N. keyGet cell2) [@ bs] then
170
- Some ( N. valueGet cell2) else
171
- match C. toOpt ( N. nextGet cell2) with
169
+ if eq key cell2.key [@ bs] then
170
+ Some cell2.value else
171
+ match C. toOpt cell2.next with
172
172
| None -> None
173
173
| Some cell3 ->
174
- if eq key ( N. keyGet cell3) [@ bs] then
175
- Some ( N. valueGet cell3)
174
+ if eq key cell3.key [@ bs] then
175
+ Some cell3.value
176
176
else
177
- getAux ~eq key ( N. nextGet cell3)
177
+ getAux ~eq key cell3.next
178
178
179
179
180
180
let rec memInBucket key cell ~eq =
181
- eq ( N. keyGet cell) key [@ bs] ||
182
- (match C. toOpt ( N. nextGet cell) with
181
+ eq cell. N. key key [@ bs] ||
182
+ (match C. toOpt cell. N. next with
183
183
| None -> false
184
184
| Some nextCell ->
185
185
memInBucket ~eq key nextCell)
186
186
187
187
let has h key =
188
- let h_buckets = C. bucketsGet h in
189
- let nid = (Belt_Id. getHashInternal ( C. hashGet h) ) key [@ bs] land (A. length h_buckets - 1 ) in
188
+ let h_buckets = h. C. buckets in
189
+ let nid = (Belt_Id. getHashInternal h. C. hash ) key [@ bs] land (A. length h_buckets - 1 ) in
190
190
let bucket = A. getUnsafe h_buckets nid in
191
191
match C. toOpt bucket with
192
192
| None -> false
193
193
| Some bucket ->
194
- memInBucket ~eq: (Belt_Id. getEqInternal ( C. eqGet h) ) key bucket
194
+ memInBucket ~eq: (Belt_Id. getEqInternal h. C. eq ) key bucket
195
195
196
196
197
197
198
198
199
- let make (type key ) ( type identity ) ~hintSize ~(id : (key,identity) id ) =
199
+ let make (type key identity ) ~hintSize ~(id : (key,identity) id ) =
200
200
let module M = (val id) in
201
201
C. make ~hash: M. hash ~eq: M. eq ~hint Size
202
202
203
203
204
- let fromArray (type a ) ( type identity ) arr ~id :(id :(a,identity) id ) =
204
+ let fromArray (type a identity ) arr ~id :(id :(a,identity) id ) =
205
205
let module M = (val id) in
206
206
let hash, eq = M. hash, M. eq in
207
207
let len = A. length arr in
@@ -214,7 +214,7 @@ let fromArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
214
214
v
215
215
216
216
let mergeMany h arr =
217
- let hash, eq = Belt_Id. getHashInternal ( C. hashGet h) , Belt_Id. getEqInternal ( C. eqGet h) in
217
+ let hash, eq = Belt_Id. getHashInternal h. C. hash , Belt_Id. getEqInternal h. C. eq in
218
218
let len = A. length arr in
219
219
for i = 0 to len - 1 do
220
220
let key,value = (A. getUnsafe arr i) in
0 commit comments