summaryrefslogtreecommitdiff
path: root/hashmap.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-03-22 17:14:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-22 20:41:41 (GMT)
commitf75619bd6d21760e1da416d4e27bce6468beffcd (patch)
treee46b96b17fbbcf688dfd4945a87fbeaf29160778 /hashmap.c
parent16f9b4cdd31de2b8185c5c717efa6d28c56b3c74 (diff)
downloadgit-f75619bd6d21760e1da416d4e27bce6468beffcd.zip
git-f75619bd6d21760e1da416d4e27bce6468beffcd.tar.gz
git-f75619bd6d21760e1da416d4e27bce6468beffcd.tar.bz2
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 <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.c')
-rw-r--r--hashmap.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/hashmap.c b/hashmap.c
index b10b642..93793cb 100644
--- a/hashmap.c
+++ b/hashmap.c
@@ -50,6 +50,23 @@ unsigned int memihash(const void *buf, size_t len)
return hash;
}
+/*
+ * Incoporate another chunk of data into a memihash
+ * computation.
+ */
+unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
+{
+ unsigned int hash = hash_seed;
+ unsigned char *ucbuf = (unsigned char *) buf;
+ while (len--) {
+ unsigned int c = *ucbuf++;
+ if (c >= 'a' && c <= 'z')
+ c -= 'a' - 'A';
+ hash = (hash * FNV32_PRIME) ^ c;
+ }
+ return hash;
+}
+
#define HASHMAP_INITIAL_SIZE 64
/* grow / shrink by 2^2 */
#define HASHMAP_RESIZE_BITS 2