From: David Given Date: Sat, 21 Jan 2017 19:50:57 +0000 (+0100) Subject: Add a function for finding the first unset bit. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b7f0e00c65068b4f6920f359d3e652a951c7b5b9;p=ack.git Add a function for finding the first unset bit. --- diff --git a/modules/src/data/bitmap.c b/modules/src/data/bitmap.c index 363d22d49..d47684d9d 100644 --- a/modules/src/data/bitmap.c +++ b/modules/src/data/bitmap.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "bitmap.h" @@ -35,7 +36,7 @@ int bitmap_findfirst(unsigned int* bitmap, int size) { unsigned int w = bitmap[word]; if (w) - return ffs(w) + word*BITS_PER_WORD; + return (ffs(w)-1) + word*BITS_PER_WORD; } return -1; @@ -59,3 +60,28 @@ void bitmap_or(unsigned int* dest, int size, unsigned int* src) dest[word] |= src[word]; } +int bitmap_find_unset_bit(unsigned int* bitmap, int size) +{ + int word; + int words = ((size-1) / BITS_PER_WORD) + 1; + + for (word=0; word