Mercurial > hg > audiodb
diff query.cpp @ 463:35bb388d0eac api-inversion
audioDB::query_loop and audioDB::query_loop_points are no more.
Be a little bit careful about deleting the exact_evaluation_queue in
error conditions, but otherwise this was simple (If you ignore the work
of the previous $N$ commits, that is). The inversion work in query.cpp
is now complete, apart from physically teasing apart the API function
from the body of audioDB::query and then moving the two remaining
audioDB:: methods elsewhere. Unfortunately, we're still not quite done,
because we have to deal with audioDB::index_query_loop too, which is
still a little bit tangled. Still, we're nearly there...
author | mas01cr |
---|---|
date | Tue, 30 Dec 2008 15:38:59 +0000 |
parents | f689510baaf4 |
children | 1030664df98c |
line wrap: on
line diff
--- a/query.cpp Tue Dec 30 15:38:55 2008 +0000 +++ b/query.cpp Tue Dec 30 15:38:59 2008 +0000 @@ -240,10 +240,10 @@ 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(adb, &qspec, &qstate); } - else{ + else { VERB_LOG(1, "Calling brute-force query on database %s\n", dbName); - if(query_loop(adb, &qspec, &qstate)) { - error("query_loop failed"); + if(audiodb_query_loop(adb, &qspec, &qstate)) { + error("audiodb_query_loop failed"); } } @@ -628,35 +628,22 @@ } -// query_points() -// -// using PointPairs held in the exact_evaluation_queue compute squared distance for each PointPair -// and insert result into the current reporter. -// -// Preconditions: -// A query inFile has been opened with setup_query(...) and query pointers initialized -// The database contains some points -// An exact_evaluation_queue has been allocated and populated -// A reporter has been allocated -// -// Postconditions: -// reporter contains the points and distances that meet the reporter constraints - -void audioDB::query_loop_points(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate, double *query, adb_qpointers_internal_t *qpointers) { +int audiodb_query_queue_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate, 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); if(qstate->exact_evaluation_queue->size() == 0) { - return; + return 0; } /* 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. We assume that points usually * don't overlap, so we will use exhaustive dot product evaluation - * (instead of memoization of partial sums, as in query_loop()). */ + * (instead of memoization of partial sums, as in query_loop()). + */ double dist; double *dbdata = 0, *dbdata_pointer; Uns32T currentTrack = 0x80000000; // KLUDGE: Initialize with a value outside of track index range @@ -671,15 +658,17 @@ currentTrack = pp.trackID; adb_datum_t d = {0}; if(audiodb_track_id_datum(adb, pp.trackID, &d)) { - error("failed to get datum"); + delete qstate->exact_evaluation_queue; + return 1; } if(audiodb_datum_qpointers(&d, sequence_length, &dbdata, &dbdata_pointer, &dbpointers)) { + delete qstate->exact_evaluation_queue; audiodb_free_datum(&d); - error("failed to get dbpointers"); + return 1; } audiodb_free_datum(&d); } - Uns32T qPos = usingQueryPoint?0:pp.qpos;// index for query point + Uns32T qPos = (spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) ? pp.qpos : 0; Uns32T sPos = pp.spos; // index into l2norm table // Test power thresholds before computing distance if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) && @@ -696,7 +685,8 @@ dist = qn*qn + sn*sn - 2*dist; break; } - if((!radius) || dist <= (O2_LSH_EXACT_MULT*radius+O2_DISTANCE_TOLERANCE)) { + if((!(spec->refine.flags & ADB_REFINE_RADIUS)) || + dist <= (spec->refine.radius+O2_DISTANCE_TOLERANCE)) { adb_result_t r; r.key = (*adb->keys)[pp.trackID].c_str(); r.dist = dist; @@ -713,9 +703,10 @@ SAFE_DELETE_ARRAY(dbpointers.power_data); SAFE_DELETE_ARRAY(dbpointers.mean_duration); delete qstate->exact_evaluation_queue; + return 0; } -int audioDB::query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { +int audiodb_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { double *query, *query_data; adb_qpointers_internal_t qpointers = {0}, dbpointers = {0};