changeset 455:93ce12fe2f76 api-inversion

Begin pushing adb_t *adb into index_query_loop and query_loop_points
author mas01cr
date Wed, 24 Dec 2008 10:57:23 +0000
parents f3b0ddc1ead0
children 0ef029232213
files audioDB.h audioDB_API.h index.cpp query.cpp
diffstat 4 files changed, 28 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.h	Wed Dec 24 10:57:18 2008 +0000
+++ b/audioDB.h	Wed Dec 24 10:57:23 2008 +0000
@@ -325,7 +325,7 @@
 
   void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
   int query_loop(adb_t *adb, adb_query_spec_t *spec);
-  void query_loop_points(adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers);
+  void query_loop_points(adb_t *adb, adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers);
   void initRNG();
   void initDBHeader(const char *dbName);
   void initInputFile(const char *inFile);
@@ -386,7 +386,7 @@
   Uns32T index_insert_shingles(vector<vector<float> >*, Uns32T trackID, double* spp);
   void index_make_shingle(vector<vector<float> >*, Uns32T idx, double* fvp, Uns32T dim, Uns32T seqLen);
   int index_norm_shingles(vector<vector<float> >*, double* snp, double* spp);
-  int index_query_loop(adb_query_spec_t *spec, const char* dbName, Uns32T queryIndex);
+  int index_query_loop(adb_t *adb, adb_query_spec_t *spec);
   vector<vector<float> >* index_initialize_shingles(Uns32T sz);
   int index_init_query(const char* dbName);
   int index_exists(const char* dbName, double radius, Uns32T sequenceLength);
--- a/audioDB_API.h	Wed Dec 24 10:57:18 2008 +0000
+++ b/audioDB_API.h	Wed Dec 24 10:57:23 2008 +0000
@@ -187,7 +187,7 @@
 
 /* query function */
 int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqres);
-int audiodb_query_csr(adb_t *, adb_query_spec_t *, adb_query_results_t *);
+int audiodb_query_spec(adb_t *, adb_query_spec_t *, adb_query_results_t *);
 
 /* database status */  
 int audiodb_status(adb_ptr mydb, adb_status_ptr status);
--- a/index.cpp	Wed Dec 24 10:57:18 2008 +0000
+++ b/index.cpp	Wed Dec 24 10:57:23 2008 +0000
@@ -576,7 +576,7 @@
 
 // return 0: if index does not exist
 // return nqv: if index exists
-int audioDB::index_query_loop(adb_query_spec_t *spec, const char* dbName, Uns32T queryIndex) {
+int audioDB::index_query_loop(adb_t *adb, adb_query_spec_t *spec) {
   
   double *query = 0, *query_data = 0;
   adb_qpointers_internal_t qpointers = {0};
@@ -594,10 +594,10 @@
   else
     add_point_func = &index_add_point_approximate;  
 
-  if(!index_init_query(dbName)) // sets-up LSH index structures for querying
+  if(!index_init_query(adb->path)) // sets-up LSH index structures for querying
     return 0;
 
-  char* database = index_get_name(dbName, radius, sequenceLength);
+  char* database = index_get_name(adb->path, radius, sequenceLength);
 
   if(audiodb_query_spec_qpointers(adb, spec, &query_data, &query, &qpointers)) {
     error("failed to set up qpointers");
@@ -635,7 +635,7 @@
 
   if(lsh_exact)
     // Perform exact distance computation on point pairs in exact_evaluation_queue
-    query_loop_points(spec, query, &qpointers);
+    query_loop_points(adb, spec, query, &qpointers);
   
   // Close the index file
   close(lshfid);
--- a/query.cpp	Wed Dec 24 10:57:18 2008 +0000
+++ b/query.cpp	Wed Dec 24 10:57:23 2008 +0000
@@ -222,7 +222,7 @@
   // Test for index (again) here
   if((qspec.refine.flags & ADB_REFINE_RADIUS) && index_exists(adb->path, qspec.refine.radius, qspec.qid.sequence_length)){ 
     VERB_LOG(1, "Calling indexed query on database %s, radius=%f, sequence_length=%d\n", adb->path, qspec.refine.radius, qspec.qid.sequence_length);
-    index_query_loop(&qspec, dbName, query_from_key_index);
+    index_query_loop(adb, &qspec);
   }
   else{
     VERB_LOG(1, "Calling brute-force query on database %s\n", dbName);
@@ -606,31 +606,32 @@
 // Postconditions:
 // reporter contains the points and distances that meet the reporter constraints 
 
-void audioDB::query_loop_points(adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers) {
+void audioDB::query_loop_points(adb_t *adb, adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers) {
   adb_qpointers_internal_t dbpointers = {0};
 
   uint32_t sequence_length = spec->qid.sequence_length;
   bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD);
 
-  // check pre-conditions
-  assert(exact_evaluation_queue&&reporter);
-  if(!exact_evaluation_queue->size()) // Exit if no points to evaluate
+  if(exact_evaluation_queue->size() == 0) {
     return;
+  }
 
-  // Compute database info
-  // FIXME: we more than likely don't need very much of the database
-  // so make a new method to build these values per-track or, even better, per-point
-  if( !( dbH->flags & O2_FLAG_LARGE_ADB) )
+  // Compute database info.  FIXME: we more than likely don't need
+  // very much of the database so write a new function to build these
+  // values per-track or, even better, per-point
+  if(!(adb->header->flags & O2_FLAG_LARGE_ADB)) {
     if(audiodb_set_up_dbpointers(adb, spec, &dbpointers)) {
-      error("failed to set up db");
+      error("failed to set up dbpointers");
     }
+  }
 
   // We are guaranteed that the order of points is sorted by:
-  // trackID, spos, qpos
-  // so we can be relatively efficient in initialization of track data.
-  // Here we assume that points don't overlap, so we will use exhaustive dot
-  // product evaluation instead of memoization of partial sums which is used
-  // for exhaustive brute-force evaluation from smaller databases: e.g. query_loop()
+  // {trackID, spos, qpos} so we can be relatively efficient in
+  // initialization of track data.  We assume that points usually
+  // don't overlap, so we will use exhaustive dot product evaluation
+  // instead of memoization of partial sums which is used for
+  // exhaustive brute-force evaluation from smaller databases in
+  // query_loop()
   double dist;
   size_t data_buffer_size = 0;
   double *data_buffer = 0;
@@ -641,7 +642,7 @@
   while(npairs--){
     PointPair pp = exact_evaluation_queue->top();
     // Large ADB track data must be loaded here for sPower
-    if(dbH->flags & O2_FLAG_LARGE_ADB){
+    if(adb->header->flags & O2_FLAG_LARGE_ADB) {
       trackOffset=0;
       trackIndexOffset=0;
       if(currentTrack!=pp.trackID){
@@ -669,7 +670,7 @@
     else{
       // These offsets are w.r.t. the entire database of feature vectors and auxillary variables
       trackOffset = (*adb->track_offsets)[pp.trackID];
-      trackIndexOffset = trackOffset/(dbH->dim * sizeof(double)); // num vectors offset
+      trackIndexOffset = trackOffset/(adb->header->dim * sizeof(double)); // num vectors offset
     }    
     Uns32T qPos = usingQueryPoint?0:pp.qpos;// index for query point
     Uns32T sPos = trackIndexOffset+pp.spos; // index into l2norm table
@@ -677,15 +678,15 @@
     if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) &&
 	( qPos<qpointers->nvectors-sequence_length+1 && pp.spos<(*adb->track_lengths)[pp.trackID]-sequence_length+1 ) ){
       // Non-large ADB track data is loaded inside power test for efficiency
-      if( !(dbH->flags & O2_FLAG_LARGE_ADB) && (currentTrack!=pp.trackID) ){
+      if(!(adb->header->flags & O2_FLAG_LARGE_ADB) && (currentTrack!=pp.trackID) ){
 	// On currentTrack change, allocate and load track data
 	currentTrack=pp.trackID;
-	lseek(dbfid, dbH->dataOffset + trackOffset, SEEK_SET);
+	lseek(dbfid, adb->header->dataOffset + trackOffset, SEEK_SET);
 	if(audiodb_read_data(adb, dbfid, currentTrack, &data_buffer, &data_buffer_size))
           error("failed to read data");
       }
       // Compute distance
-      dist = audiodb_dot_product(query+qPos*dbH->dim, data_buffer+pp.spos*dbH->dim, dbH->dim*sequence_length);
+      dist = audiodb_dot_product(query + qPos*adb->header->dim, data_buffer + pp.spos*adb->header->dim, adb->header->dim*sequence_length);
       double qn = qpointers->l2norm[qPos];
       double sn = dbpointers.l2norm[sPos];
       switch(spec->params.distance) {