diff --git a/core/CCHash.ml b/core/CCHash.ml index 5c6b3885..9432b588 100644 --- a/core/CCHash.ml +++ b/core/CCHash.ml @@ -69,9 +69,15 @@ let rec list_ f l s = match l with let array_ f a s = Array.fold_right f a s +let opt f o h = match o with + | None -> h + | Some x -> f x h let pair h1 h2 (x,y) s = h2 y (h1 x s) let triple h1 h2 h3 (x,y,z) s = h3 z (h2 y (h1 x s)) +let if_ b then_ else_ h = + if b then then_ h else else_ h + type 'a sequence = ('a -> unit) -> unit type 'a gen = unit -> 'a option type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist] diff --git a/core/CCHash.mli b/core/CCHash.mli index 33c56263..279c21f2 100644 --- a/core/CCHash.mli +++ b/core/CCHash.mli @@ -61,9 +61,13 @@ val list_ : 'a hash_fun -> 'a list hash_fun val array_ : 'a hash_fun -> 'a array hash_fun +val opt : 'a hash_fun -> 'a option hash_fun val pair : 'a hash_fun -> 'b hash_fun -> ('a * 'b) hash_fun val triple : 'a hash_fun -> 'b hash_fun -> 'c hash_fun -> ('a * 'b * 'c) hash_fun +val if_ : bool -> 'a hash_fun -> 'a hash_fun -> 'a hash_fun +(** Decide which hash function to use depending on the boolean *) + type 'a sequence = ('a -> unit) -> unit type 'a gen = unit -> 'a option type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]