diff multiprobe.h @ 518:ca1ee92c359c multiprobeLSH

Completed initial implementation of LSH MultiProbe class. Now needs to be joined to lshlib.cpp retrieve() method to perform multi-probe queries.
author mas01mc
date Mon, 26 Jan 2009 02:50:44 +0000
parents 807c8be7dd45
children fdcd436d7cbd
line wrap: on
line diff
--- a/multiprobe.h	Sun Jan 25 06:10:38 2009 +0000
+++ b/multiprobe.h	Mon Jan 26 02:50:44 2009 +0000
@@ -1,7 +1,8 @@
 /*
  * MultiProbe C++ class
  *
- * Given a LSH structure, perform lookup by probing nearby hash-function locations
+ * Given a vector of LSH boundary distances for a query, 
+ * perform lookup by probing nearby hash-function locations
  *
  * Implementation using C++ STL
  *
@@ -16,6 +17,9 @@
  *
  */
 
+#ifndef __LSH_MULTIPROBE_
+#define __LSH_MULTIPROBE_
+
 #include <functional>
 #include <queue>
 #include <vector>
@@ -23,26 +27,31 @@
 #include <algorithm>
 #include <iostream>
 
-using namespace std ;
+using namespace std;
 
 typedef set<int > perturbation_set ;
-typedef vector<perturbation_set > vector_of_perturbation_set ;
-typedef pair<perturbation_set, float > min_heap_element ;
-typedef vector<min_heap_element > vector_of_min_heap_element ;
-typedef priority_queue<
-  min_heap_element, 
-  vector_of_min_heap_element, 
-  greater<min_heap_element> 
-  > min_heap_of_perturbation_set ;
+
+typedef class MinHeapElement{
+public:
+  perturbation_set perturbs;
+  double score;
+  MinHeapElement(perturbation_set a, double s);
+  virtual ~MinHeapElement();
+} min_heap_element;
+
+typedef priority_queue<min_heap_element, 
+		       vector<min_heap_element>, 
+		       greater<min_heap_element> 
+		       > min_heap_of_perturbation_set ;
+
 typedef pair<double, pair<int, int> > sorted_distance_functions ;
-typedef vector<sorted_distance_functions> vector_of_sorted_distance_functions;
 
-bool operator>(const min_heap_element& a, const min_heap_element& b){
-  return a.second > b.second;
+bool operator> (const min_heap_element& a, const min_heap_element& b){
+  return a.score > b.score;
 }
 
-bool operator<(const min_heap_element& a, const min_heap_element& b){
-  return a.second < b.second;
+bool operator< (const min_heap_element& a, const min_heap_element& b){
+  return a.score < b.score;
 }
 
 bool operator>(const sorted_distance_functions& a, const sorted_distance_functions& b){
@@ -56,25 +65,34 @@
 class MultiProbe{
 protected:
   min_heap_of_perturbation_set* minHeap;
-  vector_of_perturbation_set* outSets;
-  vector_of_sorted_distance_functions* distFuns;
+  min_heap_of_perturbation_set* outSets;
+  vector<sorted_distance_functions>* distFuns;
   unsigned numHashBoundaries;
-public: 
-  MultiProbe();
-  ~MultiProbe();
 
+  // data structure initialization and cleanup
+  void initialize();
+  void cleanup();
+  
   // perturbation set operations
   perturbation_set& shift(perturbation_set&);
   perturbation_set& expand(perturbation_set&);
   double score(perturbation_set&);
   bool valid(perturbation_set&);
+  void makeSortedDistFuns(vector<double> &);
+
+public: 
+  MultiProbe();
+  ~MultiProbe();
 
   // generation of perturbation sets
-  void generatePerturbationSets(int, vector<double>&);
-  void makeSortedDistFuns(vector<double> &);
-  void dump(perturbation_set& );
+  void generatePerturbationSets(vector<double>& vectorOfBounaryDistances, int numSetsToGenerate);  
+  perturbation_set getNextPerturbationSet();
+  void dump(perturbation_set);
+  size_t size(); // Number of perturbation sets are in the output queue
+  bool empty(); // predicate for empty MultiProbe set
 };
 
+
 /* NOTES:
 
 Reference:
@@ -113,3 +131,5 @@
   end for
 
  */
+
+#endif // __LSH_MULTIPROBE_