[util] Make set_t endian-agnostic

Most of the set ops were always endian-agnostic since they were simply
operating on multiple bits in parallel, but individual element
add/remove/test was very endian-dependent. For the most part, this
didn't matter, but it does matter very much when loading external data
into a set or writing the data out (eg, for PVS).
This commit is contained in:
Bill Currie 2021-08-04 11:21:17 +09:00
parent 648ae3f877
commit b320c3352f
2 changed files with 8 additions and 4 deletions

View file

@ -56,7 +56,11 @@ typedef uint32_t set_bits_t;
#define SET_ZERO ((set_bits_t) 0)
#define SET_ONE ((set_bits_t) 1)
#define SET_TEST_MEMBER(s, x) \
((s)->map[(x) / SET_BITS] & (SET_ONE << ((x) % SET_BITS)))
(((const byte *)(s)->map)[(x) / 8] & (SET_ONE << ((x) % 8)))
#define SET_ADD(s, x) \
(((byte *)(s)->map)[(x) / 8] |= (SET_ONE << ((x) % 8)))
#define SET_REMOVE(s, x) \
(((byte *)(s)->map)[(x) / 8] &= ~(SET_ONE << ((x) % 8)))
#define SET_STATIC_INIT(x, alloc) { \
.size = SET_SIZE (x), \
.map = alloc (SET_SIZE (x) / 8), \

View file

@ -150,7 +150,7 @@ _set_add (set_t *set, unsigned x)
{
if (x >= set->size)
set_expand (set, x + 1);
set->map[x / SET_BITS] |= SET_ONE << (x % SET_BITS);
SET_ADD(set, x);
}
static inline void
@ -158,7 +158,7 @@ _set_remove (set_t *set, unsigned x)
{
if (x >= set->size)
return;
set->map[x / SET_BITS] &= ~(SET_ONE << (x % SET_BITS));
SET_REMOVE(set, x);
}
set_t *
@ -539,7 +539,7 @@ _set_is_member (const set_t *set, unsigned x)
{
if (x >= set->size)
return 0;
return (set->map[x / SET_BITS] & (SET_ONE << (x % SET_BITS))) != 0;
return SET_TEST_MEMBER(set, x) != 0;
}
int