git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/6] hashmap: allow memihash computation to be continued

From
Ggit@jeffhostetler.com <git@jeffhostetler.com>
Date
Mar 22, 2017, 17:14 UTC
Message-ID
<1490202865-31325-3-git-send-email-git@jeffhostetler.com>
In-Reply-To
<1490202865-31325-1-git-send-email-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

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>
---
 hashmap.c | 17 +++++++++++++++++
 hashmap.h |  1 +
 2 files changed, 18 insertions(+)
diff --git a/hashmap.c b/hashmap.c
index b10b642..505e63f 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
diff --git a/hashmap.h b/hashmap.h
index ab7958a..45eda69 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -12,6 +12,7 @@ extern unsigned int strhash(const char *buf);
 extern unsigned int strihash(const char *buf);
 extern unsigned int memhash(const void *buf, size_t len);
 extern unsigned int memihash(const void *buf, size_t len);
+extern unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
 
 static inline unsigned int sha1hash(const unsigned char *sha1)
 {
-- 
2.7.4
Previous: git@jeffhostetler.comNext: git@jeffhostetler.com
Message 5 of 14 in “thread lazy_init_name_hash”
  1. 0/6 thread lazy_init_name_hashgit@jeffhostetler.com, Mar 22, 2017
  2. 3/6 hashmap: Add disallow_rehash settinggit@jeffhostetler.com, Mar 22, 2017
  3. 4/6 name-hash: perf improvement for lazy_init_name_hashgit@jeffhostetler.com, Mar 22, 2017
  4. 1/6 name-hash: specify initial size for istate.dir_hash tablegit@jeffhostetler.com, Mar 22, 2017
  5. 2/6 hashmap: allow memihash computation to be continuedgit@jeffhostetler.com, Mar 22, 2017
  6. 6/6 name-hash: add perf test for lazy_init_name_hashgit@jeffhostetler.com, Mar 22, 2017
  7. 5/6 name-hash: add test-lazy-init-name-hashgit@jeffhostetler.com, Mar 22, 2017
  8. Stefan BellerMar 22, 2017
  9. Jeff HostetlerMar 22, 2017
  10. Junio C HamanoMar 22, 2017
  11. Junio C HamanoMar 22, 2017
  12. Jeff HostetlerMar 22, 2017
  13. Junio C HamanoMar 22, 2017
  14. Junio C HamanoMar 22, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.