Mercurial > hg > audiodb
comparison query.cpp @ 473:b2fd8113d8bc api-inversion
const declarations for some API arguments.
This should make it slightly clearer whose responsibility (the user's)
it is to manage the memory pointed to by the corresponding arguments.
Suggested by Chris Cannam.
author | mas01cr |
---|---|
date | Tue, 06 Jan 2009 16:27:01 +0000 |
parents | 0f96ad351990 |
children |
comparison
equal
deleted
inserted
replaced
472:0f96ad351990 | 473:b2fd8113d8bc |
---|---|
1 #include "audioDB.h" | 1 #include "audioDB.h" |
2 #include "audioDB-internals.h" | 2 #include "audioDB-internals.h" |
3 #include "accumulators.h" | 3 #include "accumulators.h" |
4 | 4 |
5 bool audiodb_powers_acceptable(adb_query_refine_t *r, double p1, double p2) { | 5 bool audiodb_powers_acceptable(const adb_query_refine_t *r, double p1, double p2) { |
6 if (r->flags & ADB_REFINE_ABSOLUTE_THRESHOLD) { | 6 if (r->flags & ADB_REFINE_ABSOLUTE_THRESHOLD) { |
7 if ((p1 < r->absolute_threshold) || (p2 < r->absolute_threshold)) { | 7 if ((p1 < r->absolute_threshold) || (p2 < r->absolute_threshold)) { |
8 return false; | 8 return false; |
9 } | 9 } |
10 } | 10 } |
14 } | 14 } |
15 } | 15 } |
16 return true; | 16 return true; |
17 } | 17 } |
18 | 18 |
19 adb_query_results_t *audiodb_query_spec(adb_t *adb, adb_query_spec_t *qspec) { | 19 adb_query_results_t *audiodb_query_spec(adb_t *adb, const adb_query_spec_t *qspec) { |
20 adb_qstate_internal_t qstate = {0}; | 20 adb_qstate_internal_t qstate = {0}; |
21 qstate.allowed_keys = new std::set<std::string>; | 21 qstate.allowed_keys = new std::set<std::string>; |
22 adb_query_results_t *results; | 22 adb_query_results_t *results; |
23 if(qspec->refine.flags & ADB_REFINE_INCLUDE_KEYLIST) { | 23 if(qspec->refine.flags & ADB_REFINE_INCLUDE_KEYLIST) { |
24 for(unsigned int k = 0; k < qspec->refine.include.nkeys; k++) { | 24 for(unsigned int k = 0; k < qspec->refine.include.nkeys; k++) { |
94 if(qstate.allowed_keys) | 94 if(qstate.allowed_keys) |
95 delete qstate.allowed_keys; | 95 delete qstate.allowed_keys; |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 int audiodb_query_free_results(adb_t *adb, adb_query_spec_t *spec, adb_query_results_t *rs) { | 99 int audiodb_query_free_results(adb_t *adb, const adb_query_spec_t *spec, adb_query_results_t *rs) { |
100 free(rs->results); | 100 free(rs->results); |
101 free(rs); | 101 free(rs); |
102 return 0; | 102 return 0; |
103 } | 103 } |
104 | 104 |
105 static void audiodb_initialize_arrays(adb_t *adb, adb_query_spec_t *spec, int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD) { | 105 static void audiodb_initialize_arrays(adb_t *adb, const adb_query_spec_t *spec, int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD) { |
106 unsigned int j, k, l, w; | 106 unsigned int j, k, l, w; |
107 double *dp, *qp, *sp; | 107 double *dp, *qp, *sp; |
108 | 108 |
109 const unsigned HOP_SIZE = spec->refine.hopsize; | 109 const unsigned HOP_SIZE = spec->refine.hopsize; |
110 const unsigned wL = spec->qid.sequence_length; | 110 const unsigned wL = spec->qid.sequence_length; |
276 qpointers->l2norm = qpointers->l2norm_data; | 276 qpointers->l2norm = qpointers->l2norm_data; |
277 qpointers->power = qpointers->power_data; | 277 qpointers->power = qpointers->power_data; |
278 return 0; | 278 return 0; |
279 } | 279 } |
280 | 280 |
281 int audiodb_query_spec_qpointers(adb_t *adb, adb_query_spec_t *spec, double **vector_data, double **vector, adb_qpointers_internal_t *qpointers) { | 281 int audiodb_query_spec_qpointers(adb_t *adb, const adb_query_spec_t *spec, double **vector_data, double **vector, adb_qpointers_internal_t *qpointers) { |
282 adb_datum_t *datum; | 282 adb_datum_t *datum; |
283 adb_datum_t d = {0}; | 283 adb_datum_t d = {0}; |
284 uint32_t sequence_length; | 284 uint32_t sequence_length; |
285 uint32_t sequence_start; | 285 uint32_t sequence_start; |
286 | 286 |
335 } | 335 } |
336 | 336 |
337 return 0; | 337 return 0; |
338 } | 338 } |
339 | 339 |
340 static int audiodb_set_up_dbpointers(adb_t *adb, adb_query_spec_t *spec, adb_qpointers_internal_t *dbpointers) { | 340 static int audiodb_set_up_dbpointers(adb_t *adb, const adb_query_spec_t *spec, adb_qpointers_internal_t *dbpointers) { |
341 uint32_t nvectors = adb->header->length / (adb->header->dim * sizeof(double)); | 341 uint32_t nvectors = adb->header->length / (adb->header->dim * sizeof(double)); |
342 uint32_t sequence_length = spec->qid.sequence_length; | 342 uint32_t sequence_length = spec->qid.sequence_length; |
343 | 343 |
344 bool using_power = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); | 344 bool using_power = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); |
345 bool using_times = spec->refine.flags & ADB_REFINE_DURATION_RATIO; | 345 bool using_times = spec->refine.flags & ADB_REFINE_DURATION_RATIO; |
425 } | 425 } |
426 return 1; | 426 return 1; |
427 | 427 |
428 } | 428 } |
429 | 429 |
430 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) { | 430 int audiodb_query_queue_loop(adb_t *adb, const adb_query_spec_t *spec, adb_qstate_internal_t *qstate, double *query, adb_qpointers_internal_t *qpointers) { |
431 adb_qpointers_internal_t dbpointers = {0}; | 431 adb_qpointers_internal_t dbpointers = {0}; |
432 | 432 |
433 uint32_t sequence_length = spec->qid.sequence_length; | 433 uint32_t sequence_length = spec->qid.sequence_length; |
434 bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); | 434 bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); |
435 | 435 |
503 SAFE_DELETE_ARRAY(dbpointers.mean_duration); | 503 SAFE_DELETE_ARRAY(dbpointers.mean_duration); |
504 delete qstate->exact_evaluation_queue; | 504 delete qstate->exact_evaluation_queue; |
505 return 0; | 505 return 0; |
506 } | 506 } |
507 | 507 |
508 int audiodb_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { | 508 int audiodb_query_loop(adb_t *adb, const adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { |
509 | 509 |
510 double *query, *query_data; | 510 double *query, *query_data; |
511 adb_qpointers_internal_t qpointers = {0}, dbpointers = {0}; | 511 adb_qpointers_internal_t qpointers = {0}, dbpointers = {0}; |
512 | 512 |
513 bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); | 513 bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD); |