Browse Source

* use simdb_urec_t instead direct access by offsets

master
Alex 'AdUser' Z 8 years ago
parent
commit
53a775aedc
  1. 28
      src/database.c
  2. 13
      src/sample.c

28
src/database.c

@ -257,10 +257,10 @@ simdb_search(simdb_t * const db,
{ {
simdb_block_t blk; simdb_block_t blk;
simdb_match_t match; simdb_match_t match;
simdb_urec_t *rec;
const int blk_size = 4096; const int blk_size = 4096;
uint64_t found = 0; uint64_t found = 0;
unsigned int i = 0; unsigned int i = 0;
unsigned char *p = NULL;
float ratio_s = 0.0; /* source */ float ratio_s = 0.0; /* source */
float ratio_t = 0.0; /* tested */ float ratio_t = 0.0; /* tested */
int ret = 0; int ret = 0;
@ -289,16 +289,16 @@ simdb_search(simdb_t * const db,
CALLOC(*matches, search->limit, sizeof(simdb_match_t)); CALLOC(*matches, search->limit, sizeof(simdb_match_t));
while (simdb_block_read(db, &blk) > 0) { while (simdb_block_read(db, &blk) > 0) {
p = blk.data; rec = (simdb_urec_t *) blk.data;
for (i = 0; i < blk.records; i++, p += SIMDB_REC_LEN) { for (i = 0; i < blk.records; i++, rec++) {
if (*(p + REC_OFF_RU) == 0x0) if (rec->used == 0x0)
continue; /* record missing */ continue; /* record missing */
match.diff_ratio = 0.0; match.diff_ratio = 0.0;
match.diff_bitmap = 0.0; match.diff_bitmap = 0.0;
/* - compare ratio - cheap */ /* - compare ratio - cheap */
if (ratio_s > 0.0 && (ratio_t = simdb_record_ratio((simdb_urec_t *) p)) > 0.0) { if (ratio_s > 0.0 && (ratio_t = simdb_record_ratio(rec)) > 0.0) {
match.diff_ratio = ratio_s - ratio_t; match.diff_ratio = ratio_s - ratio_t;
match.diff_ratio *= (ratio_s > ratio_t) ? 1.0 : -1.0; match.diff_ratio *= (ratio_s > ratio_t) ? 1.0 : -1.0;
if (match.diff_ratio > search->maxdiff_ratio) if (match.diff_ratio > search->maxdiff_ratio)
@ -308,7 +308,7 @@ simdb_search(simdb_t * const db,
} }
/* - compare bitmap - more expensive */ /* - compare bitmap - more expensive */
match.diff_bitmap = simdb_bitmap_compare(p + REC_OFF_BM, sample->data + REC_OFF_BM) / SIMDB_BITMAP_BITS; match.diff_bitmap = simdb_bitmap_compare(rec->bitmap, ((simdb_urec_t *) sample)->bitmap) / SIMDB_BITMAP_BITS;
if (match.diff_bitmap > search->maxdiff_bitmap) if (match.diff_bitmap > search->maxdiff_bitmap)
continue; continue;
@ -334,7 +334,7 @@ simdb_usage_map(simdb_t * const db,
const int blk_size = 4096; const int blk_size = 4096;
simdb_block_t blk; simdb_block_t blk;
uint64_t records; uint64_t records;
unsigned char *r; /* mnemonics : block, record */ simdb_urec_t *r; /* mnemonics : block, record */
char *m = NULL; /* mnemonics : map */ char *m = NULL; /* mnemonics : map */
memset(&blk, 0x0, sizeof(simdb_block_t)); memset(&blk, 0x0, sizeof(simdb_block_t));
@ -347,9 +347,9 @@ simdb_usage_map(simdb_t * const db,
blk.records = blk_size; blk.records = blk_size;
while (simdb_block_read(db, &blk) > 0) { while (simdb_block_read(db, &blk) > 0) {
r = blk.data; r = (simdb_urec_t *) blk.data;
for (unsigned int i = 0; i < blk.records; i++, m++, r += SIMDB_REC_LEN) { for (unsigned int i = 0; i < blk.records; i++, m++, r++) {
*m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE; *m = (r->used == 0xFF) ? CHAR_USED : CHAR_NONE;
} }
blk.start += blk_size; blk.start += blk_size;
} }
@ -364,7 +364,7 @@ simdb_usage_slice(simdb_t * const db,
uint64_t offset, uint64_t offset,
uint16_t limit) { uint16_t limit) {
simdb_block_t blk; simdb_block_t blk;
unsigned char *r; /* mnemonics : block, record */ simdb_urec_t *r; /* mnemonics : block, record */
char *m = NULL; /* mnemonics : map */ char *m = NULL; /* mnemonics : map */
memset(&blk, 0x0, sizeof(simdb_block_t)); memset(&blk, 0x0, sizeof(simdb_block_t));
@ -375,9 +375,9 @@ simdb_usage_slice(simdb_t * const db,
blk.records = limit; blk.records = limit;
limit = simdb_block_read(db, &blk); limit = simdb_block_read(db, &blk);
r = blk.data; r = (simdb_urec_t *) blk.data;
for (uint16_t i = 0; i < blk.records; i++, m++, r += SIMDB_REC_LEN) { for (uint16_t i = 0; i < blk.records; i++, m++, r++) {
*m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE; *m = (r->used == 0xFF) ? CHAR_USED : CHAR_NONE;
} }
return limit; return limit;

13
src/sample.c

@ -1,6 +1,7 @@
#include "common.h" #include "common.h"
#include "bitmap.h" #include "bitmap.h"
#include "simdb.h" #include "simdb.h"
#include "record.h"
#include "sample.h" #include "sample.h"
#include <wand/magick_wand.h> #include <wand/magick_wand.h>
@ -82,12 +83,14 @@ simdb_sample(simdb_rec_t * const rec,
#endif #endif
if (status == MagickPass) { if (status == MagickPass) {
simdb_urec_t urec;
assert(buf_size == SIMDB_BITMAP_SIZE); assert(buf_size == SIMDB_BITMAP_SIZE);
memset(rec->data, 0x0, SIMDB_REC_LEN); memset(&urec, 0x0, sizeof(urec));
rec->data[REC_OFF_RU] = 0xFF; urec.used = 0xFF;
memcpy(&rec->data[REC_OFF_IW], &w, sizeof(uint16_t)); urec.image_w = w;
memcpy(&rec->data[REC_OFF_IH], &h, sizeof(uint16_t)); urec.image_h = h;
memcpy(&rec->data[REC_OFF_BM], buf, SIMDB_BITMAP_SIZE); memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE);
memcpy(rec->data, &urec, sizeof(rec->data));
} else { } else {
description = MagickGetException(wand, &severity); description = MagickGetException(wand, &severity);
fprintf(stderr, "%03d %.1024s\n", severity, description); fprintf(stderr, "%03d %.1024s\n", severity, description);

Loading…
Cancel
Save