From 9ac7984f74d6267affe43257237598e00e6503d7 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 15 Dec 2017 13:49:34 +0100 Subject: [PATCH] add `Hash.const0` for trivial hash function that ignores its input --- src/core/CCHash.ml | 1 + src/core/CCHash.mli | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/core/CCHash.ml b/src/core/CCHash.ml index c4741cf4..8b0b9ac7 100644 --- a/src/core/CCHash.ml +++ b/src/core/CCHash.ml @@ -24,6 +24,7 @@ let combine4 a b c d = (** {2 Combinators} *) let const h _ = h +let const0 _ = 0 let int i = i land max_int let bool b = if b then 1 else 2 diff --git a/src/core/CCHash.mli b/src/core/CCHash.mli index 28c5fc54..e370934b 100644 --- a/src/core/CCHash.mli +++ b/src/core/CCHash.mli @@ -14,6 +14,12 @@ type 'a t = 'a -> hash val const : hash -> _ t (** [return h] hashes any value into [h]. Use with caution!. *) +val const0 : _ t +(** Always return 0. Useful for ignoring elements. + Example: [Hash.(pair string const0)] will map pairs [("a", 1)] + and [("a", 2)] to the same hash, but not the same as [("b", 1)] + @since NEXT_RELEASE *) + val int : int t val bool : bool t val char : char t