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

Re: [PATCH v2] oidmap: map with OID as key

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Oct 4, 2017, 00:29 UTC
Message-ID
<CAGf8dgKtwdT912CaARdjYnSAd2m7mmdOzM=OGCUupw80snrd_w@mail.gmail.com>
In-Reply-To
<20171003063119.iht5kl7zsiuxpaqz@sigill.intra.peff.net>
On Mon, Oct 2, 2017 at 11:31 PM, Jeff King <peff@peff.net> wrote:
Show 13 quoted lines
> Right, I kind of wonder if this has fallen into an uncanny value where
> we have this almost-hashmap infrastructure, but the end result is not
> significantly easier to use than a plain-old hashmap.
>
> I.e., it looks like you still have to declare something like:
>
>   struct my_data {
>         struct oidmap_entry oid;
>         int value; /* mapping to an int */
>   };
>
> and handle the allocation of the entry yourself. If we instead just
> adding an oidhash() and oidcmpfn(), then callers could those directly.
I thought of something like that, but it seems that you have to
remember quite a few things:
- your entry must have "struct oidmap_entry" at the start, not "struct
hashmap_entry"
- initialize your hashmap with oidcmpfn()
- when getting, hashmap_get_from_hash(map, oidhash(&oid), &oid) (and
oid might be longer e.g. ref->old_oid)
> The invocations are a _little_ longer with a raw hashmap, but not much
> (as you can see from the actual oidmap implementation, and the changes
> to oidset).

About the invocation of hashmap_get_from_hash(), I felt that it would get annoying quickly enough that I would want an oidmap_get(const struct hashmap *, const struct object_id *) but it might be strange that the "get" method is named differently from the rest. If we tolerate oidmap_get(), and tolerate the fact that the user must both declare "struct oidmap_entry" instead of "struct hashmap_entry" and initialize the hashmap with oidcmpfn() (so that the invocation to hashmap_get_from_hash() within oidmap_get() sends the correct keydata), we can avoid the thin wrapper issue where callers can no longer use other methods of hashmap. At this point I decided that I prefer the thin wrapper, but the "light touch" (struct oidmap_entry, oidcmpfn(), oidmap_get() only) still better than the status quo.

Previous: Jeff KingNext: Jeff King
Message 14 of 16 in “oidmap: map with OID as key”
  1. oidmap: map with OID as keyJonathan Tan, Sep 27, 2017
  2. Brandon WilliamsSep 28, 2017
  3. Jonathan TanSep 28, 2017
  4. Jeff KingSep 28, 2017
  5. Jonathan TanSep 29, 2017
  6. Jeff KingSep 29, 2017
  7. Johannes SchindelinSep 29, 2017
  8. Jeff KingSep 29, 2017
  9. Junio C HamanoSep 28, 2017
  10. Jonathan TanSep 28, 2017
  11. oidmap: map with OID as keyJonathan Tan, Sep 29, 2017
  12. Brandon WilliamsOct 2, 2017
  13. Jeff KingOct 3, 2017
  14. Jonathan TanOct 4, 2017
  15. Jeff KingOct 4, 2017
  16. Junio C HamanoOct 4, 2017

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.