Skip to content

Commit f1d45ea

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a6b42d commit f1d45ea

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ewah/ewah_bitmap.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,39 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
372372
read_new_rlw(it);
373373
}
374374

375+
void ewah_or_iterator_init(struct ewah_or_iterator *it,
376+
struct ewah_bitmap **parents, size_t nr)
377+
{
378+
size_t i;
379+
380+
memset(it, 0, sizeof(*it));
381+
382+
ALLOC_ARRAY(it->its, nr);
383+
for (i = 0; i < nr; i++)
384+
ewah_iterator_init(&it->its[it->nr++], parents[i]);
385+
}
386+
387+
int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it)
388+
{
389+
eword_t buf, out = 0;
390+
size_t i;
391+
int ret = 0;
392+
393+
for (i = 0; i < it->nr; i++)
394+
if (ewah_iterator_next(&buf, &it->its[i])) {
395+
out |= buf;
396+
ret = 1;
397+
}
398+
399+
*next = out;
400+
return ret;
401+
}
402+
403+
void ewah_or_iterator_free(struct ewah_or_iterator *it)
404+
{
405+
free(it->its);
406+
}
407+
375408
void ewah_xor(
376409
struct ewah_bitmap *ewah_i,
377410
struct ewah_bitmap *ewah_j,

ewah/ewok.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent);
148148
*/
149149
int ewah_iterator_next(eword_t *next, struct ewah_iterator *it);
150150

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_free(struct ewah_or_iterator *it);
162+
151163
void ewah_xor(
152164
struct ewah_bitmap *ewah_i,
153165
struct ewah_bitmap *ewah_j,

0 commit comments

Comments
 (0)