Git fork

ewah: implement `struct ewah_or_iterator`

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>

authored by

Taylor Blau and committed by
Junio C Hamano
5551ccfe e2837e29

+45
+33
ewah/ewah_bitmap.c
··· 371 371 read_new_rlw(it); 372 372 } 373 373 374 + void ewah_or_iterator_init(struct ewah_or_iterator *it, 375 + struct ewah_bitmap **parents, size_t nr) 376 + { 377 + size_t i; 378 + 379 + memset(it, 0, sizeof(*it)); 380 + 381 + ALLOC_ARRAY(it->its, nr); 382 + for (i = 0; i < nr; i++) 383 + ewah_iterator_init(&it->its[it->nr++], parents[i]); 384 + } 385 + 386 + int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it) 387 + { 388 + eword_t buf, out = 0; 389 + size_t i; 390 + int ret = 0; 391 + 392 + for (i = 0; i < it->nr; i++) 393 + if (ewah_iterator_next(&buf, &it->its[i])) { 394 + out |= buf; 395 + ret = 1; 396 + } 397 + 398 + *next = out; 399 + return ret; 400 + } 401 + 402 + void ewah_or_iterator_release(struct ewah_or_iterator *it) 403 + { 404 + free(it->its); 405 + } 406 + 374 407 void ewah_xor( 375 408 struct ewah_bitmap *ewah_i, 376 409 struct ewah_bitmap *ewah_j,
+12
ewah/ewok.h
··· 148 148 */ 149 149 int ewah_iterator_next(eword_t *next, struct ewah_iterator *it); 150 150 151 + struct ewah_or_iterator { 152 + struct ewah_iterator *its; 153 + size_t nr; 154 + }; 155 + 156 + void ewah_or_iterator_init(struct ewah_or_iterator *it, 157 + struct ewah_bitmap **parents, size_t nr); 158 + 159 + int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it); 160 + 161 + void ewah_or_iterator_release(struct ewah_or_iterator *it); 162 + 151 163 void ewah_xor( 152 164 struct ewah_bitmap *ewah_i, 153 165 struct ewah_bitmap *ewah_j,