mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
some unrolling in CCHashtbl
This commit is contained in:
parent
783331b037
commit
9488ff51c6
2 changed files with 19 additions and 6 deletions
|
|
@ -107,7 +107,8 @@ module Make(X : HASHABLE) = struct
|
||||||
h mod Array.length tbl.arr
|
h mod Array.length tbl.arr
|
||||||
|
|
||||||
let _succ tbl i =
|
let _succ tbl i =
|
||||||
if i = Array.length tbl.arr-1 then 0 else i+1
|
let i' = i+1 in
|
||||||
|
if i' = Array.length tbl.arr then 0 else i'
|
||||||
|
|
||||||
let _pred tbl i =
|
let _pred tbl i =
|
||||||
if i = 0 then Array.length tbl.arr - 1 else i-1
|
if i = 0 then Array.length tbl.arr - 1 else i-1
|
||||||
|
|
@ -198,7 +199,7 @@ module Make(X : HASHABLE) = struct
|
||||||
| Empty -> raise Not_found
|
| Empty -> raise Not_found
|
||||||
| Key (k', v', _) when X.equal k k' -> v'
|
| Key (k', v', _) when X.equal k k' -> v'
|
||||||
| Key (_, _, h_k') ->
|
| Key (_, _, h_k') ->
|
||||||
if (dib > 3 && _dib tbl h_k' i < dib)
|
if _dib tbl h_k' i < dib
|
||||||
then raise Not_found (* [k] would be here otherwise *)
|
then raise Not_found (* [k] would be here otherwise *)
|
||||||
else _get_exn tbl k h_k (_succ tbl i) (dib+1)
|
else _get_exn tbl k h_k (_succ tbl i) (dib+1)
|
||||||
|
|
||||||
|
|
@ -206,9 +207,21 @@ module Make(X : HASHABLE) = struct
|
||||||
let h_k = X.hash k in
|
let h_k = X.hash k in
|
||||||
let i0 = _initial_idx tbl h_k in
|
let i0 = _initial_idx tbl h_k in
|
||||||
match tbl.arr.(i0) with
|
match tbl.arr.(i0) with
|
||||||
| Empty -> raise Not_found
|
| Empty -> raise Not_found
|
||||||
| Key (k', v, _) when X.equal k k' -> v
|
| Key (k', v, _) ->
|
||||||
| Key _ -> _get_exn tbl k h_k (_succ tbl i0) 1
|
if X.equal k k' then v
|
||||||
|
else let i1 = _succ tbl i0 in
|
||||||
|
match tbl.arr.(i1) with
|
||||||
|
| Empty -> raise Not_found
|
||||||
|
| Key (k', v, _) ->
|
||||||
|
if X.equal k k' then v
|
||||||
|
else
|
||||||
|
let i2 = _succ tbl i1 in
|
||||||
|
match tbl.arr.(i2) with
|
||||||
|
| Empty -> raise Not_found
|
||||||
|
| Key (k', v, _) ->
|
||||||
|
if X.equal k k' then v
|
||||||
|
else _get_exn tbl k h_k (_succ tbl i2) 3
|
||||||
|
|
||||||
let get k tbl =
|
let get k tbl =
|
||||||
try Some (get_exn k tbl)
|
try Some (get_exn k tbl)
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ let imap_find m =
|
||||||
let icchashtbl_find m =
|
let icchashtbl_find m =
|
||||||
fun n ->
|
fun n ->
|
||||||
for i = 0 to n-1 do
|
for i = 0 to n-1 do
|
||||||
ignore (ICCHashtbl.find_exn m i);
|
ignore (ICCHashtbl.get_exn i m);
|
||||||
done
|
done
|
||||||
|
|
||||||
let bench_maps3 () =
|
let bench_maps3 () =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue