mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
[set] Add a macro to initialize with a static array
Nicer than trying to hack one one every time (and it looks like my previous attempt was wrong anyway)
This commit is contained in:
parent
cbc5654b5e
commit
76c62b49e0
1 changed files with 9 additions and 0 deletions
|
@ -52,6 +52,7 @@ typedef uint32_t set_bits_t;
|
|||
#define SET_BITS (sizeof (set_bits_t) * 8)
|
||||
//NOTE: x is the element number, so size is x + 1
|
||||
#define SET_SIZE(x) (((x) + SET_BITS) & ~(SET_BITS - 1))
|
||||
#define SET_WORDS_STATIC(x) (SET_SIZE (x) / SET_BITS)
|
||||
#define SET_WORDS(s) ((s)->size / SET_BITS)
|
||||
#define SET_ZERO ((set_bits_t) 0)
|
||||
#define SET_ONE ((set_bits_t) 1)
|
||||
|
@ -65,6 +66,14 @@ typedef uint32_t set_bits_t;
|
|||
.size = SET_SIZE (x), \
|
||||
.map = alloc (SET_SIZE (x) / 8), \
|
||||
}
|
||||
#define SET_STATIC_ARRAY(array) { \
|
||||
.size = 8 * __builtin_choose_expr ( \
|
||||
sizeof (array[0]) == sizeof (set_bits_t), \
|
||||
sizeof (array), \
|
||||
(void) 0 \
|
||||
), \
|
||||
.map = array, \
|
||||
}
|
||||
|
||||
/** Represent a set using a bitmap.
|
||||
|
||||
|
|
Loading…
Reference in a new issue