Browse Source

+ db_search

master
Alex 'AdUser' Z 11 years ago
parent
commit
e42bbef769
  1. 34
      src/database.c
  2. 5
      src/database.h

34
src/database.c

@ -16,6 +16,7 @@
#include "main.h"
#include "database.h"
#include "bitmap.h"
#define DB_SEEK(db, offset) \
errno = 0; \
@ -122,7 +123,7 @@ int db_wr_rec(db_t *db, rec_t *rec)
}
int db_rd_blk(db_t *db, block_t *blk)
{
{
ssize_t bytes = 0;
assert(db != NULL);
@ -180,3 +181,34 @@ int db_wr_list(db_t *db, rec_t *list, size_t list_len)
return processed;
}
int db_search(db_t *db, float tresh, match_t **matches)
{
uint64_t found = 0;
block_t blk;
const int blk_size = 4096;
unsigned int i = 0;
unsigned char *p;
float diff = 0;
*matches = NULL;
match = *matches;
memset(blk, 0x0, sizeof(block_t));
blk.start = 1;
blk.records = blk_size;
/* TODO: expand matches */
while (db_rd_blk(db, &blk) > 0) {
p = blk.data;
for (i = 0; i < blk.records; i++, p += REC_LEN) {
if (*p == '\0') continue;
diff = bitmap_compare(p + 2, sample.data + 2) / BITMAP_BITS;
if (diff > tresh) continue;
match->diff_map = diff;
}
FREE(blk.data);
}
return found;
}

5
src/database.h

@ -21,6 +21,11 @@ typedef struct {
unsigned char data[REC_LEN];
} rec_t;
typedef struct {
uint64_t num;
float diff;
} match_t;
extern int db_open(db_t *db, const char *path);
extern int db_close(db_t *db);

Loading…
Cancel
Save