Re: What's cooking in git.git (Dec 2013, #02; Fri, 6)

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: What's cooking in git.git (Dec 2013, #02; Fri, 6)

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:59:25

Karsten Blees [off-list ref] writes:
quoted
* kb/fast-hashmap (2013-11-18) 14 commits
  (merged to 'next' on 2013-12-06 at f90be3d) 
Damn, a day too late :-) I found these two glitches today...is a
fixup patch OK or should I do a reroll (or separate patch on top)?
A separate patch on top would be the most appropriate.  People have
been looking at the change since mid November, and nobody noticed
the problem; having a separate fix on top is a good way to document
what the specific gotcha that can be easily missed is.

I think the patch you attached describes the issue well, possibly
with a retitle (perhaps "hashmap.h: make sure map entries are
tightly packed", or something.)

Thanks.
quoted hunk
--- 8< ---
Subject: [PATCH] fixup! add a hashtable implementation that supports O(1) removal

Use 'unsigned int' for hash-codes everywhere.

Extending 'struct hashmap_entry' with an int-sized member shouldn't waste
memory on 64-bit systems. This is already documented in api-hashmap.txt,
but needs '__attribute__((__packed__))' to work. Reduces e.g.

 struct name_entry {
     struct hashmap_entry ent;
     int namelen;
     char *name;
 };

from 32 to 24 bytes.

Signed-off-by: Karsten Blees <redacted>
---
 hashmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hashmap.h b/hashmap.h
index f5b3b61..b64567b 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -15,7 +15,7 @@ extern unsigned int memihash(const void *buf, size_t len);
 
 /* data structures */
 
-struct hashmap_entry {
+struct __attribute__((__packed__)) hashmap_entry {
 	struct hashmap_entry *next;
 	unsigned int hash;
 };
@@ -43,7 +43,7 @@ extern void hashmap_free(struct hashmap *map, int free_entries);
 
 /* hashmap_entry functions */
 
-static inline void hashmap_entry_init(void *entry, int hash)
+static inline void hashmap_entry_init(void *entry, unsigned int hash)
 {
 	struct hashmap_entry *e = entry;
 	e->hash = hash;

[PATCH] hashmap.h: Use 'unsigned int' for hash-codes everywhere

From: Karsten Blees <hidden>
Date: 2016-06-15 22:59:28

Signed-off-by: Karsten Blees <redacted>
---

Am 09.12.2013 18:48, schrieb Junio C Hamano:
Karsten Blees [off-list ref] writes:
quoted
quoted
* kb/fast-hashmap (2013-11-18) 14 commits
  (merged to 'next' on 2013-12-06 at f90be3d) 
Damn, a day too late :-) I found these two glitches today...is a
fixup patch OK or should I do a reroll (or separate patch on top)?
A separate patch on top would be the most appropriate.
OK, this one's a no-brainer I think. See $gmane/239430 for the latest proposal on the struct packing front.


 Documentation/technical/api-hashmap.txt | 2 +-
 hashmap.h                               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/technical/api-hashmap.txt b/Documentation/technical/api-hashmap.txt
index b2280f1..42ca234 100644
--- a/Documentation/technical/api-hashmap.txt
+++ b/Documentation/technical/api-hashmap.txt
@@ -80,7 +80,7 @@ prevent expensive resizing. If 0, the table is dynamically resized.
 If `free_entries` is true, each hashmap_entry in the map is freed as well
 (using stdlib's free()).
 
-`void hashmap_entry_init(void *entry, int hash)`::
+`void hashmap_entry_init(void *entry, unsigned int hash)`::
 
 	Initializes a hashmap_entry structure.
 +
diff --git a/hashmap.h b/hashmap.h
index f5b3b61..a816ad4 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -43,7 +43,7 @@ extern void hashmap_free(struct hashmap *map, int free_entries);
 
 /* hashmap_entry functions */
 
-static inline void hashmap_entry_init(void *entry, int hash)
+static inline void hashmap_entry_init(void *entry, unsigned int hash)
 {
 	struct hashmap_entry *e = entry;
 	e->hash = hash;
-- 
1.8.5.1.276.g562b27a
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help