Mercurial > hg > audiodb
comparison audioDB.cpp @ 181:c22d53219112 no-big-mmap
inserting the data vectors goes through lseek()/write()
author | mas01cr |
---|---|
date | Thu, 15 Nov 2007 17:04:55 +0000 |
parents | d434e771c776 |
children | a6853791a275 |
comparison
equal
deleted
inserted
replaced
180:d434e771c776 | 181:c22d53219112 |
---|---|
544 | 544 |
545 bool audioDB::enough_data_space_free(off_t size) { | 545 bool audioDB::enough_data_space_free(off_t size) { |
546 return(dbH->timesTableOffset > dbH->dataOffset + dbH->length + size); | 546 return(dbH->timesTableOffset > dbH->dataOffset + dbH->length + size); |
547 } | 547 } |
548 | 548 |
549 void audioDB::insert_data_vectors(off_t offset, void *buffer, size_t size) { | |
550 lseek(dbfid, dbH->dataOffset + offset, SEEK_SET); | |
551 write(dbfid, buffer, size); | |
552 } | |
553 | |
549 void audioDB::insert(const char* dbName, const char* inFile) { | 554 void audioDB::insert(const char* dbName, const char* inFile) { |
550 forWrite = true; | 555 forWrite = true; |
551 initTables(dbName, inFile); | 556 initTables(dbName, inFile); |
552 | 557 |
553 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) | 558 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) |
604 dbH->length+=(statbuf.st_size-sizeof(int)); | 609 dbH->length+=(statbuf.st_size-sizeof(int)); |
605 | 610 |
606 // Update track to file index map | 611 // Update track to file index map |
607 memcpy (trackTable+dbH->numFiles-1, &numVectors, sizeof(unsigned)); | 612 memcpy (trackTable+dbH->numFiles-1, &numVectors, sizeof(unsigned)); |
608 | 613 |
609 // Update the feature database | 614 insert_data_vectors(insertoffset, indata + sizeof(int), statbuf.st_size - sizeof(int)); |
610 memcpy (((char *) dataBuf) + insertoffset, indata+sizeof(int), statbuf.st_size-sizeof(int)); | |
611 | 615 |
612 // Norm the vectors on input if the database is already L2 normed | 616 // Norm the vectors on input if the database is already L2 normed |
613 if(dbH->flags & O2_FLAG_L2NORM) | 617 if(dbH->flags & O2_FLAG_L2NORM) |
614 unitNormAndInsertL2((double*)(((char *) dataBuf) + insertoffset), dbH->dim, numVectors, 1); // append | 618 unitNormAndInsertL2((double*)(((char *) dataBuf) + insertoffset), dbH->dim, numVectors, 1); // append |
615 | 619 |
774 dbH->length+=(statbuf.st_size-sizeof(int)); | 778 dbH->length+=(statbuf.st_size-sizeof(int)); |
775 | 779 |
776 // Update track to file index map | 780 // Update track to file index map |
777 memcpy (trackTable+dbH->numFiles-1, &numVectors, sizeof(unsigned)); | 781 memcpy (trackTable+dbH->numFiles-1, &numVectors, sizeof(unsigned)); |
778 | 782 |
779 // Update the feature database | 783 insert_data_vectors(insertoffset, indata + sizeof(int), statbuf.st_size - sizeof(int)); |
784 | |
780 memcpy (((char *) dataBuf) + insertoffset, indata+sizeof(int), statbuf.st_size-sizeof(int)); | 785 memcpy (((char *) dataBuf) + insertoffset, indata+sizeof(int), statbuf.st_size-sizeof(int)); |
781 | 786 |
782 // Norm the vectors on input if the database is already L2 normed | 787 // Norm the vectors on input if the database is already L2 normed |
783 if(dbH->flags & O2_FLAG_L2NORM) | 788 if(dbH->flags & O2_FLAG_L2NORM) |
784 unitNormAndInsertL2((double*)(((char *) dataBuf) + insertoffset), dbH->dim, numVectors, 1); // append | 789 unitNormAndInsertL2((double*)(((char *) dataBuf) + insertoffset), dbH->dim, numVectors, 1); // append |