From e8a35c273d18faef1c6fee5bb984a02273377408 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Wed, 13 May 2015 17:56:33 +1000 Subject: [PATCH] * imdb_usage_slice() --- src/database.c | 25 +++++++++++++++++++++++++ src/database.h | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/database.c b/src/database.c index 6a8e026..2d14fc8 100644 --- a/src/database.c +++ b/src/database.c @@ -323,3 +323,28 @@ imdb_usage_map(imdb_db_t * const db, return records; } + +uint16_t +imdb_usage_slice(imdb_db_t * const db, + char ** const map, + uint64_t offset, + uint16_t limit) { + imdb_block_t blk; + unsigned char *r; /* mnemonics : block, record */ + char *m = NULL; /* mnemonics : map */ + + memset(&blk, 0x0, sizeof(imdb_block_t)); + CALLOC(*map, limit + 1, sizeof(char)); + + m = *map; + blk.start = offset; + blk.records = limit; + + limit = imdb_read_blk(db, &blk); + r = blk.data; + for (uint16_t i = 0; i < blk.records; i++, m++, r += IMDB_REC_LEN) { + *m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE; + } + + return limit; +} diff --git a/src/database.h b/src/database.h index 4e80774..0380c30 100644 --- a/src/database.h +++ b/src/database.h @@ -130,4 +130,17 @@ imdb_records_count(imdb_db_t * const db); uint64_t imdb_usage_map(imdb_db_t * const db, char ** const map); + +/** + @brief fills buffer 'map' according to records existense in given range + @param offset start of slice position + @param limit slice size + @returns records processed (and also buffer size) +*/ +uint16_t +imdb_usage_slice(imdb_db_t * const db, + char ** const map, + uint64_t offset, + uint16_t limit); + #endif