comparison query.cpp @ 580:633614461994

API for retrieving a track's data. A new function, audiodb_retrieve_datum() fills a provided adb_datum_t structure with the data corresponding to a given database key; the companion audiodb_free_datum() function frees the data in a given datum appropriately. Just in case, I continue to require passing in the adb_t * as the first argument to audiodb_free_datum(), even though it's not currently used: I couldn't convince myself that _all_ possible implementations could free a datum without reference to the adb_t. This meant rewriting the internal code to use a new internal audiodb_really_free_datum() function, which audiodb_free_datum() also calls. Sanity-checked by implementing a binding in sb-alien to this function, lightly-tested. All this fixes ticket:20 in Trac.
author mas01cr
date Tue, 14 Jul 2009 15:35:36 +0000
parents cc2b97d020b1
children 9119f2fa3efe
comparison
equal deleted inserted replaced
579:81053b8bdb51 580:633614461994
238 read_or_goto_error(adb->fd, d->times, 2 * d->nvectors * sizeof(double)); 238 read_or_goto_error(adb->fd, d->times, 2 * d->nvectors * sizeof(double));
239 } 239 }
240 return 0; 240 return 0;
241 } 241 }
242 error: 242 error:
243 audiodb_free_datum(d); 243 audiodb_really_free_datum(d);
244 return 1; 244 return 1;
245 } 245 }
246 246
247 int audiodb_datum_qpointers(adb_datum_t *d, uint32_t sequence_length, double **vector_data, double **vector, adb_qpointers_internal_t *qpointers) { 247 int audiodb_datum_qpointers(adb_datum_t *d, uint32_t sequence_length, double **vector_data, double **vector, adb_qpointers_internal_t *qpointers) {
248 uint32_t nvectors = d->nvectors; 248 uint32_t nvectors = d->nvectors;
308 } 308 }
309 309
310 /* FIXME: check the overflow logic here */ 310 /* FIXME: check the overflow logic here */
311 if(sequence_start + sequence_length > d.nvectors) { 311 if(sequence_start + sequence_length > d.nvectors) {
312 if(datum != &d) { 312 if(datum != &d) {
313 audiodb_free_datum(&d); 313 audiodb_really_free_datum(&d);
314 } 314 }
315 return 1; 315 return 1;
316 } 316 }
317 317
318 audiodb_datum_qpointers(&d, sequence_length, vector_data, vector, qpointers); 318 audiodb_datum_qpointers(&d, sequence_length, vector_data, vector, qpointers);
331 } 331 }
332 332
333 /* Clean up: free any bits of datum that we have ourselves 333 /* Clean up: free any bits of datum that we have ourselves
334 * allocated. */ 334 * allocated. */
335 if(datum != &d) { 335 if(datum != &d) {
336 audiodb_free_datum(&d); 336 audiodb_really_free_datum(&d);
337 } 337 }
338 338
339 return 0; 339 return 0;
340 } 340 }
341 341
462 delete qstate->exact_evaluation_queue; 462 delete qstate->exact_evaluation_queue;
463 return 1; 463 return 1;
464 } 464 }
465 if(audiodb_datum_qpointers(&d, sequence_length, &dbdata, &dbdata_pointer, &dbpointers)) { 465 if(audiodb_datum_qpointers(&d, sequence_length, &dbdata, &dbdata_pointer, &dbpointers)) {
466 delete qstate->exact_evaluation_queue; 466 delete qstate->exact_evaluation_queue;
467 audiodb_free_datum(&d); 467 audiodb_really_free_datum(&d);
468 return 1; 468 return 1;
469 } 469 }
470 audiodb_free_datum(&d); 470 audiodb_really_free_datum(&d);
471 } 471 }
472 Uns32T qPos = (spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) ? pp.qpos : 0; 472 Uns32T qPos = (spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) ? pp.qpos : 0;
473 Uns32T sPos = pp.spos; // index into l2norm table 473 Uns32T sPos = pp.spos; // index into l2norm table
474 // Test power thresholds before computing distance 474 // Test power thresholds before computing distance
475 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) && 475 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) &&