Mercurial > hg > audiodb
changeset 432:62a0515f59be api-inversion
Include track_lengths data structure in struct adb.
Remove mapping of trackTable where I can...
author | mas01cr |
---|---|
date | Wed, 24 Dec 2008 10:55:44 +0000 |
parents | 8632cd387e24 |
children | 681837f7c903 |
files | audioDB-internals.h close.cpp dump.cpp insert.cpp open.cpp status.cpp |
diffstat | 6 files changed, 44 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/audioDB-internals.h Wed Dec 24 10:55:40 2008 +0000 +++ b/audioDB-internals.h Wed Dec 24 10:55:44 2008 +0000 @@ -13,6 +13,7 @@ int flags; adb_header_t *header; std::map<std::string,uint32_t> *keys; + std::vector<uint32_t> *track_lengths; }; typedef struct {
--- a/close.cpp Wed Dec 24 10:55:40 2008 +0000 +++ b/close.cpp Wed Dec 24 10:55:44 2008 +0000 @@ -8,6 +8,7 @@ free(adb->path); free(adb->header); delete adb->keys; + delete adb->track_lengths; close(adb->fd); free(adb); }
--- a/dump.cpp Wed Dec 24 10:55:40 2008 +0000 +++ b/dump.cpp Wed Dec 24 10:55:44 2008 +0000 @@ -6,12 +6,10 @@ int audiodb_dump(adb_t *adb, const char *output) { char *fileTable = 0; /* key_table */ - unsigned *trackTable = 0; /* track_size_table */ double *timesTable = 0; /* timestamps_table */ double *powerTable = 0; /* power_table */ size_t fileTableLength = 0; - size_t trackTableLength = 0; size_t timesTableLength = 0; size_t powerTableLength = 0; @@ -39,7 +37,6 @@ if(adb->header->length > 0) { fileTableLength = ALIGN_PAGE_UP(nfiles * O2_FILETABLE_ENTRY_SIZE); - trackTableLength = ALIGN_PAGE_UP(nfiles * O2_TRACKTABLE_ENTRY_SIZE); if(!(adb->header->flags & O2_FLAG_LARGE_ADB)) { off_t length = adb->header->length; unsigned dim = adb->header->dim; @@ -48,7 +45,6 @@ } mmap_or_goto_error(char *, fileTable, adb->header->fileTableOffset, fileTableLength); - mmap_or_goto_error(unsigned *, trackTable, adb->header->trackTableOffset, trackTableLength); if (adb->header->flags & O2_FLAG_LARGE_ADB) { mmap_or_goto_error(char *, featureFileNameTable, adb->header->dataOffset, fileTableLength); mmap_or_goto_error(char *, powerFileNameTable, adb->header->powerTableOffset, fileTableLength); @@ -139,7 +135,7 @@ /* FIXME: this repeated malloc()/free() of data buffers is inefficient. */ - data_buffer_size = trackTable[k] * adb->header->dim * sizeof(double); + data_buffer_size = (*adb->track_lengths)[k] * adb->header->dim * sizeof(double); { void *tmp = malloc(data_buffer_size); @@ -164,7 +160,7 @@ if (times) { snprintf(fName, 256, "%05d.times", k); tFile = fopen(fName, "w"); - for(unsigned i = 0; i < trackTable[k]; i++) { + for(unsigned i = 0; i < (*adb->track_lengths)[k]; i++) { // KLUDGE: specifying 16 digits of precision after the decimal // point is (but check this!) sufficient to uniquely identify // doubles; however, that will cause ugliness, as that's @@ -173,7 +169,7 @@ // -- CSR, 2007-10-19 fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*i)); } - fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*trackTable[k]-1)); + fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*(*adb->track_lengths)[k]-1)); fclose(tFile); fprintf(tLFile, "%s\n", fName); @@ -186,14 +182,14 @@ goto error; } write_or_goto_error(pfd, &one, sizeof(uint32_t)); - write_or_goto_error(pfd, powerTable + pos, trackTable[k] * sizeof(double)); + write_or_goto_error(pfd, powerTable + pos, (*adb->track_lengths)[k] * sizeof(double)); fprintf(pLFile, "%s\n", fName); close(pfd); pfd = 0; } - pos += trackTable[k]; - std::cout << fileTable+k*O2_FILETABLE_ENTRY_SIZE << " " << trackTable[k] << std::endl; + pos += (*adb->track_lengths)[k]; + std::cout << fileTable+k*O2_FILETABLE_ENTRY_SIZE << " " << (*adb->track_lengths)[k] << std::endl; } } @@ -237,7 +233,6 @@ fclose(kLFile); maybe_munmap(fileTable, fileTableLength); - maybe_munmap(trackTable, trackTableLength); maybe_munmap(timesTable, timesTableLength); maybe_munmap(powerTable, powerTableLength); maybe_munmap(featureFileNameTable, fileTableLength); @@ -278,7 +273,6 @@ } maybe_munmap(fileTable, fileTableLength); - maybe_munmap(trackTable, trackTableLength); maybe_munmap(timesTable, timesTableLength); maybe_munmap(powerTable, powerTableLength); maybe_munmap(featureFileNameTable, fileTableLength);
--- a/insert.cpp Wed Dec 24 10:55:40 2008 +0000 +++ b/insert.cpp Wed Dec 24 10:55:44 2008 +0000 @@ -64,7 +64,7 @@ * and key tables too; * 7. if O2_FLAG_L2NORM and !O2_FLAG_LARGE_ADB, compute norms and fill * in table; - * 8. update adb->keys and adb->header; + * 8. update adb->keys, adb->track_lengths and adb->header; * 9. sync adb->header with disk. * * Step 9 essentially commits the transaction; until we update @@ -194,8 +194,9 @@ l2norm_buffer = NULL; } - /* 8. update adb->keys and adb->header; */ + /* 8. update adb->keys, adb->track_lengths and adb->header; */ (*adb->keys)[datum->key] = adb->header->numFiles; + adb->track_lengths->push_back(datum->nvectors); adb->header->numFiles += 1; adb->header->length += sizeof(double) * datum->nvectors * datum->dim;
--- a/open.cpp Wed Dec 24 10:55:40 2008 +0000 +++ b/open.cpp Wed Dec 24 10:55:44 2008 +0000 @@ -43,6 +43,26 @@ return 1; } +static int audiodb_collect_track_lengths(adb_t *adb) { + uint32_t *track_table = 0; + size_t track_table_length = 0; + if(adb->header->length > 0) { + 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); + for (unsigned int k = 0; k < nfiles; k++) { + adb->track_lengths->push_back(track_table[k]); + } + munmap(track_table, track_table_length); + } + + return 0; + + error: + maybe_munmap(track_table, track_table_length); + return 1; +} + adb_t *audiodb_open(const char *path, int flags) { adb_t *adb = 0; int fd = -1; @@ -86,6 +106,14 @@ if(audiodb_collect_keys(adb)) { goto error; } + adb->track_lengths = new std::vector<uint32_t>; + if(!adb->track_lengths) { + goto error; + } + adb->track_lengths->reserve(adb->header->numFiles); + if(audiodb_collect_track_lengths(adb)) { + goto error; + } return adb; error: @@ -99,6 +127,9 @@ if(adb->keys) { delete adb->keys; } + if(adb->track_lengths) { + delete adb->track_lengths; + } free(adb); } if(fd != -1) {
--- a/status.cpp Wed Dec 24 10:55:40 2008 +0000 +++ b/status.cpp Wed Dec 24 10:55:44 2008 +0000 @@ -12,17 +12,6 @@ unsigned dudCount = 0; unsigned nullCount = 0; - size_t trackTableLength = ALIGN_PAGE_UP(adb->header->numFiles * O2_TRACKTABLE_ENTRY_SIZE); - unsigned *trackTable = 0; - void *tmp = 0; - if (adb->header->length > 0) { - tmp = mmap(0, trackTableLength, PROT_READ, MAP_SHARED, adb->fd, adb->header->trackTableOffset); - if (tmp == (void *) -1) { - return 1; - } - trackTable = (unsigned *) tmp; - } - for(unsigned k = 0; k < adb->header->numFiles; k++) { /* FIXME: this bare "16" here reveals a problem (or maybe two). * 16 here means the default value of the sequenceLength parameter @@ -38,20 +27,14 @@ * information, but at present it's probably completely unused, so * the compromise for now is to hardwire the 16. */ - if(trackTable[k] < 16) { + if((*adb->track_lengths)[k] < 16) { dudCount++; - if(!trackTable[k]) { + if(!(*adb->track_lengths)[k]) { nullCount++; } } } - if(adb->header->length > 0) { - if(munmap(trackTable, trackTableLength)) { - return 1; - } - } - status->numFiles = adb->header->numFiles; status->dim = adb->header->dim; status->length = adb->header->length;