Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SparseBitmatrix_setdifference.cpp

Go to the documentation of this file.
00001 
00006 #include "SparseBitmatrix_setdifference.hpp"
00007 #include "common/debug.hpp"
00008 
00013 int cardinalitySetdifferenceBySparseBitmatrix_TwoRows(SparseBitmatrix* bmIn, int maxdefect) {
00014   assert(bmIn->numRows == 2);
00015   // int row = 0;
00016 
00017   // 1. reset structure of bmOut.
00018   // int numRowsIn = 2;
00019   int** rowsIn = bmIn->rows;
00020   int* rowLengthsIn = bmIn->rowLengths;
00021 
00022   // 2. do the intersection:
00023   int* row1 = rowsIn[0];
00024   int len1 = rowLengthsIn[0];
00025   
00026   // int fromr = 1;
00027   int* row2 = rowsIn[1];
00028   int len2 = rowLengthsIn[1];
00029 
00030   if (len1 == 0)
00031     return len2;
00032 
00033   int posOut = 0;
00034   if (len2 > 0) { // something to do:
00035     int pos1 = 0, pos2 = 0;
00036     int item1 = row1[0], item2 = row2[0];
00037     
00038     // a. compute cardinality of set difference:
00039     while (true) {
00040       if (item1 < item2) {
00041         pos1++; 
00042         if (pos1 >= len1) break;
00043         item1 = row1[pos1];
00044       } else if (item1 > item2) {
00045         assert(posOut >= 0);
00046         assert(posOut < len2); 
00047         posOut++;
00048         if (posOut > maxdefect) break;
00049         
00050         pos2++; 
00051         if (pos2 >= len2) break;
00052         item2 = row2[pos2];
00053       } else { // if (item1 == item2) {
00054         pos2++; if (pos2 >= len2) break; // first check for pos2 as we add all remaining row2 items at the end !
00055         pos1++; if (pos1 >= len1) break;
00056         item1 = row1[pos1]; item2 = row2[pos2];
00057       }
00058     }
00059     // copy remaining items of row2:
00060     if (pos2 < len2) {
00061       posOut += (len2-pos2);
00062     }
00063   } else { // nothing to do: row2 is empty. // [was:] copy whole row as is.
00064     posOut = 0; // len1;
00065   }
00066 
00067   return posOut <= maxdefect ? posOut : maxdefect + 1;
00068 }
00069 

Generated on Sun Sep 17 17:50:40 2006 for FIM environment by  doxygen 1.4.4