comparison nearestaccumulator.h @ 610:e21a3db643af

MORE MEMORY SANITY Move the logic tracking which points have been visited already (including the std::set datastructure) into the indexed query codepaths, rather than inside accumulators. This has the effect of drastically reducing the memory used in non-indexed queries, such that the working set for a 500-file database with 100000 vectors total goes from 1.2GB to slightly under 3MB. All this and less code, too!
author mas01cr
date Fri, 28 Aug 2009 17:14:06 +0000
parents 342822c2d49a
children
comparison
equal deleted inserted replaced
609:368320b31db6 610:e21a3db643af
3 NearestAccumulator(); 3 NearestAccumulator();
4 ~NearestAccumulator(); 4 ~NearestAccumulator();
5 void add_point(adb_result_t *r); 5 void add_point(adb_result_t *r);
6 adb_query_results_t *get_points(); 6 adb_query_results_t *get_points();
7 private: 7 private:
8 std::set< adb_result_t, adb_result_triple_lt > *set;
9 std::set< adb_result_t, adb_result_qpos_lt > *points; 8 std::set< adb_result_t, adb_result_qpos_lt > *points;
10 }; 9 };
11 10
12 template <class T> NearestAccumulator<T>::NearestAccumulator() 11 template <class T> NearestAccumulator<T>::NearestAccumulator()
13 : set(0), points(0) { 12 : points(0) {
14 set = new std::set< adb_result_t, adb_result_triple_lt >;
15 points = new std::set< adb_result_t, adb_result_qpos_lt >; 13 points = new std::set< adb_result_t, adb_result_qpos_lt >;
16 } 14 }
17 15
18 template <class T> NearestAccumulator<T>::~NearestAccumulator() { 16 template <class T> NearestAccumulator<T>::~NearestAccumulator() {
19 if(set) {
20 delete set;
21 }
22 if(points) { 17 if(points) {
23 delete points; 18 delete points;
24 } 19 }
25 } 20 }
26 21
27 template <class T> void NearestAccumulator<T>::add_point(adb_result_t *r) { 22 template <class T> void NearestAccumulator<T>::add_point(adb_result_t *r) {
28 if(!isnan(r->dist)) { 23 if(!isnan(r->dist)) {
29 if(set->find(*r) == set->end()) { 24 std::set< adb_result_t, adb_result_qpos_lt >::iterator it;
30 set->insert(*r); 25 it = points->find(*r);
31 26 if(it == points->end()) {
32 std::set< adb_result_t, adb_result_qpos_lt >::iterator it; 27 points->insert(*r);
33 it = points->find(*r); 28 } else if(T()(*(const adb_result_t *)r,(*it))) {
34 if(it == points->end()) { 29 points->erase(it);
35 points->insert(*r); 30 points->insert(*r);
36 } else if(T()(*(const adb_result_t *)r,(*it))) {
37 points->erase(it);
38 points->insert(*r);
39 }
40 } 31 }
41 } 32 }
42 } 33 }
43 34
44 template <class T> adb_query_results_t *NearestAccumulator<T>::get_points() { 35 template <class T> adb_query_results_t *NearestAccumulator<T>::get_points() {