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

Re: [PATCH/RFC 1/5] add a hashtable implementation that supports O(1) removal

From
Karsten Blees <karsten.blees@gmail.com>
Date
Sep 23, 2013, 09:21 UTC
Message-ID
<52400835.8090902@gmail.com>
In-Reply-To
<xmqqmwnir86z.fsf@gitster.dls.corp.google.com>
Am 12.09.2013 06:10, schrieb Junio C Hamano:
Show 11 quoted lines
> Karsten Blees <karsten.blees@gmail.com> writes:
> 
>> +/*
>> + * Hashmap entry data structure, intended to be used as first member of user
>> + * data structures. Consists of a pointer and an int. Ideally it should be
> 
> It is technically correct to say this is "intended to be" used, but
> to those who are using this API, it would be more helpful to say "a
> user data structure that uses this API *must* have this as its first
> member field".
> 
Right. I considered making the position in the user struct configurable via some offsetof() magic, but this would have just complicated things unnecessarily.
Show 35 quoted lines
>> + * followed by an int-sized member to prevent unused memory on 64-bit systems
>> + * due to alignment.
>> + */
>> +typedef struct hashmap_entry {
>> +	struct hashmap_entry *next;
>> +	unsigned int hash;
>> +} hashmap_entry;
>> + ...
>> +typedef struct hashmap {
>> +	hashmap_entry **table;
>> +	hashmap_cmp_fn cmpfn;
>> +	unsigned int size, tablesize;
>> +} hashmap;
> 
> I forgot to mention in my previous message, but we find that the
> code tends to be easier to read if we avoid using typedef'ed struct
> like these.  E.g. in 2/5 we see something like this:
> 
>      static int abbrev = -1; /* unspecified */
>      static int max_candidates = 10;
>     -static struct hash_table names;
>     +static hashmap names;
>      static int have_util;
>      static const char *pattern;
>      static int always;
>     @@ -38,7 +38,7 @@ static const char *diff_index_args[] = {
> 
> 
>      struct commit_name {
>     -	struct commit_name *next;
>     +	hashmap_entry entry;
>             unsigned char peeled[20];
> 
> The version before the patch is preferrable.
> 
OK
Previous: Junio C HamanoNext: Karsten Blees
Message 6 of 24 in “New hash table implementation”
  1. 0/5 New hash table implementationKarsten Blees, Sep 10, 2013
  2. 1/5 add a hashtable implementation that supports O(1) removalKarsten Blees, Sep 10, 2013
  3. Junio C HamanoSep 11, 2013
  4. Karsten BleesSep 23, 2013
  5. Junio C HamanoSep 12, 2013
  6. Karsten BleesSep 23, 2013
  7. 2/5 buitin/describe.c: use new hash map implementationKarsten Blees, Sep 10, 2013
  8. 3/5 diffcore-rename.c: move code around to prepare for the next patchKarsten Blees, Sep 10, 2013
  9. 4/5 diffcore-rename.c: simplify finding exact renamesKarsten Blees, Sep 10, 2013
  10. 5/5 diffcore-rename.c: use new hash map implementationKarsten Blees, Sep 10, 2013
  11. 0/5 New hash table implementationKarsten Blees, Sep 24, 2013
  12. 1/5 add a hashtable implementation that supports O(1) removalKarsten Blees, Sep 24, 2013
  13. 2/5 buitin/describe.c: use new hash map implementationKarsten Blees, Sep 24, 2013
  14. 3/5 diffcore-rename.c: move code around to prepare for the next patchKarsten Blees, Sep 24, 2013
  15. 4/5 diffcore-rename.c: simplify finding exact renamesKarsten Blees, Sep 24, 2013
  16. 5/5 diffcore-rename.c: use new hash map implementationKarsten Blees, Sep 24, 2013
  17. Fredrik GustafssonSep 24, 2013
  18. Tay Ray ChuanSep 24, 2013
  19. Karsten BleesSep 26, 2013
  20. Fredrik GustafssonSep 26, 2013
  21. Duy NguyenSep 26, 2013
  22. Fredrik GustafssonSep 26, 2013
  23. Duy NguyenSep 26, 2013
  24. Karsten BleesSep 26, 2013

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.