X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fbitmap%2Fbitmap.h;h=9e6c2bbc51912d797eec56000963756598d48592;hb=9a5d0387e388594616ce216ce07de39c205d547c;hp=794b2650361955f29dbf2a0fc2f5265afb3daaf8;hpb=d91a3b8b416ed12bf7c0d5b0bda902b7ae769a40;p=ccan diff --git a/ccan/bitmap/bitmap.h b/ccan/bitmap/bitmap.h index 794b2650..9e6c2bbc 100644 --- a/ccan/bitmap/bitmap.h +++ b/ccan/bitmap/bitmap.h @@ -30,11 +30,6 @@ static inline size_t bitmap_sizeof(unsigned long nbits) return BITMAP_NWORDS(nbits) * sizeof(bitmap_word); } -static inline bitmap *bitmap_alloc(unsigned long nbits) -{ - return malloc(bitmap_sizeof(nbits)); -} - static inline bitmap_word bitmap_bswap(bitmap_word w) { if (BITMAP_WORD_BITS == 32) @@ -80,6 +75,8 @@ static inline bool bitmap_test_bit(const bitmap *bitmap, unsigned long n) return !!(BITMAP_WORD(bitmap, n) & BITMAP_WORDBIT(n)); } +void bitmap_zero_range(bitmap *bitmap, unsigned long n, unsigned long m); +void bitmap_fill_range(bitmap *bitmap, unsigned long n, unsigned long m); static inline void bitmap_zero(bitmap *bitmap, unsigned long nbits) { @@ -190,4 +187,57 @@ 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 + */ +static inline bitmap *bitmap_alloc(unsigned long nbits) +{ + return malloc(bitmap_sizeof(nbits)); +} + +static inline bitmap *bitmap_alloc0(unsigned long nbits) +{ + bitmap *bitmap; + + bitmap = bitmap_alloc(nbits); + if (bitmap) + bitmap_zero(bitmap, nbits); + return bitmap; +} + +static inline bitmap *bitmap_alloc1(unsigned long nbits) +{ + bitmap *bitmap; + + bitmap = bitmap_alloc(nbits); + if (bitmap) + bitmap_fill(bitmap, nbits); + return bitmap; +} + +static inline bitmap *bitmap_realloc0(bitmap *bitmap, + unsigned long obits, unsigned long nbits) +{ + bitmap = realloc(bitmap, bitmap_sizeof(nbits)); + + if ((nbits > obits) && bitmap) + bitmap_zero_range(bitmap, obits, nbits); + + return bitmap; +} + +static inline bitmap *bitmap_realloc1(bitmap *bitmap, + unsigned long obits, unsigned long nbits) +{ + bitmap = realloc(bitmap, bitmap_sizeof(nbits)); + + if ((nbits > obits) && bitmap) + bitmap_fill_range(bitmap, obits, nbits); + + return bitmap; +} + #endif /* CCAN_BITMAP_H_ */