Browse Source

* bitmap_compare

master
Alex 'AdUser' Z 11 years ago
parent
commit
260dd3b2ce
  1. 6
      src/Makefile
  2. 10
      src/bitmap.c
  3. 10
      tests/Makefile
  4. 4
      tests/bitmap.c

6
src/Makefile

@ -1,11 +1,7 @@
all: test-bitmap all:
%.o: %.c %.o: %.c
gcc -O0 -Wall -Wextra -pedantic -ggdb $< -o $@ gcc -O0 -Wall -Wextra -pedantic -ggdb $< -o $@
test-bitmap: test-bitmap.c bitmap.c
gcc -Wall -Wextra -pedantic -g -ggdb test-bitmap.c bitmap.c -o test-bitmap
clean: clean:
rm -f *.o rm -f *.o
rm -f test-bitmap

10
src/bitmap.c

@ -20,14 +20,14 @@
int bitmap_compare(bitmap *a, bitmap *b) int bitmap_compare(bitmap *a, bitmap *b)
{ {
uint16_t row = 0; uint16_t row = 0;
uint16_t bit = 0; uint16_t diff = 0;
size_t cnt = 0; size_t cnt = 0;
for (row = 0; row < 16; row++) { for (row = 0; row < 16; row++) {
bit = 1 << 15; diff = (*a)[row] ^ (*b)[row];
while (bit) { while (diff) {
cnt += !!(((*a)[row] & bit) ^ ((*b)[row] & bit)); cnt += (diff & 1);
bit >>= 1; diff >>= 1;
} }
} }

10
tests/Makefile

@ -0,0 +1,10 @@
all: test-bitmap
CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic
%.o: %.c
gcc $(CFLAGS) $< -o $@
SRC=../src/bitmap.c bitmap.c
test-bitmap:
gcc $(CFLAGS) $(SRC) -o $@

4
tests/bitmap.c

@ -1,5 +1,5 @@
#include "main.h" #include "../src/main.h"
#include "bitmap.h" #include "../src/bitmap.h"
int int
main(int argc, char **argv) main(int argc, char **argv)

Loading…
Cancel
Save