+/**
+ * Returns 1 of two bitsets are equal.
+ *
+ * @param bitset1 the first bitset
+ * @param bitset2 the second bitset
+ * @param size size of both bitsets in bits
+ */
+static inline bool rbitsets_equal(const unsigned *bitset1,
+ const unsigned *bitset2, size_t size)
+{
+ size_t size_bytes = BITSET_SIZE_BYTES(size);
+ return memcmp(bitset1, bitset2, size_bytes) == 0;
+}
+
+/**
+ * Tests wether 2 bitsets wether at least 1 bit is set in both.
+ *
+ * @param bitset1 the first bitset
+ * @param bitset2 the second bitset
+ * @param size size of both bitsets in bits
+ */
+static inline bool rbitsets_have_common(const unsigned *bitset1,
+ const unsigned *bitset2, size_t size)
+{
+ size_t i, n = BITSET_SIZE_ELEMS(size);
+
+ for (i = 0; i < n; ++i) {
+ if ((bitset1[i] & bitset2[i]) != 0)
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Tests wether all bits set in bitset1 are also set in bitset2.
+ *
+ * @param bitset1 the first bitset
+ * @param bitset2 the second bitset
+ * @param size size of both bitsets in bits
+ */
+static inline bool rbitset_contains(const unsigned *bitset1,
+ const unsigned *bitset2, size_t size)
+{
+ size_t i, n = BITSET_SIZE_ELEMS(size);
+
+ for (i = 0; i < n; ++i) {
+ if ((bitset1[i] & bitset2[i]) != bitset1[i])
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Treat the bitset as a number and subtract 1.
+ * @param bitset the bitset.
+ * @return size size of the bitset in bits
+ */
+static inline void rbitset_minus1(unsigned *bitset, size_t size)
+{
+ size_t i, n = BITSET_SIZE_ELEMS(size);
+ unsigned last_mask = rbitset_last_mask_(size);
+
+ for (i = 0; i < n; ++i) {
+ unsigned mask = i == n-1 ? last_mask : ~0u;
+ unsigned val = bitset[i] & mask;
+ unsigned val_minus1 = val - 1;
+ bitset[i] = val_minus1 & mask;
+
+ if (((val >> (BITS_PER_ELEM-1)) ^ (val_minus1 >> (BITS_PER_ELEM-1))) == 0)
+ break;
+ }
+}
+
+/**
+ * Copy a raw bitset into another.
+ *
+ * @param dst the destination set
+ * @param src the source set
+ * @param size size of both bitsets in bits
+ */
+static inline void rbitset_copy(unsigned *dst, const unsigned *src,
+ size_t size)
+{
+ memcpy(dst, src, BITSET_SIZE_BYTES(size));
+}
+
+static inline void rbitset_copy_into(unsigned *dst, const unsigned *src,
+ size_t size)
+{
+ size_t n = BITSET_SIZE_ELEMS(size);
+ unsigned last_mask = rbitset_last_mask_(size);
+
+ memcpy(dst, src, (n-1) * (BITS_PER_ELEM/8));
+ dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
+}
+