# HG changeset patch # User mas01cr # Date 1230116189 0 # Node ID 16c5c51a4c32460c4d455aee96df24ab97881398 # Parent 1a1ea05a94cef400af4b3cc6dfb5f8d80ee5faaf 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...) diff -r 1a1ea05a94ce -r 16c5c51a4c32 audioDB-internals.h --- 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 *keys; std::vector *track_lengths; + std::vector *track_offsets; }; typedef struct { diff -r 1a1ea05a94ce -r 16c5c51a4c32 close.cpp --- 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); } diff -r 1a1ea05a94ce -r 16c5c51a4c32 insert.cpp --- 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; diff -r 1a1ea05a94ce -r 16c5c51a4c32 open.cpp --- 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; + if(!adb->track_offsets) { + goto error; + } + adb->track_offsets->reserve(adb->header->numFiles); if(audiodb_collect_track_lengths(adb)) { goto error; }