annotate audioDB_API.h @ 453:16a903968d18 api-inversion

Almost finish with audioDB::query_loop. This patch is a little bit noisy, because we rename adb->keys to adb->keymap, introduce a new vector adb->keys (essentially to replace fileTable), and introduce new functionality (both include and exclude keylists in adb_query_refine_t) as well as modifying the query_loop function itself to take advantage of all of these goodies. Oh, and we also fix an embarrassing state bug in adb->track_offsets for insert -- what was I thinking? (Thank you, regression test suites). Since we are on a private branch at the moment, we can take the luxury of renumbering the ADB_REFINE_ flags to include the exclude list at the logical place; once we have an ABI to support, that won't be possible. Now audioDB::query builds up include and exclude lists as appropriate; query_loop does an [O(NlogN) probably] buildup of the keys to consider, and then iterates over tracks sequentially, seeking only if one or more tracks have been excluded. No more trackFile, yay! The only remaining thing to deal with is the accumulator. It's easy enough to pass it around, but I want to read the indexed version before doing so to see how that all fits together.
author mas01cr
date Wed, 24 Dec 2008 10:57:14 +0000
parents 1a1ea05a94ce
children 93ce12fe2f76
rev   line source
mas01cr@421 1 #ifndef AUDIODB_API_H
mas01cr@421 2 #define AUDIODB_API_H
mas01cr@421 3
mas01cr@392 4 #include <stdbool.h>
mas01cr@398 5 #include <stdint.h>
mas01cr@398 6
mas01ik@355 7 /* for API questions contact
mas01ik@355 8 * Christophe Rhodes c.rhodes@gold.ac.uk
mas01ik@355 9 * Ian Knopke mas01ik@gold.ac.uk, ian.knopke@gmail.com */
mas01ik@355 10
mas01cr@392 11 /* Temporary workarounds */
mas01cr@388 12 typedef struct dbTableHeader adb_header_t;
mas01cr@392 13 int acquire_lock(int, bool);
mas01cr@388 14
mas01cr@400 15
mas01cr@401 16 /*******************************************************************/
mas01cr@401 17 /* Data types for API */
mas01cr@400 18
mas01ik@355 19 /* The main struct that stores the name of the database, and in future will hold all
mas01ik@355 20 * kinds of other interesting information */
mas01ik@355 21 /* This basically gets passed around to all of the other functions */
mas01cr@388 22
mas01cr@388 23 /* FIXME: it might be that "adb_" isn't such a good prefix to use, and
mas01cr@419 24 that we should prefer "audiodb_". Or else maybe we should be
mas01cr@419 25 calling ourselves libadb? */
mas01ik@355 26 typedef struct adb adb_t, *adb_ptr;
mas01ik@355 27
mas01cr@404 28 struct adb_datum {
mas01cr@404 29 uint32_t nvectors;
mas01cr@404 30 uint32_t dim;
mas01cr@404 31 const char *key;
mas01cr@404 32 double *data;
mas01cr@404 33 double *power;
mas01cr@404 34 double *times;
mas01cr@404 35 };
mas01cr@404 36 typedef struct adb_datum adb_datum_t;
mas01cr@404 37
mas01ik@355 38 //used for both insert and batchinsert
mas01ik@355 39 struct adbinsert {
mas01cr@405 40 const char *features;
mas01cr@405 41 const char *power;
mas01cr@405 42 const char *key;
mas01cr@405 43 const char *times;
mas01ik@355 44 };
mas01cr@441 45 typedef struct adbinsert adb_insert_t, adb_reference_t, *adb_insert_ptr;
mas01ik@355 46
mas01ik@355 47 /* struct for returning status results */
mas01ik@355 48 struct adbstatus {
mas01ik@355 49 unsigned int numFiles;
mas01ik@355 50 unsigned int dim;
mas01ik@355 51 unsigned int dudCount;
mas01ik@355 52 unsigned int nullCount;
mas01ik@355 53 unsigned int flags;
mas01cr@398 54 uint64_t length;
mas01cr@398 55 uint64_t data_region_size;
mas01ik@355 56 };
mas01ik@355 57 typedef struct adbstatus adb_status_t, *adb_status_ptr;
mas01ik@355 58
mas01ik@355 59 /* needed for constructing a query */
mas01ik@355 60 struct adbquery {
mas01ik@355 61
mas01ik@355 62 char * querytype;
mas01ik@355 63 char * feature; //usually a file of some kind
mas01ik@355 64 char * power; //also a file
mas01ik@355 65 char * keylist; //also a file
mas01ik@355 66 char * qpoint; //position
mas01ik@355 67 char * numpoints;
mas01ik@355 68 char * radius;
mas01ik@355 69 char * resultlength; //how many results to make
mas01ik@355 70 char * sequencelength;
mas01ik@355 71 char * sequencehop;
mas01ik@355 72 double absolute_threshold;
mas01ik@355 73 double relative_threshold;
mas01ik@355 74 int exhaustive; //hidden option in gengetopt
mas01ik@355 75 double expandfactor; //hidden
mas01ik@355 76 int rotate; //hidden
mas01ik@355 77
mas01ik@355 78 };
mas01ik@355 79 typedef struct adbquery adb_query_t,*adb_query_ptr;
mas01ik@355 80
mas01ik@355 81 /* ... and for getting query results back */
mas01ik@355 82 struct adbqueryresult {
mas01ik@355 83
mas01ik@355 84 int sizeRlist; /* do I really need to return all 4 sizes here */
mas01ik@355 85 int sizeDist;
mas01ik@355 86 int sizeQpos;
mas01ik@355 87 int sizeSpos;
mas01ik@355 88 char **Rlist;
mas01ik@355 89 double *Dist;
mas01ik@355 90 unsigned int *Qpos;
mas01ik@355 91 unsigned int *Spos;
mas01ik@355 92
mas01ik@355 93 };
mas01ik@355 94 typedef struct adbqueryresult adb_queryresult_t, *adb_queryresult_ptr;
mas01ik@355 95
mas01cr@419 96 /* New ("new" == December 2008) query API */
mas01cr@419 97
mas01cr@419 98 typedef struct adbresult {
mas01cr@419 99 const char *key;
mas01cr@419 100 double dist;
mas01cr@419 101 uint32_t qpos;
mas01cr@419 102 uint32_t ipos;
mas01cr@419 103 } adb_result_t;
mas01cr@419 104
mas01cr@453 105 #define ADB_REFINE_INCLUDE_KEYLIST 1
mas01cr@453 106 #define ADB_REFINE_EXCLUDE_KEYLIST 2
mas01cr@453 107 #define ADB_REFINE_RADIUS 4
mas01cr@453 108 #define ADB_REFINE_ABSOLUTE_THRESHOLD 8
mas01cr@453 109 #define ADB_REFINE_RELATIVE_THRESHOLD 16
mas01cr@453 110 #define ADB_REFINE_DURATION_RATIO 32
mas01cr@453 111 #define ADB_REFINE_HOP_SIZE 64
mas01cr@453 112
mas01cr@453 113 typedef struct adbkeylist {
mas01cr@453 114 uint32_t nkeys;
mas01cr@453 115 const char **keys;
mas01cr@453 116 } adb_keylist_t;
mas01cr@419 117
mas01cr@419 118 typedef struct adbqueryrefine {
mas01cr@419 119 uint32_t flags;
mas01cr@453 120 adb_keylist_t include;
mas01cr@453 121 adb_keylist_t exclude;
mas01cr@419 122 double radius;
mas01cr@419 123 double absolute_threshold;
mas01cr@419 124 double relative_threshold;
mas01cr@419 125 double duration_ratio; /* expandfactor */
mas01cr@419 126 uint32_t hopsize;
mas01cr@419 127 } adb_query_refine_t;
mas01cr@419 128
mas01cr@419 129 #define ADB_ACCUMULATION_DB 1
mas01cr@419 130 #define ADB_ACCUMULATION_PER_TRACK 2
mas01cr@419 131 #define ADB_ACCUMULATION_ONE_TO_ONE 3
mas01cr@419 132
mas01cr@419 133 #define ADB_DISTANCE_DOT_PRODUCT 1
mas01cr@419 134 #define ADB_DISTANCE_EUCLIDEAN_NORMED 2
mas01cr@419 135 #define ADB_DISTANCE_EUCLIDEAN 3
mas01cr@419 136
mas01cr@419 137 typedef struct adbqueryparameters {
mas01cr@419 138 uint32_t accumulation;
mas01cr@419 139 uint32_t distance;
mas01cr@419 140 uint32_t npoints;
mas01cr@419 141 uint32_t ntracks;
mas01cr@419 142 } adb_query_parameters_t;
mas01cr@419 143
mas01cr@419 144 typedef struct adbqueryresults {
mas01cr@419 145 uint32_t nresults;
mas01cr@419 146 adb_result_t *results;
mas01cr@419 147 } adb_query_results_t;
mas01cr@419 148
mas01cr@434 149 #define ADB_QUERY_ID_FLAG_EXHAUSTIVE 1
mas01cr@434 150
mas01cr@419 151 typedef struct adbqueryid {
mas01cr@419 152 adb_datum_t *datum;
mas01cr@419 153 uint32_t sequence_length;
mas01cr@434 154 uint32_t flags;
mas01cr@419 155 uint32_t sequence_start;
mas01cr@419 156 } adb_query_id_t;
mas01cr@419 157
mas01cr@419 158 typedef struct adbqueryspec {
mas01cr@419 159 adb_query_id_t qid;
mas01cr@435 160 adb_query_parameters_t params;
mas01cr@435 161 adb_query_refine_t refine;
mas01cr@419 162 } adb_query_spec_t;
mas01ik@355 163
mas01ik@355 164 /*******************************************************************/
mas01ik@355 165 /* Function prototypes for API */
mas01ik@355 166
mas01ik@355 167 /* open an existing database */
mas01ik@355 168 /* returns a struct or NULL on failure */
mas01cr@392 169 adb_ptr audiodb_open(const char *path, int flags);
mas01ik@355 170
mas01ik@355 171 /* create a new database */
mas01ik@355 172 /* returns a struct or NULL on failure */
mas01cr@381 173 adb_ptr audiodb_create(const char *path, unsigned datasize, unsigned ntracks, unsigned datadim);
mas01ik@355 174
mas01ik@355 175 /* close a database */
mas01ik@355 176 void audiodb_close(adb_ptr db);
mas01ik@355 177
mas01ik@355 178 /* You'll need to turn both of these on to do anything useful */
mas01ik@355 179 int audiodb_l2norm(adb_ptr mydb);
mas01ik@355 180 int audiodb_power(adb_ptr mydb);
mas01ik@355 181
mas01ik@355 182 /* insert functions */
mas01cr@404 183 int audiodb_insert_datum(adb_t *, adb_datum_t *);
mas01cr@441 184 int audiodb_insert_reference(adb_t *, adb_reference_t *);
mas01ik@355 185 int audiodb_insert(adb_ptr mydb, adb_insert_ptr ins);
mas01ik@355 186 int audiodb_batchinsert(adb_ptr mydb, adb_insert_ptr ins, unsigned int size);
mas01ik@355 187
mas01ik@355 188 /* query function */
mas01ik@355 189 int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqres);
mas01cr@419 190 int audiodb_query_csr(adb_t *, adb_query_spec_t *, adb_query_results_t *);
mas01cr@419 191
mas01ik@355 192 /* database status */
mas01ik@355 193 int audiodb_status(adb_ptr mydb, adb_status_ptr status);
mas01ik@355 194
mas01ik@355 195 /* varoius dump formats */
mas01cr@399 196 int audiodb_dump(adb_ptr mydb, const char *outputdir);
mas01cr@421 197
mas01cr@421 198 #endif