Skip to content

Commit 4ca7017

Browse files
brandb97gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16bd9f2 commit 4ca7017

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

bloom.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g,
107107
* Not considered to be cryptographically secure.
108108
* Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm
109109
*/
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)
111111
{
112112
const uint32_t c1 = 0xcc9e2d51;
113113
const uint32_t c2 = 0x1b873593;
@@ -540,3 +540,14 @@ int bloom_filter_contains(const struct bloom_filter *filter,
540540

541541
return 1;
542542
}
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+
}

bloom.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ int load_bloom_filter_from_graph(struct commit_graph *g,
7878
struct bloom_filter *filter,
7979
uint32_t graph_pos);
8080

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-
9081
void fill_bloom_key(const char *data,
9182
size_t len,
9283
struct bloom_key *key,
@@ -137,4 +128,7 @@ int bloom_filter_contains(const struct bloom_filter *filter,
137128
const struct bloom_key *key,
138129
const struct bloom_filter_settings *settings);
139130

131+
uint32_t test_bloom_murmur3_seeded(uint32_t seed, const char *data, size_t len,
132+
int version);
133+
140134
#endif

t/helper/test-bloom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ int cmd__bloom(int argc, const char **argv)
6161
uint32_t hashed;
6262
if (argc < 3)
6363
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);
6565
printf("Murmur3 Hash with seed=0:0x%08x\n", hashed);
6666
}
6767

6868
if (!strcmp(argv[1], "get_murmur3_seven_highbit")) {
6969
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);
7171
printf("Murmur3 Hash with seed=0:0x%08x\n", hashed);
7272
}
7373

0 commit comments

Comments
 (0)