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

Re: Fix object re-hashing

From
Linus Torvalds <torvalds@osdl.org>
Date
Feb 12, 2006, 19:39 UTC
Message-ID
<Pine.LNX.4.64.0602121137330.3691@g5.osdl.org>
In-Reply-To
<7vlkwg9ye0.fsf@assigned-by-dhcp.cox.net>
On Sun, 12 Feb 2006, Junio C Hamano wrote:
Show 11 quoted lines
> 
> > Btw, as it currently stands, I worry a tiny tiny bit about the
> >
> > 	obj_allocs = (obj_allocs < 32 ? 32 : 2 * obj_allocs)
> >
> > thing, because I think that second "32" needs to be a "64" to be really 
> > safe (ie guarantee that the new obj_allocs value is always at least twice 
> > the old one).
> 
> obj_allocs starts out as 0 so the first value it gets is 32 when
> you need to insert the first element.

Yes. The point being that the code is "conceptually wrong", not that it doesn't work in practice. If we somehow could get into the situation that we had a hash size of 31, resizing it to 32 would be incorrect.

Of course, if we just make it a rule that the hash size must always be a power-of-two (add a comment, and enforce the rule by changing the modulus into a bitwise "and"), then that issue too goes away.

			Linus
Previous: Junio C HamanoNext: Johannes Schindelin
Message 7 of 13 in “Fix object re-hashing”
  1. Linus TorvaldsFeb 12, 2006
  2. Linus TorvaldsFeb 12, 2006
  3. Junio C HamanoFeb 12, 2006
  4. Linus TorvaldsFeb 12, 2006
  5. Linus TorvaldsFeb 12, 2006
  6. Junio C HamanoFeb 12, 2006
  7. Linus TorvaldsFeb 12, 2006
  8. Johannes SchindelinFeb 12, 2006
  9. Linus TorvaldsFeb 13, 2006
  10. Johannes SchindelinFeb 13, 2006
  11. Junio C HamanoFeb 12, 2006
  12. Linus TorvaldsFeb 12, 2006
  13. Linus TorvaldsFeb 12, 2006

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.