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

Re: Libgit2 on the Summer of Code

From
ILIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Date
May 27, 2010, 18:35 UTC
Message-ID
<20100527183534.GA10414@LK-Perkele-V2.elisa-laajakaista.fi>
In-Reply-To
<20100527180554.GM16470@spearce.org>
On Thu, May 27, 2010 at 11:05:54AM -0700, Shawn O. Pearce wrote:
Show 12 quoted lines
> Ilari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:
> > * Where algorithm in git_revpool_table__hash() is from? Since it appears to
> > hash binary object IDs, wouldn't just simple sum/xor over words be sufficient
> > (all SHA-1 output bits are very nearly independent). Or do you need to be
> > compatible with some other implementation (doesn't appear so, because hash
> > is computed differently depending on endianess)?
> 
> If you need a hash value for a SHA-1, why not just cast the unsigned
> char* to unsigned int* and load the first int as the hash code?
> The output of SHA-1 is pretty evenly distributed, using the first
> few bytes as an int should yield a sufficient distribution throughout
> the hashtable.

Yeah, With pseudorandom function[*], all ways of reducing the output to n bits are at most as good as just taking first n bits. But if reducing output to [0, m), the best way (distribution-wise, not speed-wise) is to take remainder of the whole value divided by m...

[*] SHA-1 is not pseudorandom function, but for virtually all practical purposes it is.

-Ilari
Previous: Junio C HamanoNext: Vicent Marti
Message 6 of 7 in “Libgit2 on the Summer of Code”
  1. Vicent MartiMay 27, 2010
  2. Ilari LiusvaaraMay 27, 2010
  3. Shawn O. PearceMay 27, 2010
  4. Alex RiesenMay 27, 2010
  5. Junio C HamanoJun 2, 2010
  6. Ilari LiusvaaraMay 27, 2010
  7. Vicent MartiMay 28, 2010

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.