From 76c62b49e060cf5ee21dc5fd10dd0179f1313a88 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 4 Jun 2022 12:06:34 +0900 Subject: [PATCH] [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) --- include/QF/set.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/QF/set.h b/include/QF/set.h index 1d59ed395..e7d75e4f5 100644 --- a/include/QF/set.h +++ b/include/QF/set.h @@ -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.