]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[cover] Remove unnecessary mask and dedup hash functions 2217/head
authorNick Terrell <terrelln@fb.com>
Mon, 22 Jun 2020 19:52:13 +0000 (12:52 -0700)
committerNick Terrell <terrelln@fb.com>
Mon, 22 Jun 2020 19:52:13 +0000 (12:52 -0700)
* Remove the unnecessary mask, since `ZSTD_hash*()` already ensures
  the output is mod 2^h.
* Dedup the hash functions and use `ZSTD_hash*()` directly.

lib/dictBuilder/fastcover.c

index 520ca19295dee15b3f95985cb4be1eacb9762124..4a4b8f8be62e86f092189ee5fc65bd0ccfab627f 100644 (file)
@@ -21,6 +21,7 @@
 #include "../common/threading.h"
 #include "cover.h"
 #include "../common/zstd_internal.h" /* includes zstd.h */
+#include "../compress/zstd_compress_internal.h" /* ZSTD_hash*() */
 #ifndef ZDICT_STATIC_LINKING_ONLY
 #define ZDICT_STATIC_LINKING_ONLY
 #endif
@@ -75,25 +76,16 @@ static clock_t g_time = 0;
 
 
 /*-*************************************
-* Hash Functions (matching zstd_compress_internal.h)
+* Hash Functions
 ***************************************/
-static const U64 FASTCOVER_prime6bytes = 227718039650203ULL;
-static size_t FASTCOVER_hash6(U64 u, U32 h) { return (size_t)(((u  << (64-48)) * FASTCOVER_prime6bytes) >> (64-h)) ; }
-static size_t FASTCOVER_hash6Ptr(const void* p, U32 h) { return FASTCOVER_hash6(MEM_readLE64(p), h); }
-
-static const U64 FASTCOVER_prime8bytes = 0xCF1BBCDCB7A56463ULL;
-static size_t FASTCOVER_hash8(U64 u, U32 h) { return (size_t)(((u) * FASTCOVER_prime8bytes) >> (64-h)) ; }
-static size_t FASTCOVER_hash8Ptr(const void* p, U32 h) { return FASTCOVER_hash8(MEM_readLE64(p), h); }
-
-
 /**
- * Hash the d-byte value pointed to by p and mod 2^f
+ * Hash the d-byte value pointed to by p and mod 2^f into the frequency vector
  */
-static size_t FASTCOVER_hashPtrToIndex(const void* p, U32 h, unsigned d) {
+static size_t FASTCOVER_hashPtrToIndex(const void* p, U32 f, unsigned d) {
   if (d == 6) {
-    return FASTCOVER_hash6Ptr(p, h) & ((1 << h) - 1);
+    return ZSTD_hash6Ptr(p, f);
   }
-  return FASTCOVER_hash8Ptr(p, h) & ((1 << h) - 1);
+  return ZSTD_hash8Ptr(p, f);
 }