Generalise bitfield fully
authornorly <ny-git@enpas.org>
Sun, 14 Jul 2019 12:46:57 +0000 (14:46 +0200)
committernorly <ny-git@enpas.org>
Sun, 14 Jul 2019 12:57:19 +0000 (14:57 +0200)
lookup-incoming.c

index 8223feb5618e72d77a3cadeb2689beb3ebd605b4..da21f4433ba55fb6eac462caa6f83ca94531dddf 100644 (file)
 
 
 typedef __uint32_t bitfield_type;
+#define BITS_PER_BITFIELD 32
+#define BITS_PER_BITFIELD_LOG 5
 
 #define BIT_SET(set, d) \
-  ( (void) ( set[d >> 5] |= (1 << (d & 31)) ) )
+  ( (void) ( set[d >> BITS_PER_BITFIELD_LOG] |= (1 << (d & (BITS_PER_BITFIELD-1))) ) )
 #define BIT_ISSET(set, d) \
-  (!(! ( set[d >> 5] & (1 << (d & 31)) ) ))
+  (!(! ( set[d >> BITS_PER_BITFIELD_LOG] & (1 << (d & (BITS_PER_BITFIELD-1))) ) ))
 
 int ANY_BITS_SET(bitfield_type *set, size_t elems)
 {
@@ -191,7 +193,7 @@ int main(int argc, char **argv)
 
        printf("\n\n\n\nBuilding table of distances...\n\n");
 
-       titles_bitfield_elems = ROUNDUP(titles / 8 / sizeof(bitfield_type), sizeof(bitfield_type));
+       titles_bitfield_elems = ROUNDUP(titles / BITS_PER_BITFIELD, BITS_PER_BITFIELD);
        titles_bitfield_bytes = titles_bitfield_elems * sizeof(bitfield_type);
 
        titles_seen = calloc(titles_bitfield_bytes, 1);