mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
add mem to CCHashTrie
This commit is contained in:
parent
791eb8efba
commit
47414c7f40
2 changed files with 12 additions and 4 deletions
|
|
@ -38,6 +38,8 @@ module type S = sig
|
||||||
|
|
||||||
val add : key -> 'a -> 'a t -> 'a t
|
val add : key -> 'a -> 'a t -> 'a t
|
||||||
|
|
||||||
|
val mem : key -> _ t -> bool
|
||||||
|
|
||||||
val get : key -> 'a t -> 'a option
|
val get : key -> 'a t -> 'a option
|
||||||
|
|
||||||
val get_exn : key -> 'a t -> 'a
|
val get_exn : key -> 'a t -> 'a
|
||||||
|
|
@ -115,14 +117,14 @@ end
|
||||||
(*
|
(*
|
||||||
from https://en.wikipedia.org/wiki/Hamming_weight
|
from https://en.wikipedia.org/wiki/Hamming_weight
|
||||||
|
|
||||||
//This uses fewer arithmetic operations than any other known
|
//This uses fewer arithmetic operations than any other known
|
||||||
//implementation on machines with fast multiplication.
|
//implementation on machines with fast multiplication.
|
||||||
//It uses 12 arithmetic operations, one of which is a multiply.
|
//It uses 12 arithmetic operations, one of which is a multiply.
|
||||||
int popcount_3(uint64_t x) {
|
int popcount_3(uint64_t x) {
|
||||||
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
||||||
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
||||||
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
||||||
return (x * h01)>>56; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
return (x * h01)>>56; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||||
}
|
}
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
@ -317,6 +319,10 @@ module Make(Key : KEY)
|
||||||
try Some (get_exn_ k ~h:(hash_ k) m)
|
try Some (get_exn_ k ~h:(hash_ k) m)
|
||||||
with Not_found -> None
|
with Not_found -> None
|
||||||
|
|
||||||
|
let mem k m =
|
||||||
|
try ignore (get_exn_ k ~h:(hash_ k) m); true
|
||||||
|
with Not_found -> false
|
||||||
|
|
||||||
(* TODO: use Hash.combine if array only has one non-empty LEAF element? *)
|
(* TODO: use Hash.combine if array only has one non-empty LEAF element? *)
|
||||||
|
|
||||||
(* [left] list nodes already visited *)
|
(* [left] list nodes already visited *)
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ module type S = sig
|
||||||
|
|
||||||
val add : key -> 'a -> 'a t -> 'a t
|
val add : key -> 'a -> 'a t -> 'a t
|
||||||
|
|
||||||
|
val mem : key -> _ t -> bool
|
||||||
|
|
||||||
val get : key -> 'a t -> 'a option
|
val get : key -> 'a t -> 'a option
|
||||||
|
|
||||||
val get_exn : key -> 'a t -> 'a
|
val get_exn : key -> 'a t -> 'a
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue