comparison audioDB-internals.h @ 536:ad561daf75ca

Use upper_bound rather than lower_bound in audiodb_index_to_track_id() Saves us one explicit conditional.
author mas01cr
date Wed, 04 Feb 2009 13:47:02 +0000
parents 77e63d5c6de0
children d3c96cbb91e3
comparison
equal deleted inserted replaced
535:77e63d5c6de0 536:ad561daf75ca
269 269
270 static inline const char *audiodb_index_key(adb_t *adb, uint32_t index) { 270 static inline const char *audiodb_index_key(adb_t *adb, uint32_t index) {
271 return (*adb->keys)[index].c_str(); 271 return (*adb->keys)[index].c_str();
272 } 272 }
273 273
274 static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid){ 274 static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid) {
275 std::vector<off_t>::iterator it_b = (*adb->track_offsets).begin(); 275 off_t offset = lshid * adb->header->dim * sizeof(double);
276 std::vector<off_t>::iterator it_e = (*adb->track_offsets).end(); 276 std::vector<off_t>::iterator b = (*adb->track_offsets).begin();
277 off_t test_id = lshid*adb->header->dim*sizeof(double); 277 std::vector<off_t>::iterator e = (*adb->track_offsets).end();
278 std::vector<off_t>::iterator point_p = std::lower_bound(it_b, it_e, test_id); 278 std::vector<off_t>::iterator p = std::upper_bound(b, e, offset);
279 if(*point_p == test_id) 279 return p - b - 1;
280 return point_p - it_b; // lshid is first point in found track
281 else
282 return point_p - it_b - 1; // lshid is a point in the previous track
283 } 280 }
284 281
285 static inline uint32_t audiodb_index_to_track_pos(adb_t *adb, uint32_t track_id, uint32_t lshid) { 282 static inline uint32_t audiodb_index_to_track_pos(adb_t *adb, uint32_t track_id, uint32_t lshid) {
286 uint32_t trackIndexOffset = (*adb->track_offsets)[track_id] / (adb->header->dim * sizeof(double)); 283 uint32_t trackIndexOffset = (*adb->track_offsets)[track_id] / (adb->header->dim * sizeof(double));
287 return lshid - trackIndexOffset; 284 return lshid - trackIndexOffset;