Reduce differences between alternative bitmap implementations.

This commit is contained in:
Jason Evans 2016-04-06 10:38:47 -07:00
parent 4a8abbb400
commit 2ee2f1ec57
2 changed files with 5 additions and 8 deletions

View File

@ -223,7 +223,7 @@ bitmap_sfu(bitmap_t *bitmap, const bitmap_info_t *binfo)
i++; i++;
g = bitmap[i]; g = bitmap[i];
} }
bit = (bit - 1) + (i << LG_BITMAP_GROUP_NBITS); bit = (i << LG_BITMAP_GROUP_NBITS) + (bit - 1);
#endif #endif
bitmap_set(bitmap, binfo, bit); bitmap_set(bitmap, binfo, bit);
return (bit); return (bit);

View File

@ -74,15 +74,11 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
void void
bitmap_info_init(bitmap_info_t *binfo, size_t nbits) bitmap_info_init(bitmap_info_t *binfo, size_t nbits)
{ {
size_t i;
assert(nbits > 0); assert(nbits > 0);
assert(nbits <= (ZU(1) << LG_BITMAP_MAXBITS)); assert(nbits <= (ZU(1) << LG_BITMAP_MAXBITS));
i = nbits >> LG_BITMAP_GROUP_NBITS; binfo->ngroups = BITMAP_BITS2GROUPS(nbits);
if (nbits % BITMAP_GROUP_NBITS != 0)
i++;
binfo->ngroups = i;
binfo->nbits = nbits; binfo->nbits = nbits;
} }
@ -99,9 +95,10 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
size_t extra; size_t extra;
memset(bitmap, 0xffU, bitmap_size(binfo)); memset(bitmap, 0xffU, bitmap_size(binfo));
extra = (binfo->nbits % (binfo->ngroups * BITMAP_GROUP_NBITS)); extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK))
& BITMAP_GROUP_NBITS_MASK;
if (extra != 0) if (extra != 0)
bitmap[binfo->ngroups - 1] >>= (BITMAP_GROUP_NBITS - extra); bitmap[binfo->ngroups - 1] >>= extra;
} }
#endif /* USE_TREE */ #endif /* USE_TREE */