mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 12:15:32 -05:00
fix: CCIntMap not a search tree for negative keys, apparently
This commit is contained in:
parent
a5a45efa8c
commit
1cdd678eb3
1 changed files with 10 additions and 4 deletions
|
|
@ -82,10 +82,18 @@ let rec find_exn k t = match t with
|
||||||
| E -> raise Not_found
|
| E -> raise Not_found
|
||||||
| L (k', v) when k = k' -> v
|
| L (k', v) when k = k' -> v
|
||||||
| L _ -> raise Not_found
|
| L _ -> raise Not_found
|
||||||
| N (prefix, _, l, r) ->
|
| N (prefix, m, l, r) ->
|
||||||
|
if is_prefix_ ~prefix k ~bit:m
|
||||||
|
then if bit_is_0_ k ~bit:m
|
||||||
|
then find_exn k l
|
||||||
|
else find_exn k r
|
||||||
|
else raise Not_found
|
||||||
|
|
||||||
|
(* FIXME: valid if k < 0?
|
||||||
if k <= prefix (* search tree *)
|
if k <= prefix (* search tree *)
|
||||||
then find_exn k l
|
then find_exn k l
|
||||||
else find_exn k r
|
else find_exn k r
|
||||||
|
*)
|
||||||
|
|
||||||
let find k t =
|
let find k t =
|
||||||
try Some (find_exn k t)
|
try Some (find_exn k t)
|
||||||
|
|
@ -129,11 +137,9 @@ let add k v t = insert_ (fun ~old:_ v -> v) k v t
|
||||||
(*$Q
|
(*$Q
|
||||||
Q.(list (pair int int)) (fun l -> \
|
Q.(list (pair int int)) (fun l -> \
|
||||||
let l = CCList.Set.uniq l in let m = of_list l in \
|
let l = CCList.Set.uniq l in let m = of_list l in \
|
||||||
List.for_all (fun (k,v) -> k < 0 || find_exn k m = v) l)
|
List.for_all (fun (k,v) -> find_exn k m = v) l)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(* TODO: fix the previous test *)
|
|
||||||
|
|
||||||
let rec remove k t = match t with
|
let rec remove k t = match t with
|
||||||
| E -> E
|
| E -> E
|
||||||
| L (k', _) -> if k=k' then E else t
|
| L (k', _) -> if k=k' then E else t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue