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

Re: [PATCH] hashmap: hashmap_get_next passes through keydata as well

From
Jeff King <peff@peff.net>
Date
May 13, 2017, 08:50 UTC
Message-ID
<20170513085050.plmau5ffvzn6ibfp@sigill.intra.peff.net>
In-Reply-To
<20170512200244.25245-1-sbeller@google.com>
On Fri, May 12, 2017 at 01:02:44PM -0700, Stefan Beller wrote:
> The 'keydata' may be of value in the underlying compare function to decide
> if the given two entries are the same.

I had to scratch my head over this for a minute, because there isn't really any motivating example of what you're trying to do.

I think I figured it out, but I have a feeling it is violating the intent of the "keydata" parameter. That parameter is typically used not as a pointer to arbitrary auxiliary data, but as a trick for finding a hash entry without having to allocate a struct for it.

So generally, I'd think two entries in the table should be able to be compared on their own merits, even if no keydata is available. Without that property, any internal operations in the hashmap can't actually do an entry comparison (e.g., a table resize that needs to rehash the entries).

It works out in the current code because the chaining is purely linear, and doesn't care about order. So we can rehash and just stick the elements into a new list. But if it were switched out for a different data structure (e.g., a tree), then the hashmap code would need to be able to compare elements.

I don't think we have any particular plans for such a change, but I wonder if we should avoid encouraging callers to rely on the current implementation.

-Peff
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 4 in “hashmap: hashmap_get_next passes through keydata as well”
  1. hashmap: hashmap_get_next passes through keydata as wellStefan Beller, May 12, 2017
  2. Jeff KingMay 13, 2017
  3. Stefan BellerMay 13, 2017
  4. Jeff KingMay 16, 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.