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

Re: [PATCH] Document khash

From
Jeff King <peff@peff.net>
Date
Nov 28, 2013, 10:35 UTC
Message-ID
<20131128103555.GA14615@sigill.intra.peff.net>
In-Reply-To
<ccce08818b6856f67a5316eba148d5a860d1d8f7.1385391631.git.tr@thomasrast.ch>
On Mon, Nov 25, 2013 at 04:04:48PM +0100, Thomas Rast wrote:
Show 5 quoted lines
> > I think I'll also lend you a hand writing Documentation/technical/api-khash.txt
> > (expect it tomorrow) so that we also have documentation in the git
> > style, where gitters can be expected to find it on their own.
> 
> Here goes.
Thanks. Some comments below.
Show 7 quoted lines
> > Furthermore, would it be a problem to name the second hash sha1_int
> > instead?  I have another use for such a hash, and I can't imagine I'm
> > the only one.  (That's not critical however, I can do the required
> > editing in that other series.)
> 
> Actually, let's not do that.  Since everything is 'static inline'
> anyway, there's no cost to simply instantiating more hashes as needed.

Yeah. If we cared about code duplication, we'd have to split it into declaration and definition macros, and then collect the definitions in one .c file (khash does support this, but we don't use it). I don't think we are using enough repeated ones to make it matter, and most of the functions benefit from inlining anyway.

> +------------
> +#import "khash.h"
> +KHASH_INIT(NAME, key_t, value_t, is_map, key_hash_fn, key_equal_fn)
> +------------
#import?
> +The arguments are as follows:
> [...]
> +`khint_t key_hash_fn(key_t)`::
> +	Hash function.

It is true that this is a khint_t, but I do not think knowing that helps the caller. They need to design a hash function, so knowing the size and type of the hint helps. Maybe:

  Return a hash value for a key. The khint_t is a 32-bit unsigned value.
  Git provides __kh_oid_hash, which converts a sha1 into a hash value.
> +`int key_equal_fn(key_t a, key_t b)`::
> +	Comparison function.  Return 1 if the two keys are the same, 0
> +	otherwise.

Here we provide __kh_oid_cmp, and we should mention it. Based on recent discussions, this should probably be __kh_oid_equal, since it is not a "cmp" function in the ordering sense.

Show 5 quoted lines
> +`khint_t kh_get_NAME(const kh_NAME_t *hash, key_t key)`::
> +	Find the given key in the hash table.  The returned khint_t
> +	should be treated as an opaque iterator token that indexes
> +	into the hash.  Use `kh_value` to get the value from the
> +	token.  If the key does not exist, returns kh_end(hash).

I do not know of the khash author's intention, but in the bitmap code we prefer khiter_t to represent an iterator. It is the same as a khint_t, but I think that is an implementation detail (and the khash functions should probably be returning a khiter_t).

> [...]
The rest of it looks correct to me.
-Peff
Previous: Thomas RastNext: Karsten Blees
Message 14 of 55 in “pack bitmaps”
  1. 0/21 pack bitmapsJeff King, Nov 14, 2013
  2. 01/21 sha1write: make buffer const-correctJeff King, Nov 14, 2013
  3. 02/21 revindex: Export new APIsJeff King, Nov 14, 2013
  4. 03/21 pack-objects: Refactor the packing listJeff King, Nov 14, 2013
  5. 04/21 pack-objects: factor out name_hashJeff King, Nov 14, 2013
  6. 05/21 revision: allow setting custom limiter functionJeff King, Nov 14, 2013
  7. 06/21 sha1_file: export `git_open_noatime`Jeff King, Nov 14, 2013
  8. 07/21 compat: add endianness helpersJeff King, Nov 14, 2013
  9. 08/21 ewah: compressed bitmap implementationJeff King, Nov 14, 2013
  10. 09/21 documentation: add documentation for the bitmap formatJeff King, Nov 14, 2013
  11. 10/21 pack-bitmap: add support for bitmap indexesJeff King, Nov 14, 2013
  12. Thomas RastNov 24, 2013
  13. Document khashThomas Rast, Nov 25, 2013
  14. Jeff KingNov 28, 2013
  15. Karsten BleesNov 27, 2013
  16. Jeff KingNov 28, 2013
  17. Karsten BleesDec 3, 2013
  18. Jeff KingDec 3, 2013
  19. Karsten BleesDec 7, 2013
  20. Thomas RastNov 29, 2013
  21. Jeff KingDec 2, 2013
  22. Junio C HamanoDec 2, 2013
  23. Jeff KingDec 2, 2013
  24. Junio C HamanoDec 2, 2013
  25. 11/21 pack-objects: use bitmaps when packing objectsJeff King, Nov 14, 2013
  26. Thomas RastDec 7, 2013
  27. Jeff KingDec 21, 2013
  28. 12/21 rev-list: add bitmap mode to speed up object listsJeff King, Nov 14, 2013
  29. Thomas RastDec 7, 2013
  30. 13/21 pack-objects: implement bitmap writingJeff King, Nov 14, 2013
  31. Thomas RastDec 7, 2013
  32. Jeff KingDec 21, 2013
  33. 14/21 repack: stop using magic number for ARRAY_SIZE(exts)Jeff King, Nov 14, 2013
  34. Thomas RastDec 7, 2013
  35. 15/21 repack: turn exts array into array-of-structJeff King, Nov 14, 2013
  36. Thomas RastDec 7, 2013
  37. 16/21 repack: handle optional files created by pack-objectsJeff King, Nov 14, 2013
  38. Thomas RastDec 7, 2013
  39. 17/21 repack: consider bitmaps when performing repacksJeff King, Nov 14, 2013
  40. Thomas RastDec 7, 2013
  41. 18/21 count-objects: recognize .bitmap in garbage-checkingJeff King, Nov 14, 2013
  42. Thomas RastDec 7, 2013
  43. 19/21 t: add basic bitmap functionality testsJeff King, Nov 14, 2013
  44. Thomas RastDec 7, 2013
  45. Jeff KingDec 21, 2013
  46. 20/21 t/perf: add tests for pack bitmapsJeff King, Nov 14, 2013
  47. Thomas RastDec 7, 2013
  48. Jeff KingDec 21, 2013
  49. 21/21 pack-bitmap: implement optional name_hash cacheJeff King, Nov 14, 2013
  50. Thomas RastDec 7, 2013
  51. Ramsay JonesNov 14, 2013
  52. Jeff KingNov 14, 2013
  53. Ramsay JonesNov 14, 2013
  54. Ramsay JonesNov 18, 2013
  55. Thomas RastNov 16, 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.