]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ewah: implement `struct ewah_or_iterator`
authorTaylor Blau <me@ttaylorr.com>
Thu, 20 Mar 2025 17:56:59 +0000 (13:56 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Mar 2025 11:34:04 +0000 (04:34 -0700)
While individual bitmap layers store different commit, type-level, and
pseudo-merge bitmaps, only the top-most layer is used to compute
reachability traversals.

Many functions which implement the aforementioned traversal rely on
enumerating the results according to the type-level bitmaps, and so
would benefit from a conceptual type-level bitmap that spans multiple
layers.

Implement `struct ewah_or_iterator` which is capable of enumerating
multiple EWAH bitmaps at once, and OR-ing the results together. When
initialized with, for example, all of the commit type bitmaps from each
layer, callers can pretend as if they are enumerating a large type-level
bitmap which contains the commits from *all* bitmap layers.

There are a couple of alternative approaches which were considered:

  - Decompress each EWAH bitmap and OR them together, enumerating a
    single (non-EWAH) bitmap. This would work, but has the disadvantage
    of decompressing a potentially large bitmap, which may not be
    necessary if the caller does not wish to read all of it.

  - Recursively call bitmap internal functions, reusing the "result" and
    "haves" bitmap from the top-most layer. This approach resembles the
    original implementation of this feature, but is inefficient in that
    it both (a) requires significant refactoring to implement, and (b)
    enumerates large sections of later bitmaps which are all zeros (as
    they pertain to objects in earlier layers).

    (b) is not so bad in and of itself, but can cause significant
    slow-downs when combined with expensive loop bodies.

This approach (enumerating an OR'd together version of all of the
type-level bitmaps from each layer) produces a significantly more
straightforward implementation with significantly less refactoring
required in order to make it work.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ewah/ewah_bitmap.c
ewah/ewok.h

index 67f8f588e056248dbc2707f68abdd832203e5d97..056c410efb7aed5cbd526339f7b6149a285a31a2 100644 (file)
@@ -371,6 +371,39 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
                read_new_rlw(it);
 }
 
+void ewah_or_iterator_init(struct ewah_or_iterator *it,
+                          struct ewah_bitmap **parents, size_t nr)
+{
+       size_t i;
+
+       memset(it, 0, sizeof(*it));
+
+       ALLOC_ARRAY(it->its, nr);
+       for (i = 0; i < nr; i++)
+               ewah_iterator_init(&it->its[it->nr++], parents[i]);
+}
+
+int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it)
+{
+       eword_t buf, out = 0;
+       size_t i;
+       int ret = 0;
+
+       for (i = 0; i < it->nr; i++)
+               if (ewah_iterator_next(&buf, &it->its[i])) {
+                       out |= buf;
+                       ret = 1;
+               }
+
+       *next = out;
+       return ret;
+}
+
+void ewah_or_iterator_release(struct ewah_or_iterator *it)
+{
+       free(it->its);
+}
+
 void ewah_xor(
        struct ewah_bitmap *ewah_i,
        struct ewah_bitmap *ewah_j,
index 5e357e24933e977cc85331fd9dd17d506dd49139..c29d3542361c84ef195efd0c237e6ca23d4fc53e 100644 (file)
@@ -148,6 +148,18 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent);
  */
 int ewah_iterator_next(eword_t *next, struct ewah_iterator *it);
 
+struct ewah_or_iterator {
+       struct ewah_iterator *its;
+       size_t nr;
+};
+
+void ewah_or_iterator_init(struct ewah_or_iterator *it,
+                          struct ewah_bitmap **parents, size_t nr);
+
+int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it);
+
+void ewah_or_iterator_release(struct ewah_or_iterator *it);
+
 void ewah_xor(
        struct ewah_bitmap *ewah_i,
        struct ewah_bitmap *ewah_j,