Browse Source

* rename simdb_{read,write}_{rec,blk} to simdb_{record,block}_{read,write}

master
Alex 'AdUser' Z 8 years ago
parent
commit
e29176e883
  1. 14
      src/database.c
  2. 6
      src/database.h
  3. 6
      src/simdb-query.c
  4. 4
      src/simdb-write.c
  5. 10
      tests/database.c

14
src/database.c

@ -165,7 +165,7 @@ simdb_error(int error) {
return "unknown error";
}
int simdb_read_rec(simdb_t *db, simdb_rec_t *rec) {
int simdb_record_read(simdb_t *db, simdb_rec_t *rec) {
ssize_t bytes = 0;
assert(db != NULL);
@ -183,7 +183,7 @@ int simdb_read_rec(simdb_t *db, simdb_rec_t *rec) {
return 1;
}
int simdb_write_rec(simdb_t *db, simdb_rec_t *rec) {
int simdb_record_write(simdb_t *db, simdb_rec_t *rec) {
ssize_t bytes = 0;
assert(db != NULL);
@ -201,7 +201,7 @@ int simdb_write_rec(simdb_t *db, simdb_rec_t *rec) {
return 1;
}
int simdb_read_blk(simdb_t *db, simdb_block_t *blk) {
int simdb_block_read(simdb_t *db, simdb_block_t *blk) {
ssize_t bytes = 0;
assert(db != NULL);
@ -268,7 +268,7 @@ simdb_search(simdb_t * const db,
blk.start = 1;
blk.records = blk_size;
if ((ret = simdb_read_rec(db, sample)) < 1)
if ((ret = simdb_record_read(db, sample)) < 1)
return ret;
if (search->limit == 0)
@ -279,7 +279,7 @@ simdb_search(simdb_t * const db,
CALLOC(*matches, search->limit, sizeof(simdb_match_t));
while (simdb_read_blk(db, &blk) > 0) {
while (simdb_block_read(db, &blk) > 0) {
p = blk.data;
for (i = 0; i < blk.records; i++, p += SIMDB_REC_LEN) {
if (*(p + REC_OFF_RU) == 0x0)
@ -338,7 +338,7 @@ simdb_usage_map(simdb_t * const db,
blk.start = 1;
blk.records = blk_size;
while (simdb_read_blk(db, &blk) > 0) {
while (simdb_block_read(db, &blk) > 0) {
r = blk.data;
for (unsigned int i = 0; i < blk.records; i++, m++, r += SIMDB_REC_LEN) {
*m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE;
@ -366,7 +366,7 @@ simdb_usage_slice(simdb_t * const db,
blk.start = offset;
blk.records = limit;
limit = simdb_read_blk(db, &blk);
limit = simdb_block_read(db, &blk);
r = blk.data;
for (uint16_t i = 0; i < blk.records; i++, m++, r += SIMDB_REC_LEN) {
*m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE;

6
src/database.h

@ -143,7 +143,7 @@ simdb_search(simdb_t * const db,
* @retval 0 if record exists but not used,
* @retval <0 on error (system error or record missing)
*/
int simdb_read_rec (simdb_t *db, simdb_rec_t *rec);
int simdb_record_read(simdb_t *db, simdb_rec_t *rec);
/**
* @brief Write single record to database
* @param db Database handle
@ -152,7 +152,7 @@ int simdb_read_rec (simdb_t *db, simdb_rec_t *rec);
* @retval 1 on success
* @retval <0 on error (system error or record missing)
*/
int simdb_write_rec(simdb_t *db, simdb_rec_t *rec);
int simdb_record_write(simdb_t *db, simdb_rec_t *rec);
/**
* @brief Read continious records block from database
@ -162,7 +162,7 @@ int simdb_write_rec(simdb_t *db, simdb_rec_t *rec);
* @retval >=0 As number of records actually read
* @retval <0 on error
*/
int simdb_read_blk (simdb_t *db, simdb_block_t *blk);
int simdb_block_read(simdb_t *db, simdb_block_t *blk);
/**
* @brief Get database capacity

6
src/simdb-query.c

@ -126,7 +126,7 @@ int rec_bitmap(simdb_t *db, uint64_t number)
memset(&rec, 0x0, sizeof(simdb_rec_t));
rec.num = number;
if (simdb_read_rec(db, &rec) < 1) {
if (simdb_record_read(db, &rec) < 1) {
fprintf(stderr, "bitmap: %s\n", "sample not found");
return 1;
}
@ -148,14 +148,14 @@ int rec_diff(simdb_t *db, uint64_t a, uint64_t b, unsigned short int showmap)
memset(&rec, 0x0, sizeof(simdb_rec_t));
rec.num = a;
if (simdb_read_rec(db, &rec) < 1) {
if (simdb_record_read(db, &rec) < 1) {
fprintf(stderr, "record diff: first sample not exists\n");
return 1;
}
memcpy(one, &rec.data[REC_OFF_BM], BITMAP_SIZE);
rec.num = b;
if (simdb_read_rec(db, &rec) < 1) {
if (simdb_record_read(db, &rec) < 1) {
fprintf(stderr, "record diff: second sample not exists\n");
return 1;
}

4
src/simdb-write.c

@ -86,13 +86,13 @@ int main(int argc, char **argv)
fprintf(stderr, "sampler failure\n");
exit(EXIT_FAILURE);
}
if ((err = simdb_write_rec(db, &rec)) < 1) {
if ((err = simdb_record_write(db, &rec)) < 1) {
fprintf(stderr, "%s\n", simdb_error(err));
exit(EXIT_FAILURE);
}
break;
case del :
if ((err = simdb_write_rec(db, &rec)) < 1) {
if ((err = simdb_record_write(db, &rec)) < 1) {
fprintf(stderr, "%s\n", simdb_error(err));
exit(EXIT_FAILURE);
}

10
tests/database.c

@ -22,13 +22,13 @@ int main() {
assert(db != NULL);
rec[0].num = 1;
err = simdb_read_rec(db, rec);
err = simdb_record_read(db, rec);
assert(err == SIMDB_ERR_NXRECORD);
memset(rec[0].data, 0xAA, SIMDB_REC_LEN);
memset(rec[0].data, 0xFF, 1); /* record is used */
num = simdb_write_rec(db, rec);
num = simdb_record_write(db, rec);
assert(num == SIMDB_ERR_READONLY); /* database open in read-only mode */
simdb_close(db);
@ -37,16 +37,16 @@ int main() {
db = simdb_open(path, mode, &err);
assert(db != NULL);
num = simdb_write_rec(db, rec);
num = simdb_record_write(db, rec);
assert(num == 1); /* success */
num = simdb_read_rec(db, rec);
num = simdb_record_read(db, rec);
assert(num == 1);
blk.start = 1;
blk.records = 2;
blk.data = NULL;
num = simdb_read_blk(db, &blk);
num = simdb_block_read(db, &blk);
assert(num == 1);
assert(blk.records == 1);
assert(blk.data != NULL);

Loading…
Cancel
Save