Mercurial > hg > audiodb
changeset 442:16c5c51a4c32 api-inversion
Add more information to adb_t
In this case, add a vector to store track offsets.
WARNING WARNING WARNING: unlike trackOffsetTable, this is a raw off_t in
bytes of the feature data: in other words, it already has sizeof(double)
and dbH->dim in it. (I think this is probably minimally unsurprising in
the long run, but as I convert stuff there might well be errors creeping
in...)
author | mas01cr |
---|---|
date | Wed, 24 Dec 2008 10:56:29 +0000 |
parents | 1a1ea05a94ce |
children | cb44e57a96fa |
files | audioDB-internals.h close.cpp insert.cpp open.cpp |
diffstat | 4 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/audioDB-internals.h Wed Dec 24 10:56:25 2008 +0000 +++ b/audioDB-internals.h Wed Dec 24 10:56:29 2008 +0000 @@ -14,6 +14,7 @@ adb_header_t *header; std::map<std::string,uint32_t> *keys; std::vector<uint32_t> *track_lengths; + std::vector<off_t> *track_offsets; }; typedef struct {
--- a/close.cpp Wed Dec 24 10:56:25 2008 +0000 +++ b/close.cpp Wed Dec 24 10:56:29 2008 +0000 @@ -9,6 +9,7 @@ free(adb->header); delete adb->keys; delete adb->track_lengths; + delete adb->track_offsets; close(adb->fd); free(adb); }
--- a/insert.cpp Wed Dec 24 10:56:25 2008 +0000 +++ b/insert.cpp Wed Dec 24 10:56:29 2008 +0000 @@ -64,7 +64,8 @@ * and key tables too; * 7. if O2_FLAG_L2NORM and !O2_FLAG_LARGE_ADB, compute norms and fill * in table; - * 8. update adb->keys, adb->track_lengths and adb->header; + * 8. update adb->keys, adb->track_lengths, adb->track_offsets and + * adb->header; * 9. sync adb->header with disk. * * Step 9 essentially commits the transaction; until we update @@ -194,9 +195,14 @@ l2norm_buffer = NULL; } - /* 8. update adb->keys, adb->track_lengths and adb->header; */ + /* 8. update adb->keys, adb->track_lengths, adb->track_offsets and + * adb->header; + */ (*adb->keys)[datum->key] = adb->header->numFiles; adb->track_lengths->push_back(datum->nvectors); + if(adb->header->numFiles > 0) { + adb->track_offsets->push_back(offset); + } adb->header->numFiles += 1; adb->header->length += sizeof(double) * datum->nvectors * datum->dim;
--- a/open.cpp Wed Dec 24 10:56:25 2008 +0000 +++ b/open.cpp Wed Dec 24 10:56:29 2008 +0000 @@ -50,8 +50,12 @@ unsigned nfiles = adb->header->numFiles; track_table_length = ALIGN_PAGE_UP(nfiles * O2_TRACKTABLE_ENTRY_SIZE); mmap_or_goto_error(uint32_t *, track_table, adb->header->trackTableOffset, track_table_length); + off_t offset = 0; for (unsigned int k = 0; k < nfiles; k++) { - adb->track_lengths->push_back(track_table[k]); + uint32_t track_length = track_table[k]; + adb->track_lengths->push_back(track_length); + adb->track_offsets->push_back(offset); + offset += track_length * adb->header->dim * sizeof(double); } munmap(track_table, track_table_length); } @@ -111,6 +115,11 @@ goto error; } adb->track_lengths->reserve(adb->header->numFiles); + adb->track_offsets = new std::vector<off_t>; + if(!adb->track_offsets) { + goto error; + } + adb->track_offsets->reserve(adb->header->numFiles); if(audiodb_collect_track_lengths(adb)) { goto error; }