Browse Source

* bitmap compare with dictionary

master
Alex 'AdUser' Z 11 years ago
parent
commit
e799bc169a
  1. 24
      src/bitmap.c
  2. 1
      src/bitmap.h

24
src/bitmap.c

@ -17,6 +17,27 @@
#include "main.h"
#include "bitmap.h"
unsigned char dict[256] = {
/* 0x00 _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */
/* ---------------------------------------------------- */
/* 0_ */ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
/* 1_ */ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
/* 2_ */ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
/* 3_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* 4_ */ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
/* 5_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* 6_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* 7_ */ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
/* 8_ */ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
/* 9_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* A_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* B_ */ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
/* C_ */ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
/* D_ */ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
/* E_ */ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
/* F_ */ 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
};
int bitmap_compare(const unsigned char *a, const unsigned char *b)
{
unsigned char diff = 0;
@ -25,10 +46,13 @@ int bitmap_compare(const unsigned char *a, const unsigned char *b)
for (i = 0; i < BITMAP_SIZE; i++, a++, b++) {
diff = *a ^ *b;
/* bruteforce:
while (diff) {
cnt += (diff & 1);
diff >>= 1;
}
*/
cnt += dict[diff];
}
return cnt;

1
src/bitmap.h

@ -5,5 +5,6 @@
typedef unsigned char bitmap_t[BITMAP_SIZE];
int bitmap_compare(const unsigned char *a, const unsigned char *b);
#endif
#define HAS_BITMAP_H 1

Loading…
Cancel
Save