changeset 514:01cb73dfcddd

Removed redundant copy in LSH hashfunction computation when #!defined USE_U_FUNCTIONS. Moved LSH macro definitions into lshlib.h
author mas01mc
date Sat, 24 Jan 2009 06:16:00 +0000
parents a30948382f56
children c7bdb7913762
files lshlib.cpp lshlib.h
diffstat 2 files changed, 19 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/lshlib.cpp	Fri Jan 23 21:44:32 2009 +0000
+++ b/lshlib.cpp	Sat Jan 24 06:16:00 2009 +0000
@@ -1,19 +1,5 @@
 #include "lshlib.h"
 
-//#define LSH_DUMP_CORE_TABLES
-//#define USE_U_FUNCTIONS
-
-// Use backward-compatible CORE ARRAY lsh index
-#define LSH_CORE_ARRAY  // Set to use arrays for hashtables rather than linked-lists
-#define LSH_LIST_HEAD_COUNTERS // Enable counters in hashtable list heads
-
-// Critical path logic
-#if defined LSH_CORE_ARRAY && !defined LSH_LIST_HEAD_COUNTERS
-#define LSH_LIST_HEAD_COUNTERS
-#endif
-
-#define LSH_CORE_ARRAY_BIT (0x80000000) //  LSH_CORE_ARRAY test bit for list head
-
 
 void err(char*s){cout << s << endl;exit(2);}
 
@@ -162,10 +148,6 @@
   H::uu = vector<vector<Uns32T> >(H::m);
   for( Uns32T aa=0 ; aa < H::m ; aa++ )
     H::uu[aa] = vector<Uns32T>( H::k/2 );
-#else
-  H::uu = vector<vector<Uns32T> >(H::L);
-  for( Uns32T aa=0 ; aa < H::L ; aa++ )
-    H::uu[aa] = vector<Uns32T>( H::k );
 #endif
 }
 
@@ -309,8 +291,8 @@
     }
 #else
   for( aa=0; aa < H::L ; aa++ ){
-    ui = H::uu[aa].begin();
-    for( kk = 0 ; kk < H::k ; kk++ ){
+    pg= *( H::g + aa ); // L \times functions g_j(v) \in Z^k      
+    for( kk = 0 ; kk != H::k ; kk++ ){
       pb = *( H::b + aa ) + kk;
       pA = * ( * ( H::A + aa ) + kk );
       dd = H::d;
@@ -320,18 +302,9 @@
 	tmp += *pA++ * *vi++;  // project
       tmp += *pb;              // translate
       tmp *= iw;               // scale      
-      *ui++ = (Uns32T) (floor(tmp));   // floor
+      *pg++ = (Uns32T) (floor(tmp));      // hash function g_j(v)=[x1 x2 ... xk]; xk \in Z
     }
   }
-  // Compute hash functions
-  for( aa=0 ; aa < H::L ; aa++ ){
-    pg= *( H::g + aa ); // L \times functions g_j(v) \in Z^k      
-    // u_1 \in Z^{k \times d}
-    ui = H::uu[aa].begin();
-    kk=H::k;    
-    while( kk-- )
-      *pg++ = *ui++;      // hash function g_j(v)=[x1 x2 ... xk]; xk \in Z
-  }
 #endif
 }
 
--- a/lshlib.h	Fri Jan 23 21:44:32 2009 +0000
+++ b/lshlib.h	Sat Jan 24 06:16:00 2009 +0000
@@ -93,6 +93,20 @@
 #define WRITE_UNS32(VAL, TOKENSTR) if( fwrite(VAL, sizeof(Uns32T), 1, dbFile) != 1 ){\
   fclose(dbFile);error("write error in serial_write_format2",TOKENSTR);}	
 
+//#define LSH_DUMP_CORE_TABLES  // set to dump hashtables on load
+//#define USE_U_FUNCTIONS       // set to use partial hashfunction re-use
+
+// Backward-compatible CORE ARRAY lsh index
+#define LSH_CORE_ARRAY  // Set to use arrays for hashtables rather than linked-lists
+#define LSH_LIST_HEAD_COUNTERS // Enable counters in hashtable list heads
+
+// Critical path logic
+#if defined LSH_CORE_ARRAY && !defined LSH_LIST_HEAD_COUNTERS
+#define LSH_LIST_HEAD_COUNTERS
+#endif
+
+#define LSH_CORE_ARRAY_BIT (0x80000000) //  LSH_CORE_ARRAY test bit for list head
+
 using namespace std;
 
 Uns32T get_page_logn();
@@ -206,8 +220,9 @@
   bucket*** h;      // The LSH hash tables
 
   bool use_u_functions; // flag to optimize computation of hashes
+#ifdef USE_U_FUNCTIONS
   vector<vector<Uns32T> > uu; // Storage for m patial hash evaluations ( g_j = [u_a,u_b] )
-
+#endif
   Uns32T maxp; // highest pointID stored in database
   Uns32T bucketCount;  // count of number of point buckets allocated
   Uns32T pointCount;    // count of number of points inserted