if (b->bits != NULL || bit_cnt == 0)
{
bitmap_set_all (b, false);
if (b->bits != NULL || bit_cnt == 0)
{
bitmap_set_all (b, false);
bitmap_set_multiple (b, 0, bitmap_size (b), value);
}
bitmap_set_multiple (b, 0, bitmap_size (b), value);
}
-bitmap_set_multiple (struct bitmap *b, size_t start, size_t end, bool value)
+bitmap_set_multiple (struct bitmap *b, size_t start, size_t cnt, bool value)
- for (idx = start; idx < end; idx++)
- bitmap_set (b, idx, value);
+ for (i = 0; i < cnt; i++)
+ bitmap_set (b, start + i, value);
-contains (const struct bitmap *b, size_t start, size_t end, bool value)
+contains (const struct bitmap *b, size_t start, size_t cnt, bool value)
- for (idx = start; idx < end; idx++)
- if (bitmap_test (b, idx) == value)
+ for (i = 0; i < cnt; i++)
+ if (bitmap_test (b, start + i) == value)
- if (!contains (b, idx, idx + cnt, !value))
+ if (!contains (b, idx, cnt, !value))
START that are all set to VALUE, flips them all to !VALUE,
and returns the index of the first bit in the group.
If there is no such group, returns BITMAP_ERROR.
START that are all set to VALUE, flips them all to !VALUE,
and returns the index of the first bit in the group.
If there is no such group, returns BITMAP_ERROR.
{
size_t idx = bitmap_scan (b, start, cnt, value);
if (idx != BITMAP_ERROR)
{
size_t idx = bitmap_scan (b, start, cnt, value);
if (idx != BITMAP_ERROR)
- bitmap_set_multiple (b, idx, idx + cnt, !value);
+ bitmap_set_multiple (b, idx, cnt, !value);
-bitmap_count (const struct bitmap *b, size_t start, size_t end, bool value)
+bitmap_count (const struct bitmap *b, size_t start, size_t cnt, bool value)
- cnt = 0;
- for (idx = start; idx < end; idx++)
- cnt += bitmap_test (b, idx) == value;
- return cnt;
+ value_cnt = 0;
+ for (i = 0; i < cnt; i++)
+ if (bitmap_test (b, start + i) == value)
+ value_cnt++;
+ return value_cnt;
- return contains (b, start, end, true);
+ return contains (b, start, cnt, true);
-/* Returns true if no bits in B between START and END, exclusive,
- are set to true, and false otherwise.*/
+/* Returns true if no bits in B between START and START + CNT,
+ exclusive, are set to true, and false otherwise.*/
- return !contains (b, start, end, true);
+ return !contains (b, start, cnt, true);
- return !contains (b, start, end, false);
+ return !contains (b, start, cnt, false);
- file_read_at (file, b->bits, byte_cnt (b), 0);
- b->bits[elem_cnt (b) - 1] &= last_mask (b);
+ file_read_at (file, b->bits, byte_cnt (b->bit_cnt), 0);
+ b->bits[elem_cnt (b->bit_cnt) - 1] &= last_mask (b);
- file_write_at (file, b->bits, byte_cnt (b), 0);
+ file_write_at (file, b->bits, byte_cnt (b->bit_cnt), 0);
- hex_dump (0, b->bits, byte_cnt (b), false);
+ hex_dump (0, b->bits, byte_cnt (b->bit_cnt), false);