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

Re: [PATCH 4/8] add functions for memory-efficient bitmaps

From
Jeff King <peff@peff.net>
Date
Jul 1, 2014, 17:18 UTC
Message-ID
<20140701171759.GB7282@sigill.intra.peff.net>
In-Reply-To
<xmqqegy5xbiu.fsf@gitster.dls.corp.google.com>
On Tue, Jul 01, 2014 at 09:57:13AM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Another thing I noticed was that the definition of and the
> commentary on bitset_equal() and bitset_empty() sounded somewhat
> "undecided".  These functions take "max" that is deliberately named
> differently from "num_bits" (the width of the bitsets involved),
> inviting to use them for testing only earlier bits in the bitset as
> long as the caller understands the caveat, but the caveat requires
> that the partial bitset to test must be byte-aligned, which makes it
> not very useful in practice, which means we probably do not want
> them to be used for any "max" other than "num_bits".

Yeah, I added that comment because I found "max" to be confusing, but couldn't think of a better name. I'm not sure why "num_bits" did not occur to me, as that makes it completely obvious.

>  * take "num_bits", not "max", to clarify that callers must use them
>    only on the full bitset.

This seems like the right solution to me. Handling partially aligned bytes adds to the complexity and may hurt performance (in fact, I think bitset_equal could actually just call memcmp, which I should fix). That's fine if callers care about that feature, but I actually don't anticipate any that do.

By the way, I chose "unsigned char" as the storage format somewhat arbitrarily. Performance might be better with "unsigned int" or even "unsigned long". It means potentially wasting more space, but not more than one word (minus a byte) per commit (so about 3MB on linux.git). I'll try to do some timings to see if it's worth doing.

Show 5 quoted lines
> In either case, there needs another item in the "caller's responsibility"
> list at the beginning of bitset.h:
> 
>     4. Ensure that padding bits at the end of the bitset array are
>        initialized to 0.

Agreed. That is definitely a requirement I had in mind, but I didn't think to write it down.

I'll fix both points in the re-roll.
-Peff
Previous: Junio C HamanoNext: Jeff King
Message 13 of 26 in “use merge-base for tag --contains”
  1. 0/8 use merge-base for tag --containsJeff King, Jun 25, 2014
  2. 1/8 tag: allow --sort with -nJeff King, Jun 25, 2014
  3. 2/8 tag: factor out decision to stream tagsJeff King, Jun 25, 2014
  4. 3/8 paint_down_to_common: use prio_queueJeff King, Jun 25, 2014
  5. Junio C HamanoJul 1, 2014
  6. Jeff KingJul 1, 2014
  7. 4/8 add functions for memory-efficient bitmapsJeff King, Jun 25, 2014
  8. Torsten BögershausenJun 26, 2014
  9. Jeff KingJun 26, 2014
  10. Eric SunshineJun 29, 2014
  11. Jeff KingJun 30, 2014
  12. Junio C HamanoJul 1, 2014
  13. Jeff KingJul 1, 2014
  14. 5/8 string-list: add pos to iterator callbackJeff King, Jun 25, 2014
  15. Junio C HamanoJul 1, 2014
  16. Jeff KingJul 1, 2014
  17. 6/8 commit: provide a fast multi-tip contains functionJeff King, Jun 25, 2014
  18. Junio C HamanoJun 26, 2014
  19. Junio C HamanoJun 26, 2014
  20. Junio C HamanoJun 26, 2014
  21. Junio C HamanoJul 1, 2014
  22. Junio C HamanoJul 1, 2014
  23. 7/8 tag: use commit_containsJeff King, Jun 25, 2014
  24. 8/8 perf: add tests for tag --containsJeff King, Jun 25, 2014
  25. Jeff KingJun 26, 2014
  26. Jeff KingJun 26, 2014

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.