diff --git a/src/bitmap.c b/src/bitmap.c index 5b0d9cb..f4797cf 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -17,14 +17,14 @@ #include "main.h" #include "bitmap.h" -int bitmap_compare(bitmap_t *a, bitmap_t *b) +int bitmap_compare(const unsigned char *a, const unsigned char *b) { - uint16_t row = 0; - uint16_t diff = 0; - size_t cnt = 0; + unsigned char diff = 0; + size_t i = 0; + size_t cnt = 0; - for (row = 0; row < 16; row++) { - diff = (*a)[row] ^ (*b)[row]; + for (i = 0; i < BITMAP_SIZE; i++, a++, b++) { + diff = *a ^ *b; while (diff) { cnt += (diff & 1); diff >>= 1; diff --git a/src/bitmap.h b/src/bitmap.h index 493c779..981b22b 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -1,6 +1,9 @@ #ifndef HAS_BITMAP_H -typedef uint16_t bitmap_t[16]; -int bitmap_compare(bitmap_t *a, bitmap_t *b); +#define BITMAP_SIZE 32 + +typedef unsigned char bitmap_t[BITMAP_SIZE]; + +int bitmap_compare(const unsigned char *a, const unsigned char *b); #endif -#define HAS_BITMAP_H +#define HAS_BITMAP_H 1 diff --git a/tests/Makefile b/tests/Makefile index 42a2f16..78ea1c4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,3 +8,6 @@ CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic SRC=../src/bitmap.c bitmap.c test-bitmap: gcc $(CFLAGS) $(SRC) -o $@ + +clean: + rm -f test-bitmap diff --git a/tests/bitmap.c b/tests/bitmap.c index 3021ed3..25a3b25 100644 --- a/tests/bitmap.c +++ b/tests/bitmap.c @@ -4,31 +4,31 @@ int main(int argc, char **argv) { - bitmap a, b; + bitmap_t a, b; - memset (&a, 0x00, 16 * sizeof(uint16_t)); - memset (&b, 0x00, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 0); + memset (a, 0x00, sizeof(bitmap_t)); + memset (b, 0x00, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 0); - memset (&a, 0xFE, 16 * sizeof(uint16_t)); - memset (&b, 0xFF, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 32); + memset (a, 0xFE, sizeof(bitmap_t)); + memset (b, 0xFF, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 32); - memset (&a, 0x00, 16 * sizeof(uint16_t)); - memset (&b, 0x55, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 128); + memset (a, 0x00, sizeof(bitmap_t)); + memset (b, 0x55, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 128); - memset (&a, 0x00, 16 * sizeof(uint16_t)); - memset (&b, 0xAA, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 128); + memset (a, 0x00, sizeof(bitmap_t)); + memset (b, 0xAA, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 128); - memset (&a, 0xAA, 16 * sizeof(uint16_t)); - memset (&b, 0x55, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 256); + memset (a, 0xAA, sizeof(bitmap_t)); + memset (b, 0x55, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 256); - memset (&a, 0x00, 16 * sizeof(uint16_t)); - memset (&b, 0xFF, 16 * sizeof(uint16_t)); - assert(bitmap_compare(&a, &b) == 256); + memset (a, 0x00, sizeof(bitmap_t)); + memset (b, 0xFF, sizeof(bitmap_t)); + assert(bitmap_compare(a, b) == 256); return 0; }