Re: move some bitmapset.c macros to bitmapset.h - Mailing list pgsql-hackers

From David Rowley
Subject Re: move some bitmapset.c macros to bitmapset.h
Date
Msg-id CAApHDvpyucADjv5D_vXUzxYBDsoohV5t-sjktYjugeDu3KSK-Q@mail.gmail.com
Whole thread Raw
In response to Re: move some bitmapset.c macros to bitmapset.h  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: move some bitmapset.c macros to bitmapset.h
List pgsql-hackers
On Tue, 6 Dec 2022 at 17:57, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> And RIGHTMOST_ONE is something that could be made public, but
> I think it belongs in pg_bitutils.h, perhaps with a different
> name.

Maybe there's a path of lesser resistance... There's been a bit of
work in pg_bitutils.h to define some of the bit manipulation functions
for size_t types which wrap the 32 or 64-bit version of the function
accordingly. Couldn't we just define one of those for
pg_rightmost_one_pos and then use a size_t as the bitmap word type?

Then you'd end up with something like:

for (idx = 0; idx < 128 / (sizeof(size_t) * 8); idx++)
 if (isset[idx] != ~((size_t) 0))
    break;
slotpos = idx * (sizeof(size_t) * 8) + pg_rightmost_one_pos_size_t(~isset[idx]);

no need to export anything from bitmapset.c to do it like that.

I've not looked at the code in question to know how often that form
would be needed. Maybe it would need a set of inlined functions
similar to above in the same file this is being used in to save on
repeating too often.

David



pgsql-hackers by date:

Previous
From: Vik Fearing
Date:
Subject: Re: ANY_VALUE aggregate
Next
From: Tom Lane
Date:
Subject: Re: move some bitmapset.c macros to bitmapset.h