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
00016
00017
00018
00019 int** rowsIn = bmIn->rows;
00020 int* rowLengthsIn = bmIn->rowLengths;
00021
00022
00023 int* row1 = rowsIn[0];
00024 int len1 = rowLengthsIn[0];
00025
00026
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) {
00035 int pos1 = 0, pos2 = 0;
00036 int item1 = row1[0], item2 = row2[0];
00037
00038
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 {
00054 pos2++; if (pos2 >= len2) break;
00055 pos1++; if (pos1 >= len1) break;
00056 item1 = row1[pos1]; item2 = row2[pos2];
00057 }
00058 }
00059
00060 if (pos2 < len2) {
00061 posOut += (len2-pos2);
00062 }
00063 } else {
00064 posOut = 0;
00065 }
00066
00067 return posOut <= maxdefect ? posOut : maxdefect + 1;
00068 }
00069