]> git.ozlabs.org Git - ccan/blobdiff - ccan/bitmap/bitmap.h
xtea: new module.
[ccan] / ccan / bitmap / bitmap.h
index 6c8d7e4d4593e0f1745704c92761e69121fd25dd..543828010188aa39490005ebe53dcaba3b52c1a5 100644 (file)
@@ -15,10 +15,13 @@ typedef unsigned long bitmap_word;
 #define BITMAP_NWORDS(_n)      \
        (((_n) + BITMAP_WORD_BITS - 1) / BITMAP_WORD_BITS)
 
+#define BITMAP_WORD_0          (0)
+#define BITMAP_WORD_1          ((bitmap_word)-1UL)
+
 /*
  * We wrap each word in a structure for type checking.
  */
-typedef struct {
+typedef struct bitmap {
        bitmap_word w;
 } bitmap;
 
@@ -187,6 +190,9 @@ static inline bool bitmap_empty(const bitmap *bitmap, unsigned long nbits)
        return true;
 }
 
+unsigned long bitmap_ffs(const bitmap *bitmap,
+                        unsigned long n, unsigned long m);
+
 /*
  * Allocation functions
  */
@@ -200,7 +206,8 @@ static inline bitmap *bitmap_alloc0(unsigned long nbits)
        bitmap *bitmap;
 
        bitmap = bitmap_alloc(nbits);
-       bitmap_zero(bitmap, nbits);
+       if (bitmap)
+               bitmap_zero(bitmap, nbits);
        return bitmap;
 }
 
@@ -209,7 +216,8 @@ static inline bitmap *bitmap_alloc1(unsigned long nbits)
        bitmap *bitmap;
 
        bitmap = bitmap_alloc(nbits);
-       bitmap_fill(bitmap, nbits);
+       if (bitmap)
+               bitmap_fill(bitmap, nbits);
        return bitmap;
 }
 
@@ -218,7 +226,7 @@ static inline bitmap *bitmap_realloc0(bitmap *bitmap,
 {
        bitmap = realloc(bitmap, bitmap_sizeof(nbits));
 
-       if (nbits > obits)
+       if ((nbits > obits) && bitmap)
                bitmap_zero_range(bitmap, obits, nbits);
 
        return bitmap;
@@ -229,7 +237,7 @@ static inline bitmap *bitmap_realloc1(bitmap *bitmap,
 {
        bitmap = realloc(bitmap, bitmap_sizeof(nbits));
 
-       if (nbits > obits)
+       if ((nbits > obits) && bitmap)
                bitmap_fill_range(bitmap, obits, nbits);
 
        return bitmap;