changeset 561:1e6cc843563a multiprobeLSH

Fixed error in pointID bit processing (logical ! used instead of bit-wise ~). Fixed LSH table row disk/core dump routines.
author mas01mc
date Sun, 22 Feb 2009 15:04:44 +0000
parents 11ea54a02534
children 92f034aa8f28
files lshlib.cpp tabdump.cpp
diffstat 2 files changed, 52 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/lshlib.cpp	Sun Feb 22 03:44:25 2009 +0000
+++ b/lshlib.cpp	Sun Feb 22 15:04:44 2009 +0000
@@ -1674,9 +1674,9 @@
     p2 = *p++;
     skip = (( p1 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_LSB) + (( p2 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_MSB);
     if( t2 == H::t2 ){
-      add_point_callback(calling_instance, p1 & !SKIP_BITS, qpos, radius);
+      add_point_callback(calling_instance, p1 & ~SKIP_BITS, qpos, radius);
       if(skip--){
-	add_point_callback(calling_instance, p2 & !SKIP_BITS, qpos, radius);
+	add_point_callback(calling_instance, p2 & ~SKIP_BITS, qpos, radius);
 	while(skip-- )
 	  add_point_callback(calling_instance, *p++, qpos, radius);
       }
@@ -1712,7 +1712,7 @@
 
  void G::dump_core_row(Uns32T n){
    if(!(n<H::N)){
-     printf("ROW OUT OF RANGE:%d (MAX:%d)\n", n, H::N);
+     printf("ROW OUT OF RANGE:%d (MAX:%d)\n", n, H::N-1);
      return;
    }
    for(Uns32T j = 0 ; j < H::L ; j++ ){
@@ -1756,7 +1756,7 @@
     fclose(dbFile);
     error("fSeek error in unserialize_lsh_hashtables_format2");
   }
-  Uns32T token;
+  Uns32T token = 0;
   Uns32T pointID;
 
   // Read the hash tables into core (structure is given in header) 
@@ -1764,78 +1764,67 @@
     y=0;
     if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
       fclose(dbFile);
-      error("Read error 1","unserialize_lsh_hashtables_format2()");
+      error("Read error T1","unserialize_lsh_hashtables_format2()");
     }
-    if(token==O2_SERIAL_TOKEN_ENDTABLE){
-      x++; // End of table
-    }
-    else{
-      while(y < n){
-	// Read a row and move file pointer to beginning of next row or _bittable
-	if(!(token==O2_SERIAL_TOKEN_T1)){
+    while(token != O2_SERIAL_TOKEN_ENDTABLE){
+      if(token == O2_SERIAL_TOKEN_T1){
+	if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
 	  fclose(dbFile);
-	  error("State machine error T1","unserialize_lsh_hashtables_format2()");
-	}
-	
-	while(token != O2_SERIAL_TOKEN_ENDTABLE){
+	  error("Read error t1","unserialize_lsh_hashtables_format2()");
+	    }
+	y=token;
+	if(y==n){
+	  printf("D[%d,%d]", x, y);
 	  if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
 	    fclose(dbFile);
 	    error("Read error 2","unserialize_lsh_hashtables_format2()");
 	  }
-	  if(token == O2_SERIAL_TOKEN_T1){
+	  printf("[numElements=%d]", token);
+	  if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
+	    fclose(dbFile);
+	    error("Read error 3","unserialize_lsh_hashtables_format2()");
+	  }
+	  while(!(token==O2_SERIAL_TOKEN_ENDTABLE || token==O2_SERIAL_TOKEN_T1)){
+	    // Check for T2 token
+	    if(token!=O2_SERIAL_TOKEN_T2){
+	      printf("t2=%d",token);
+	      fclose(dbFile);
+	      error("State machine error T2 token", "unserialize_hashtable_row_format2()");
+	    }
+	    // Read t2 value
 	    if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
 	      fclose(dbFile);
-	      error("Read error t1","unserialize_lsh_hashtables_format2()");
+	      error("Read error t2","unserialize_hashtable_row_format2");
 	    }
-	    y=token;
-	    if(y==n){
-	      printf("D[%d,%d]", x, y);
-	      if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
+	    if(fread(&pointID, sizeof(Uns32T), 1, dbFile) != 1){
+	      fclose(dbFile);
+	      error("Read error pointID","unserialize_hashtable_row_format2");
+	    }
+	    while(!(pointID==O2_SERIAL_TOKEN_ENDTABLE || pointID==O2_SERIAL_TOKEN_T1 || pointID==O2_SERIAL_TOKEN_T2 )){
+	      printf("(%0X,%u)", token, pointID);
+	      if(fread(&pointID, sizeof(Uns32T), 1, dbFile) != 1){
 		fclose(dbFile);
-		error("Read error 2","unserialize_lsh_hashtables_format2()");
+		error("Read error H::p","unserialize_hashtable_row_format2");
 	      }
-	      printf("[numElements=%d]", token);
-	      if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
-		fclose(dbFile);
-		error("Read error 3","unserialize_lsh_hashtables_format2()");
-	      }
-	      while(!(token==O2_SERIAL_TOKEN_ENDTABLE || token==O2_SERIAL_TOKEN_T1)){
-		// Check for T2 token
-		if(token!=O2_SERIAL_TOKEN_T2){
-		  printf("t2=%d",token);
-		  fclose(dbFile);
-		  error("State machine error T2 token", "unserialize_hashtable_row_format2()");
-		}
-		// Read t2 value
-		if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
-		  fclose(dbFile);
-		  error("Read error t2","unserialize_hashtable_row_format2");
-		}
-		if(fread(&pointID, sizeof(Uns32T), 1, dbFile) != 1){
-		  fclose(dbFile);
-		  error("Read error pointID","unserialize_hashtable_row_format2");
-		}
-		while(!(pointID==O2_SERIAL_TOKEN_ENDTABLE || pointID==O2_SERIAL_TOKEN_T1 || pointID==O2_SERIAL_TOKEN_T2 )){
-		  printf("(%0X,%u)", token, pointID);
-		  if(fread(&pointID, sizeof(Uns32T), 1, dbFile) != 1){
-		    fclose(dbFile);
-		    error("Read error H::p","unserialize_hashtable_row_format2");
-		  }
-		}
-		token = pointID; // Copy last found token
-	      }
-	      printf("\n");
+	    }
+	    token = pointID; // Copy last found token
+	  }
+	  printf("\n");
+	}
+	else{ // gobble up rest of row
+	  while(!(token==O2_SERIAL_TOKEN_T1 || token==O2_SERIAL_TOKEN_ENDTABLE)){
+	    if(fread(&token, sizeof(Uns32T), 1, dbFile) != 1){
+	      fclose(dbFile);
+	      error("Read error 4","unserialize_lsh_hashtables_format2()");
 	    }
 	  }
 	}
-	if(token==O2_SERIAL_TOKEN_ENDTABLE){
-	  x++;
-	  break;
-	}
       }
     }
+    if(token==O2_SERIAL_TOKEN_ENDTABLE){
+      x++;
+    }
   }
-  
   close(dbfid);
  }
 
@@ -1850,9 +1839,9 @@
     p1 = *p++;
     p2 = *p++;
     skip = (( p1 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_LSB) + (( p2 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_MSB);
-    printf("(%0X, %u)", t2, p1 & !SKIP_BITS);
+    printf("(%0X, %u)", t2, p1 & ~SKIP_BITS);
     if(skip--){
-      printf("(%0X, %u)", t2, p2 & !SKIP_BITS);
+      printf("(%0X, %u)", t2, p2 & ~SKIP_BITS);
       while(skip-- )
 	printf("(%0X, %u)", t2, *p++);
     }
--- a/tabdump.cpp	Sun Feb 22 03:44:25 2009 +0000
+++ b/tabdump.cpp	Sun Feb 22 15:04:44 2009 +0000
@@ -25,8 +25,9 @@
       exit(0);
     }
     n = atoi(buf);
-    printf("row=%d\n", n);
+    printf("*** LSH DISK ***\n");
     lsh->dump_disk_row(argv[1], n);
+    printf("*** LSH CORE (ARRAY) ***\n");
     lsh->dump_core_row(n);
   }
   return 0;