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

Re: [PATCH 2/3] oidmap: add size function

From
Patrick Steinhardt <ps@pks.im>
Date
May 13, 2025, 09:48 UTC
Message-ID
<aCMVdEg8d6BHo7AA@pks.im>
In-Reply-To
<20250512185130.GB1276214@coredump.intra.peff.net>
On Mon, May 12, 2025 at 02:51:30PM -0400, Jeff King wrote:
Show 11 quoted lines
> Callers which want to know how many items are in an oidmap have to look
> at the underlying hashmap struct, leaking an implementation detail.
> Let's provide a type-appropriate wrapper and use it.
> 
> Note in the call from lookup_replace_object(), the caller was actually
> looking at the hashmap's tablesize parameter (the allocated size of the
> table) rather than hashmap_get_size(), the number of items in the table.
> This probably should have been checking the number of items all along,
> but the two are functionally equivalent here since we only add to the
> map and never remove anything. Thus if there was any allocation, it was
> because there is at least one item.

I was a bit puzzled by this explanation initially. The two sizes aren't functioally equivalent -- the table size will typically be larger than the number of contained entries. But the thing is that we don't care for the actual size, we only care whether the map is empty or not. And for that those are indeed equivalent in this specific case.

Patrick
Previous: Jeff KingNext: Jeff King
Message 4 of 8 in “minor oidmap cleanups”
  1. 0/3 minor oidmap cleanupsJeff King, May 12, 2025
  2. 1/3 oidmap: rename oidmap_free() to oidmap_clear()Jeff King, May 12, 2025
  3. 2/3 oidmap: add size functionJeff King, May 12, 2025
  4. Patrick SteinhardtMay 13, 2025
  5. Jeff KingMay 14, 2025
  6. 3/3 raw_object_store: drop extra pointer to replace_mapJeff King, May 12, 2025
  7. Patrick SteinhardtMay 13, 2025
  8. Junio C HamanoMay 14, 2025

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.