Skip to content

Commit 35e4137

Browse files
jeffhostetlerdscho
authored andcommitted
hashmap: allow memihash computation to be continued
Add variant of memihash() to allow the hash computation to be continued. There are times when we compute the hash on a full path and then the hash on just the path to the parent directory. This can be expensive on large repositories. With this, we can hash the parent directory first. And then continue the computation to include the "/filename". Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 586f856 commit 35e4137

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

hashmap.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ unsigned int memihash(const void *buf, size_t len)
5050
return hash;
5151
}
5252

53+
/*
54+
* Incoporate another chunk of data into a memihash
55+
* computation.
56+
*/
57+
unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
58+
{
59+
unsigned int hash = hash_seed;
60+
unsigned char *ucbuf = (unsigned char *) buf;
61+
while (len--) {
62+
unsigned int c = *ucbuf++;
63+
if (c >= 'a' && c <= 'z')
64+
c -= 'a' - 'A';
65+
hash = (hash * FNV32_PRIME) ^ c;
66+
}
67+
return hash;
68+
}
69+
5370
#define HASHMAP_INITIAL_SIZE 64
5471
/* grow / shrink by 2^2 */
5572
#define HASHMAP_RESIZE_BITS 2

hashmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern unsigned int strhash(const char *buf);
1212
extern unsigned int strihash(const char *buf);
1313
extern unsigned int memhash(const void *buf, size_t len);
1414
extern unsigned int memihash(const void *buf, size_t len);
15+
extern unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
1516

1617
static inline unsigned int sha1hash(const unsigned char *sha1)
1718
{

0 commit comments

Comments
 (0)