| 42 | } |
| 43 | |
| 44 | void |
| 45 | bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo, bool fill) { |
| 46 | size_t extra; |
| 47 | unsigned i; |
| 48 | |
| 49 | /* |
| 50 | * Bits are actually inverted with regard to the external bitmap |
| 51 | * interface. |
| 52 | */ |
| 53 | |
| 54 | if (fill) { |
| 55 | /* The "filled" bitmap starts out with all 0 bits. */ |
| 56 | memset(bitmap, 0, bitmap_size(binfo)); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * The "empty" bitmap starts out with all 1 bits, except for trailing |
| 62 | * unused bits (if any). Note that each group uses bit 0 to correspond |
| 63 | * to the first logical bit in the group, so extra bits are the most |
| 64 | * significant bits of the last group. |
| 65 | */ |
| 66 | memset(bitmap, 0xffU, bitmap_size(binfo)); |
| 67 | extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK)) |
| 68 | & BITMAP_GROUP_NBITS_MASK; |
| 69 | if (extra != 0) { |
| 70 | bitmap[binfo->levels[1].group_offset - 1] >>= extra; |
| 71 | } |
| 72 | for (i = 1; i < binfo->nlevels; i++) { |
| 73 | size_t group_count = binfo->levels[i].group_offset - |
| 74 | binfo->levels[i-1].group_offset; |
| 75 | extra = (BITMAP_GROUP_NBITS - (group_count & |
| 76 | BITMAP_GROUP_NBITS_MASK)) & BITMAP_GROUP_NBITS_MASK; |
| 77 | if (extra != 0) { |
| 78 | bitmap[binfo->levels[i+1].group_offset - 1] >>= extra; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | #else /* BITMAP_USE_TREE */ |
| 84 | |