Git fork

bloom: add test helper to return murmur3 hash

In bloom.h, murmur3_seeded_v2() is exported for the use of test murmur3
hash. To clarify that murmur3_seeded_v2() is exported solely for testing
purposes, a new helper function test_murmur3_seeded() was added instead
of exporting murmur3_seeded_v2() directly.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Lidong Yan and committed by
Junio C Hamano
4ca70179 16bd9f20

+17 -12
+12 -1
bloom.c
··· 107 107 * Not considered to be cryptographically secure. 108 108 * Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm 109 109 */ 110 - uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len) 110 + static uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len) 111 111 { 112 112 const uint32_t c1 = 0xcc9e2d51; 113 113 const uint32_t c2 = 0x1b873593; ··· 540 540 541 541 return 1; 542 542 } 543 + 544 + uint32_t test_bloom_murmur3_seeded(uint32_t seed, const char *data, size_t len, 545 + int version) 546 + { 547 + assert(version == 1 || version == 2); 548 + 549 + if (version == 2) 550 + return murmur3_seeded_v2(seed, data, len); 551 + else 552 + return murmur3_seeded_v1(seed, data, len); 553 + }
+3 -9
bloom.h
··· 78 78 struct bloom_filter *filter, 79 79 uint32_t graph_pos); 80 80 81 - /* 82 - * Calculate the murmur3 32-bit hash value for the given data 83 - * using the given seed. 84 - * Produces a uniformly distributed hash value. 85 - * Not considered to be cryptographically secure. 86 - * Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm 87 - */ 88 - uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len); 89 - 90 81 void fill_bloom_key(const char *data, 91 82 size_t len, 92 83 struct bloom_key *key, ··· 136 127 int bloom_filter_contains(const struct bloom_filter *filter, 137 128 const struct bloom_key *key, 138 129 const struct bloom_filter_settings *settings); 130 + 131 + uint32_t test_bloom_murmur3_seeded(uint32_t seed, const char *data, size_t len, 132 + int version); 139 133 140 134 #endif
+2 -2
t/helper/test-bloom.c
··· 61 61 uint32_t hashed; 62 62 if (argc < 3) 63 63 usage(bloom_usage); 64 - hashed = murmur3_seeded_v2(0, argv[2], strlen(argv[2])); 64 + hashed = test_bloom_murmur3_seeded(0, argv[2], strlen(argv[2]), 2); 65 65 printf("Murmur3 Hash with seed=0:0x%08x\n", hashed); 66 66 } 67 67 68 68 if (!strcmp(argv[1], "get_murmur3_seven_highbit")) { 69 69 uint32_t hashed; 70 - hashed = murmur3_seeded_v2(0, "\x99\xaa\xbb\xcc\xdd\xee\xff", 7); 70 + hashed = test_bloom_murmur3_seeded(0, "\x99\xaa\xbb\xcc\xdd\xee\xff", 7, 2); 71 71 printf("Murmur3 Hash with seed=0:0x%08x\n", hashed); 72 72 } 73 73