Skip to content

Commit eafead1

Browse files
committed
upstream: cherry-pick e920a5b onto d9dd990
This commit helps to teach `git rerere` to resolve merge conflicts when cherry-picking: e920a5b (fixup! Merge pull request #964 from jeffhostetler/jeffhostetler/memihash_perf, 2017-03-27)
1 parent 1318425 commit eafead1

File tree

2 files changed

+500
-101
lines changed

2 files changed

+500
-101
lines changed

hashmap.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ unsigned int memihash(const void *buf, size_t len)
5353
/*
5454
* Incoporate another chunk of data into a memihash
5555
* computation.
56-
*/
56+
*/
5757
unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
5858
{
5959
unsigned int hash = hash_seed;
@@ -104,11 +104,19 @@ static inline unsigned int bucket(const struct hashmap *map,
104104
return key->hash & (map->tablesize - 1);
105105
}
106106

107+
int hashmap_bucket(const struct hashmap *map, unsigned int hash)
108+
{
109+
return hash & (map->tablesize - 1);
110+
}
111+
107112
static void rehash(struct hashmap *map, unsigned int newsize)
108113
{
109114
unsigned int i, oldsize = map->tablesize;
110115
struct hashmap_entry **oldtable = map->table;
111116

117+
if (map->disallow_rehash)
118+
return;
119+
112120
alloc_table(map, newsize);
113121
for (i = 0; i < oldsize; i++) {
114122
struct hashmap_entry *e = oldtable[i];
@@ -141,7 +149,9 @@ void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function,
141149
size_t initial_size)
142150
{
143151
unsigned int size = HASHMAP_INITIAL_SIZE;
144-
map->size = 0;
152+
153+
memset(map, 0, sizeof(*map));
154+
145155
map->cmpfn = equals_function ? equals_function : always_equal;
146156

147157
/* calculate initial table size and allocate the table */

0 commit comments

Comments
 (0)