comparison audioDB.h @ 458:913a95f06998 api-inversion

Start using the query state structure. Actually using it means moving it around in the source code a little bit, thanks to entanglements. It'll all be alright on the night. Now the accumulator, allowed_keys and exact_evaluation_queue are all part of the query state, and can therefore be passed around with minimal effort (and deleted in the appropriate place). Now a whole bunch of static methods (the callbacks, basically) in index.cpp can be rewritten as plain old C functions. The callbacks need both an adb_t and a query state structure to function (the adb_t to get at things like lsh_n_point_bits and the track->key table; the qstate to get at the accumulator and allowed_keys list). Rearrange audioDB::query a little bit, and mark the beginning and the end of the putative audiodb_query_spec() API function implementation.
author mas01cr
date Sun, 28 Dec 2008 18:44:08 +0000
parents 0ef029232213
children fcc6f7c4856b
comparison
equal deleted inserted replaced
457:823bca1e10f5 458:913a95f06998
30 30
31 // includes for web services 31 // includes for web services
32 #include "soapH.h" 32 #include "soapH.h"
33 #include "cmdline.h" 33 #include "cmdline.h"
34 34
35 // should probably be rewritten
36 class PointPair{
37 public:
38 Uns32T trackID;
39 Uns32T qpos;
40 Uns32T spos;
41 PointPair(Uns32T a, Uns32T b, Uns32T c);
42 };
43 bool operator<(const PointPair& a, const PointPair& b);
44
35 // should be in -internals.h 45 // should be in -internals.h
36 typedef struct adb_qpointers_internal { 46 typedef struct adb_qpointers_internal {
37 uint32_t nvectors; 47 uint32_t nvectors;
38 double *l2norm_data; 48 double *l2norm_data;
39 double *l2norm; 49 double *l2norm;
40 double *power_data; 50 double *power_data;
41 double *power; 51 double *power;
42 double *mean_duration; 52 double *mean_duration;
43 } adb_qpointers_internal_t; 53 } adb_qpointers_internal_t;
54
55 typedef struct adb_qstate_internal {
56 Accumulator *accumulator;
57 std::set<std::string> *allowed_keys;
58 std::priority_queue<PointPair> *exact_evaluation_queue;
59 } adb_qstate_internal_t;
44 60
45 #define MAXSTR 512 61 #define MAXSTR 512
46 62
47 // Databse PRIMARY commands 63 // Databse PRIMARY commands
48 #define COM_CREATE "--NEW" 64 #define COM_CREATE "--NEW"
216 off_t l2normTableOffset; 232 off_t l2normTableOffset;
217 off_t timesTableOffset; 233 off_t timesTableOffset;
218 off_t powerTableOffset; 234 off_t powerTableOffset;
219 off_t dbSize; 235 off_t dbSize;
220 } dbTableHeaderT, *dbTableHeaderPtr; 236 } dbTableHeaderT, *dbTableHeaderPtr;
221
222 class PointPair{
223 public:
224 Uns32T trackID;
225 Uns32T qpos;
226 Uns32T spos;
227 PointPair(Uns32T a, Uns32T b, Uns32T c);
228 };
229
230 bool operator<(const PointPair& a, const PointPair& b);
231 237
232 class audioDB{ 238 class audioDB{
233 private: 239 private:
234 gengetopt_args_info args_info; 240 gengetopt_args_info args_info;
235 unsigned dim; 241 unsigned dim;
307 double absolute_threshold; 313 double absolute_threshold;
308 bool use_relative_threshold; 314 bool use_relative_threshold;
309 double relative_threshold; 315 double relative_threshold;
310 316
311 ReporterBase* reporter; // track/point reporter 317 ReporterBase* reporter; // track/point reporter
312 Accumulator *accumulator;
313 priority_queue<PointPair, std::vector<PointPair>, std::less<PointPair> >* exact_evaluation_queue;
314 318
315 // LISZT parameters 319 // LISZT parameters
316 unsigned lisztOffset; 320 unsigned lisztOffset;
317 unsigned lisztLength; 321 unsigned lisztLength;
318 322
322 326
323 // private methods 327 // private methods
324 void error(const char* a, const char* b = "", const char *sysFunc = 0); 328 void error(const char* a, const char* b = "", const char *sysFunc = 0);
325 329
326 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata); 330 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
327 int query_loop(adb_t *adb, adb_query_spec_t *spec); 331 int query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate);
328 void query_loop_points(adb_t *adb, adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers); 332 void query_loop_points(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate, double *query, adb_qpointers_internal_t *qpointers);
329 void initRNG(); 333 void initRNG();
330 void initDBHeader(const char *dbName); 334 void initDBHeader(const char *dbName);
331 void initInputFile(const char *inFile); 335 void initInputFile(const char *inFile);
332 void initTables(const char* dbName, const char* inFile = 0); 336 void initTables(const char* dbName, const char* inFile = 0);
333 void initTablesFromKey(const char* dbName, const Uns32T queryIndex); 337 void initTablesFromKey(const char* dbName, const Uns32T queryIndex);
369 Uns32T lsh_param_k; // Number of independent hash functions 373 Uns32T lsh_param_k; // Number of independent hash functions
370 Uns32T lsh_param_m; // Combinatorial parameter for m(m-1)/2 hash tables 374 Uns32T lsh_param_m; // Combinatorial parameter for m(m-1)/2 hash tables
371 Uns32T lsh_param_N; // Number of rows per hash table 375 Uns32T lsh_param_N; // Number of rows per hash table
372 Uns32T lsh_param_b; // Batch size, in number of tracks, per indexing iteration 376 Uns32T lsh_param_b; // Batch size, in number of tracks, per indexing iteration
373 Uns32T lsh_param_ncols; // Maximum number of collision in a hash-table row 377 Uns32T lsh_param_ncols; // Maximum number of collision in a hash-table row
374 Uns32T lsh_n_point_bits; // How many bits to use to encode point ID within a track
375 378
376 379
377 // LSH vector<> containers for one in-core copy of a set of feature vectors 380 // LSH vector<> containers for one in-core copy of a set of feature vectors
378 vector<vector<float> > *vv; // one-track's worth data 381 vector<vector<float> > *vv; // one-track's worth data
379 382
382 void index_initialize(double**,double**,double**,double**,unsigned int*); 385 void index_initialize(double**,double**,double**,double**,unsigned int*);
383 void index_insert_tracks(Uns32T start_track, Uns32T end_track, double** fvpp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp); 386 void index_insert_tracks(Uns32T start_track, Uns32T end_track, double** fvpp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp);
384 int index_insert_track(Uns32T trackID, double** fvpp, double** snpp, double** sppp); 387 int index_insert_track(Uns32T trackID, double** fvpp, double** snpp, double** sppp);
385 Uns32T index_insert_shingles(vector<vector<float> >*, Uns32T trackID, double* spp); 388 Uns32T index_insert_shingles(vector<vector<float> >*, Uns32T trackID, double* spp);
386 int index_norm_shingles(vector<vector<float> >*, double* snp, double* spp); 389 int index_norm_shingles(vector<vector<float> >*, double* snp, double* spp);
387 int index_query_loop(adb_t *adb, adb_query_spec_t *spec); 390 int index_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate);
388 vector<vector<float> >* index_initialize_shingles(Uns32T sz); 391 vector<vector<float> >* index_initialize_shingles(Uns32T sz);
389 int index_init_query(const char* dbName); 392 int index_init_query(const char* dbName);
390 int index_exists(const char* dbName, double radius, Uns32T sequenceLength); 393 int index_exists(const char* dbName, double radius, Uns32T sequenceLength);
391 char* index_get_name(const char*dbName, double radius, Uns32T sequenceLength); 394 char* index_get_name(const char*dbName, double radius, Uns32T sequenceLength);
392 static void index_add_point_approximate(void* instance, Uns32T pointID, Uns32T qpos, float dist); // static point reporter callback method
393 static void index_add_point_exact(void* instance, Uns32T pointID, Uns32T qpos, float dist); // static point reporter callback method
394 static Uns32T index_to_trackID(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackID
395 static Uns32T index_to_trackPos(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackPos (spos)
396 static Uns32T index_from_trackInfo(Uns32T trackID, Uns32T pntID, Uns32T nPntBits); // Convert audioDB trackID and trackPos to an lsh point index
397 void initialize_exact_evalutation_queue();
398 void index_insert_exact_evaluation_queue(Uns32T trackID, Uns32T qpos, Uns32T spos);
399 LSH* index_allocate(char* indexName, bool load_hashTables); 395 LSH* index_allocate(char* indexName, bool load_hashTables);
400 void insertPowerData(unsigned n, int powerfd, double *powerdata); 396 void insertPowerData(unsigned n, int powerfd, double *powerdata);
401 void init_track_aux_data(Uns32T trackID, double* fvp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp); 397 void init_track_aux_data(Uns32T trackID, double* fvp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp);
402 398
403 // Web Services 399 // Web Services
472 use_absolute_threshold(false), \ 468 use_absolute_threshold(false), \
473 absolute_threshold(0.0), \ 469 absolute_threshold(0.0), \
474 use_relative_threshold(false), \ 470 use_relative_threshold(false), \
475 relative_threshold(0.0), \ 471 relative_threshold(0.0), \
476 reporter(0), \ 472 reporter(0), \
477 accumulator(0), \
478 exact_evaluation_queue(0), \
479 lisztOffset(0), \ 473 lisztOffset(0), \
480 lisztLength(0), \ 474 lisztLength(0), \
481 apierrortemp(0), \ 475 apierrortemp(0), \
482 UseApiError(0), \ 476 UseApiError(0), \
483 lsh(0), \ 477 lsh(0), \
488 lsh_param_k(0), \ 482 lsh_param_k(0), \
489 lsh_param_m(0), \ 483 lsh_param_m(0), \
490 lsh_param_N(0), \ 484 lsh_param_N(0), \
491 lsh_param_b(0), \ 485 lsh_param_b(0), \
492 lsh_param_ncols(0), \ 486 lsh_param_ncols(0), \
493 lsh_n_point_bits(0), \
494 vv(0) 487 vv(0)
495 #endif 488 #endif