comparison audioDB.h @ 405:ef4792df8f93 api-inversion

invert audioDB::insert / audiodb_insert(). Start off by removing audioDB::insertDatum, and essentially reusing it as audiodb_insert. We now ignore the fact that the command-line parsing code has "helpfully" opened a std::ifstream for the times file and an fd for the power file, and simply go ahead and do our own dirty work. We can delete audioDB::insertDatum entirely, but unfortunately we can't delete audioDB::insertPowerData and audioDB::insertTimestamps, because the index and query code respectively use them. Instead, move the two methods closer to their single uses. audiodb_insert() is perhaps not as short and simple as it might have been hoped given the existence of audiodb_insert_datum(); some of that is C and its terribly way of making you pay every time you use dynamic memory; some of it is the fact that the three different files (feature, times, power) each requires slightly different treatment. Hey ho. We can implement audiodb_batchinsert() in terms of audiodb_insert(); the function is pleasingly small. We can't quite use it for audioDB::batchinsert yet, as we have to deal with the O2_FLAG_LARGE_ADB case (which codepath is untested in libtests/). This means that we can delete whole swathes of hideous code from audioDB.cpp, including not just the versions of audiodb_insert() and audiodb_batchinsert() but also an entire audioDB constructor. Yay. (audioDB::unitNormAndInsertL2 has also died a deserved death).
author mas01cr
date Fri, 05 Dec 2008 22:32:49 +0000
parents 1fb8bee777e5
children 99e6cbad7f76
comparison
equal deleted inserted replaced
404:1fb8bee777e5 405:ef4792df8f93
322 322
323 323
324 void initialize_arrays(int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD); 324 void initialize_arrays(int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD);
325 void delete_arrays(int track, unsigned int numVectors, double **D, double **DD); 325 void delete_arrays(int track, unsigned int numVectors, double **D, double **DD);
326 void read_data(int trkfid, int track, double **data_buffer_p, size_t *data_buffer_size_p); 326 void read_data(int trkfid, int track, double **data_buffer_p, size_t *data_buffer_size_p);
327 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
327 void set_up_query(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned int *nvp); 328 void set_up_query(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned int *nvp);
328 void set_up_query_from_key(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned *nvp, Uns32T queryIndex); 329 void set_up_query_from_key(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned *nvp, Uns32T queryIndex);
329 void set_up_db(double **snp, double **vsnp, double **spp, double **vspp, double **mddp, unsigned int *dvp); 330 void set_up_db(double **snp, double **vsnp, double **spp, double **vspp, double **mddp, unsigned int *dvp);
330 void query_loop(const char* dbName, Uns32T queryIndex); 331 void query_loop(const char* dbName, Uns32T queryIndex);
331 void query_loop_points(double* query, double* qnPtr, double* qpPtr, double meanQdur, Uns32T numVectors); 332 void query_loop_points(double* query, double* qnPtr, double* qpPtr, double meanQdur, Uns32T numVectors);
335 void initInputFile(const char *inFile, bool loadData = true); 336 void initInputFile(const char *inFile, bool loadData = true);
336 void initTables(const char* dbName, const char* inFile = 0); 337 void initTables(const char* dbName, const char* inFile = 0);
337 void initTablesFromKey(const char* dbName, const Uns32T queryIndex); 338 void initTablesFromKey(const char* dbName, const Uns32T queryIndex);
338 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm); 339 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm);
339 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n); 340 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n);
340 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
341 void insertPowerData(unsigned n, int powerfd, double *powerdata);
342 unsigned getKeyPos(char* key); 341 unsigned getKeyPos(char* key);
343 void prefix_name(char** const name, const char* prefix); 342 void prefix_name(char** const name, const char* prefix);
344 343
345 public: 344 public:
346 audioDB(const unsigned argc, const char *argv[]); 345 audioDB(const unsigned argc, const char *argv[]);
347 audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse); 346 audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse);
348 audioDB(const unsigned argc, const char *argv[], adb__statusResponse *adbStatusResponse); 347 audioDB(const unsigned argc, const char *argv[], adb__statusResponse *adbStatusResponse);
349 audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse); 348 audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse);
350 audioDB(const unsigned argc, const char *argv[], int * apierror, struct adb *a);
351 audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror, struct adb *a); 349 audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror, struct adb *a);
352 350
353 351
354 void cleanup(); 352 void cleanup();
355 ~audioDB(); 353 ~audioDB();
357 void get_lock(int fd, bool exclusive); 355 void get_lock(int fd, bool exclusive);
358 void release_lock(int fd); 356 void release_lock(int fd);
359 void create(const char* dbName); 357 void create(const char* dbName);
360 bool enough_per_file_space_free(); 358 bool enough_per_file_space_free();
361 void insert(const char* dbName, const char* inFile); 359 void insert(const char* dbName, const char* inFile);
362 void insertDatum(const char *inFile, std::ifstream *timesFile, int powerfd, const char *key);
363 void batchinsert(const char* dbName, const char* inFile); 360 void batchinsert(const char* dbName, const char* inFile);
364 void batchinsert_large_adb(const char* dbName, const char* inFile); 361 void batchinsert_large_adb(const char* dbName, const char* inFile);
365 void query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0); 362 void query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0);
366 void status(const char* dbName, adb__statusResponse *adbStatusResponse=0); 363 void status(const char* dbName, adb__statusResponse *adbStatusResponse=0);
367 364
411 static Uns32T index_to_trackPos(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackPos (spos) 408 static Uns32T index_to_trackPos(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackPos (spos)
412 static Uns32T index_from_trackInfo(Uns32T trackID, Uns32T pntID, Uns32T nPntBits); // Convert audioDB trackID and trackPos to an lsh point index 409 static Uns32T index_from_trackInfo(Uns32T trackID, Uns32T pntID, Uns32T nPntBits); // Convert audioDB trackID and trackPos to an lsh point index
413 void initialize_exact_evalutation_queue(); 410 void initialize_exact_evalutation_queue();
414 void index_insert_exact_evaluation_queue(Uns32T trackID, Uns32T qpos, Uns32T spos); 411 void index_insert_exact_evaluation_queue(Uns32T trackID, Uns32T qpos, Uns32T spos);
415 LSH* index_allocate(char* indexName, bool load_hashTables); 412 LSH* index_allocate(char* indexName, bool load_hashTables);
413 void insertPowerData(unsigned n, int powerfd, double *powerdata);
416 void init_track_aux_data(Uns32T trackID, double* fvp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp); 414 void init_track_aux_data(Uns32T trackID, double* fvp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp);
417 415
418 // Web Services 416 // Web Services
419 void startServer(); 417 void startServer();
420 418