diff pertrackaccumulator.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 a35ca2d5f238
line wrap: on
line diff
--- a/pertrackaccumulator.h	Fri Aug 21 15:23:32 2009 +0000
+++ b/pertrackaccumulator.h	Fri Aug 28 17:14:06 2009 +0000
@@ -8,13 +8,11 @@
   unsigned int pointNN;
   unsigned int trackNN;
   std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_key_lt> *queues;
-  std::set< adb_result_t, adb_result_triple_lt > *set;
 };
 
 template <class T> PerTrackAccumulator<T>::PerTrackAccumulator(unsigned int pointNN, unsigned int trackNN)
-  : pointNN(pointNN), trackNN(trackNN), queues(0), set(0) {
+  : pointNN(pointNN), trackNN(trackNN), queues(0) {
   queues = new std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_key_lt>;
-  set = new std::set< adb_result_t, adb_result_triple_lt >;
 }
 
 template <class T> PerTrackAccumulator<T>::~PerTrackAccumulator() {
@@ -25,30 +23,23 @@
     }
     delete queues;
   }
-  if(set) {
-    delete set;
-  }
 }
 
 template <class T> void PerTrackAccumulator<T>::add_point(adb_result_t *r) {
   if(!isnan(r->dist)) {
-    if(set->find(*r) == set->end()) {
-      set->insert(*r);
-
-      typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_key_lt>::iterator it;
-      std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *queue;
-      it = queues->find(*r);
-      if(it == queues->end()) {
-        queue = new std::priority_queue< adb_result_t, std::vector< adb_result_t >, T >;
-        (*queues)[*r] = queue;
-      } else {
-        queue = (*it).second;
-      }
-
-      queue->push(*r);
-      if(queue->size() > pointNN) {
-        queue->pop();
-      }
+    typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_key_lt>::iterator it;
+    std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *queue;
+    it = queues->find(*r);
+    if(it == queues->end()) {
+      queue = new std::priority_queue< adb_result_t, std::vector< adb_result_t >, T >;
+      (*queues)[*r] = queue;
+    } else {
+      queue = (*it).second;
+    }
+    
+    queue->push(*r);
+    if(queue->size() > pointNN) {
+      queue->pop();
     }
   }
 }