add CCHash.map

This commit is contained in:
Simon Cruanes 2021-07-09 14:40:15 -04:00
parent 4db9d4eccb
commit f5505297de
2 changed files with 14 additions and 0 deletions

View file

@ -124,6 +124,7 @@ let array f l = Array.fold_left (combine f) 0x42 l
let pair f g (x,y) = combine2 (f x) (g y)
let triple f g h (x,y,z) = combine2 (combine2 (f x) (g y)) (h z)
let quad f g h i (x,y,z,w) = combine2 (combine2 (f x) (g y)) (combine2 (h z) (i w))
let map f h x = h (f x)
let if_ b then_ else_ h =
if b then then_ h else else_ h

View file

@ -50,6 +50,19 @@ val pair : 'a t -> 'b t -> ('a * 'b) t
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val map : ('a -> 'b) -> 'b t -> 'a t
(** [map f h] is the hasher that takes [x],
and uses [h] to hash [f x].
For example:
{[
module Str_set = Set.Make(String)
let hash_str_set : Str_set.t CCHash.t = CCHash.(map Str_set.to_seq @@ seq string)
]}
@since NEXT_RELEASE *)
val if_ : bool -> 'a t -> 'a t -> 'a t
(** Decide which hash function to use depending on the boolean. *)