comparison audioDB-internals.h @ 534:57e459f62788

Removed LSH_N_POINT_BITS coding for LSH index. Now uses binay search via STL lower_bound to locate tracks and positions from global pointID searching over cumulative track lengths. MERGE of branches/multiprobeLSH -r 819:821 onto trunk. This is a non backward-compatible change; WARNING generated on attempt to use INDEXING with older audioDB databases. Only INDEXES are broken, not ADB instances.
author mas01mc
date Wed, 04 Feb 2009 10:45:57 +0000
parents cc2b97d020b1
children 77e63d5c6de0
comparison
equal deleted inserted replaced
515:c7bdb7913762 534:57e459f62788
268 268
269 static inline const char *audiodb_index_key(adb_t *adb, uint32_t index) { 269 static inline const char *audiodb_index_key(adb_t *adb, uint32_t index) {
270 return (*adb->keys)[index].c_str(); 270 return (*adb->keys)[index].c_str();
271 } 271 }
272 272
273 static inline uint32_t audiodb_index_to_track_id(uint32_t lshid, uint32_t n_point_bits) { 273 static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid){
274 return (lshid >> n_point_bits); 274 std::vector<off_t>::iterator it_b = (*adb->track_offsets).begin();
275 } 275 std::vector<off_t>::iterator it_e = (*adb->track_offsets).end();
276 276 off_t test_id = lshid*adb->header->dim*sizeof(double);
277 static inline uint32_t audiodb_index_to_track_pos(uint32_t lshid, uint32_t n_point_bits) { 277 std::vector<off_t>::iterator point_p = std::lower_bound(it_b, it_e, test_id);
278 return (lshid & ((1 << n_point_bits) - 1)); 278 if(*point_p == test_id)
279 } 279 return point_p - it_b; // lshid is first point in found track
280 280 else
281 static inline uint32_t audiodb_index_from_trackinfo(uint32_t track_id, uint32_t track_pos, uint32_t n_point_bits) { 281 return point_p - it_b - 1; // lshid is a point in the previous track
282 return ((track_id << n_point_bits) | track_pos); 282 }
283 } 283
284 284 static inline uint32_t audiodb_index_to_track_pos(adb_t *adb, uint32_t track_id, uint32_t lshid) {
285 #define ADB_FIXME_DEFAULT_LSH_N_POINT_BITS 14 285 uint32_t trackIndexOffset = (*adb->track_offsets)[track_id] / (adb->header->dim * sizeof(double));
286 #ifndef ADB_FIXME_LSH_N_POINT_BITS 286 return lshid - trackIndexOffset;
287 #define ADB_FIXME_LSH_N_POINT_BITS ADB_FIXME_DEFAULT_LSH_N_POINT_BITS 287 }
288 #endif 288
289 289 static inline uint32_t audiodb_index_from_trackinfo(adb_t *adb, uint32_t track_id, uint32_t track_pos) {
290 static inline uint32_t audiodb_lsh_n_point_bits(adb_t *adb) { 290 uint32_t trackIndexOffset = (*adb->track_offsets)[track_id] / (adb->header->dim * sizeof(double));
291 uint32_t nbits = adb->header->flags >> 28; 291 return trackIndexOffset + track_pos;
292 return (nbits ? nbits : ADB_FIXME_LSH_N_POINT_BITS);
293 } 292 }
294 293
295 int audiodb_read_data(adb_t *, int, int, double **, size_t *); 294 int audiodb_read_data(adb_t *, int, int, double **, size_t *);
296 int audiodb_insert_create_datum(adb_insert_t *, adb_datum_t *); 295 int audiodb_insert_create_datum(adb_insert_t *, adb_datum_t *);
297 int audiodb_track_id_datum(adb_t *, uint32_t, adb_datum_t *); 296 int audiodb_track_id_datum(adb_t *, uint32_t, adb_datum_t *);
323 322
324 #define ADB_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24) 323 #define ADB_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24)
325 #define ADB_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24) 324 #define ADB_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24)
326 #define ADB_FORMAT_VERSION (4U) 325 #define ADB_FORMAT_VERSION (4U)
327 326
328 #define ADB_LSH_MAXTRACKLEN (1 << ADB_FIXME_LSH_N_POINT_BITS)
329
330 #define align_up(x,w) (((x) + ((1<<w)-1)) & ~((1<<w)-1)) 327 #define align_up(x,w) (((x) + ((1<<w)-1)) & ~((1<<w)-1))
331 #define align_down(x,w) ((x) & ~((1<<w)-1)) 328 #define align_down(x,w) ((x) & ~((1<<w)-1))
332 329
333 #define align_page_up(x) (((x) + (getpagesize()-1)) & ~(getpagesize()-1)) 330 #define align_page_up(x) (((x) + (getpagesize()-1)) & ~(getpagesize()-1))
334 #define align_page_down(x) ((x) & ~(getpagesize()-1)) 331 #define align_page_down(x) ((x) & ~(getpagesize()-1))