Skip to content

Commit

Permalink
add CCHash.map
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Jul 9, 2021
1 parent 4db9d4e commit f550529
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/CCHash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/core/CCHash.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)

Expand Down

0 comments on commit f550529

Please sign in to comment.