summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
95a6664)
A few macros took a struct bvector pointer as their first argument just
to get the sizeof one of its fields. This can be done with a NULL
pointer so remove that argument from all of them.
* constants in the code below must also be changed to a 1 that's at
* least as wide as the new type.
*/
* constants in the code below must also be changed to a 1 that's at
* least as wide as the new type.
*/
-#define BVEC_WORD(vec, max) ((max) / (sizeof *vec->bits * CHAR_BIT))
-#define BVEC_OFFSET(vec, max) ((max) % (sizeof *vec->bits * CHAR_BIT))
-#define BVEC_BYTES(vec, n) \
- ((BVEC_WORD (vec, n) + (BVEC_OFFSET (vec, n) == 0 ? 0 : 1)) * \
- sizeof *vec->bits)
+#define BVEC_SIZEOF_BITS (sizeof *(((bvector_t)NULL)->bits))
+#define BVEC_WORD(max) ((max) / (BVEC_SIZEOF_BITS * CHAR_BIT))
+#define BVEC_OFFSET(max) ((max) % (BVEC_SIZEOF_BITS * CHAR_BIT))
+#define BVEC_BYTES(n) \
+ ((BVEC_WORD(n) + (BVEC_OFFSET(n) == 0 ? 0 : 1)) * BVEC_SIZEOF_BITS)
struct bvector {
unsigned long *bits;
struct bvector {
unsigned long *bits;
assert (sizeof *vec->bits <= sizeof 1ul);
NEW(vec);
assert (sizeof *vec->bits <= sizeof 1ul);
NEW(vec);
- bytes = BVEC_BYTES (vec, init_size ? init_size : VEC_INIT_SIZE);
+ bytes = BVEC_BYTES(init_size ? init_size : VEC_INIT_SIZE);
vec->bits = mh_xcalloc (1, bytes);
vec->maxsize = bytes * CHAR_BIT;
vec->bits = mh_xcalloc (1, bytes);
vec->maxsize = bytes * CHAR_BIT;
void
bvector_copy (bvector_t dest, bvector_t src) {
void
bvector_copy (bvector_t dest, bvector_t src) {
- size_t bytes = BVEC_BYTES (dest, src->maxsize);
+ size_t bytes = BVEC_BYTES(src->maxsize);
free (dest->bits);
dest->bits = mh_xmalloc (bytes);
free (dest->bits);
dest->bits = mh_xmalloc (bytes);
void
bvector_clear (bvector_t vec, size_t n) {
void
bvector_clear (bvector_t vec, size_t n) {
- size_t word = BVEC_WORD (vec,n);
- size_t offset = BVEC_OFFSET (vec, n);
+ size_t word = BVEC_WORD(n);
+ size_t offset = BVEC_OFFSET(n);
if (n >= vec->maxsize)
bvector_resize (vec, n);
if (n >= vec->maxsize)
bvector_resize (vec, n);
void
bvector_clear_all (bvector_t vec) {
void
bvector_clear_all (bvector_t vec) {
- memset (vec->bits, 0, BVEC_BYTES (vec, vec->maxsize));
+ memset (vec->bits, 0, BVEC_BYTES(vec->maxsize));
}
void
bvector_set (bvector_t vec, size_t n) {
}
void
bvector_set (bvector_t vec, size_t n) {
- size_t word = BVEC_WORD (vec, n);
- size_t offset = BVEC_OFFSET (vec, n);
+ size_t word = BVEC_WORD(n);
+ size_t offset = BVEC_OFFSET(n);
if (n >= vec->maxsize)
bvector_resize (vec, n);
if (n >= vec->maxsize)
bvector_resize (vec, n);
unsigned int
bvector_at (bvector_t vec, size_t i) {
unsigned int
bvector_at (bvector_t vec, size_t i) {
- size_t word = BVEC_WORD (vec, i);
- size_t offset = BVEC_OFFSET (vec, i);
+ size_t word = BVEC_WORD(i);
+ size_t offset = BVEC_OFFSET(i);
return i < vec->maxsize
? (vec->bits[word] & (1ul << offset) ? 1 : 0)
return i < vec->maxsize
? (vec->bits[word] & (1ul << offset) ? 1 : 0)
while ((vec->maxsize *= 2) < maxsize)
;
while ((vec->maxsize *= 2) < maxsize)
;
- bytes = BVEC_BYTES (vec, vec->maxsize);
+ bytes = BVEC_BYTES(vec->maxsize);
vec->bits = mh_xrealloc (vec->bits, bytes);
for (i = old_maxsize; i < vec->maxsize; ++i)
bvector_clear (vec, i);
vec->bits = mh_xrealloc (vec->bits, bytes);
for (i = old_maxsize; i < vec->maxsize; ++i)
bvector_clear (vec, i);