@@ -300,31 +300,36 @@ let[@inline] get t =
300
300
301
301
(* *)
302
302
303
- let rec assoc_exn t key = function
304
- | Nil -> raise_notrace Not_found
305
- | Cons r -> if t r.key key then r.value else assoc_exn t key r.rest
303
+ let rec assoc_node t key = function
304
+ | Nil -> ( Nil : (_, _, [< `Nil | `Cons ] ) tdt)
305
+ | Cons r as cons -> if t r.key key then cons else assoc_node t key r.rest
306
306
307
- let find_exn t key =
307
+ let find_node t key =
308
308
(* Reads can proceed in parallel with writes. *)
309
309
let r = Atomic. get t in
310
310
let h = r.hash key in
311
311
let mask = Array. length r.buckets - 1 in
312
312
let i = h land mask in
313
313
match Atomic. get (Array. unsafe_get r.buckets i) with
314
- | B Nil -> raise_notrace Not_found
315
- | B (Cons cons_r ) ->
316
- if r.equal cons_r.key key then cons_r.value
317
- else assoc_exn r.equal key cons_r.rest
314
+ | B Nil -> Nil
315
+ | B (Cons cons_r as cons ) ->
316
+ if r.equal cons_r.key key then cons
317
+ else assoc_node r.equal key cons_r.rest
318
318
| B (Resize resize_r ) ->
319
319
(* A resize is in progress. The spine of the resize still holds what was
320
320
in the bucket before resize reached that bucket. *)
321
- assoc_exn r.equal key resize_r.spine
321
+ assoc_node r.equal key resize_r.spine
322
322
323
323
(* *)
324
324
325
- let rec mem t key = function
326
- | Nil -> false
327
- | Cons r -> t key r.key || mem t key r.rest
325
+ let find_exn t key =
326
+ match find_node t key with
327
+ | Nil -> raise_notrace Not_found
328
+ | Cons r -> r.value
329
+
330
+ let mem t key = find_node t key != Nil
331
+
332
+ (* *)
328
333
329
334
let rec try_add t key value backoff =
330
335
let r = get t in
@@ -339,7 +344,7 @@ let rec try_add t key value backoff =
339
344
adjust_estimated_size t r mask 1
340
345
else try_add t key value (Backoff. once backoff)
341
346
| B (Cons _ as before ) ->
342
- if mem r.equal key before then false
347
+ if assoc_node r.equal key before != Nil then false
343
348
else
344
349
let after = Cons { key; value; rest = before } in
345
350
if Atomic. compare_and_set b (B before) (B after) then
0 commit comments