00001
00006 #ifndef __SPARSEBITMATRIX_SETDIFFERENCE_HPP_
00007 #define __SPARSEBITMATRIX_SETDIFFERENCE_HPP_ t
00008
00009 #include "eclat/SparseBitvector_setdifference.hpp"
00010
00011
00012 #include "common/debug.hpp"
00013
00014
00030 template <bool EARLY_FILTERING, bool REMOVE_IDENTICAL_ROWS, class OutputIterator>
00031 int setdifferenceOfSparseBitmatrix(const SparseBitmatrix& bmIn, const int row, SparseBitmatrix& bmOut,
00032 const int maximalLength, OutputIterator identicalRowsIterator) {
00033 assert(row >= 0 && row < bmIn.nRows());
00034
00035
00036 bmOut.setNRows(bmIn.nRows() - row - 1);
00037 const GET_ROW(row1, bmIn, row);
00038 int tor = 0;
00039 int maxRowLength = 0;
00040
00041
00042 for (int fromr = row+1; fromr < bmIn.nRows(); fromr++) {
00043
00044
00045 const GET_ROW(row2, bmIn, fromr);
00046 GET_ROW(rowOut, bmOut, tor);
00047
00048 const bool hasMaximalLength = EARLY_FILTERING && row1.length() > maximalLength
00049 ? setdifference<EARLY_FILTERING>(rowOut, row1, row2, maximalLength)
00050 : setdifference<false>(rowOut, row1, row2, maximalLength);
00051
00052
00053 if (hasMaximalLength) {
00054 if (REMOVE_IDENTICAL_ROWS && rowOut.length() == 0)
00055 *identicalRowsIterator++ = bmIn.rowLabel(fromr);
00056 else {
00057 if (rowOut.length() > maxRowLength)
00058 maxRowLength = rowOut.length();
00059
00060 bmOut.setRowLabel(tor, bmIn.rowLabel(fromr));
00061 tor++;
00062 }
00063 }
00064 }
00065
00066 bmOut.setNRows(tor);
00067 bmOut.setMaxRowLength(maxRowLength);
00068 return tor;
00069 }
00070
00071
00072
00088 template <bool EARLY_FILTERING, bool REMOVE_IDENTICAL_ROWS, class OutputIterator>
00089 int setdifferenceBySparseBitmatrix(const SparseBitmatrix& bmIn, const int row, SparseBitmatrix& bmOut,
00090 const int maximalLength, OutputIterator identicalRowsIterator) {
00091 assert(row >= 0 && row < bmIn.nRows());
00092
00093
00094 bmOut.setNRows(bmIn.nRows() - row - 1);
00095 const GET_ROW(row1, bmIn, row);
00096 int tor = 0;
00097 int maxRowLength = 0;
00098
00099
00100 for (int fromr = row+1; fromr < bmIn.nRows(); fromr++) {
00101 const GET_ROW(row2, bmIn, fromr);
00102 GET_ROW(rowOut, bmOut, tor);
00103
00104 const bool hasMaximalLength = EARLY_FILTERING && row2.length() > maximalLength
00105 ? setdifference<EARLY_FILTERING>(rowOut, row2, row1, maximalLength)
00106 : setdifference<false>(rowOut, row2, row1, maximalLength);
00107
00108
00109 if (hasMaximalLength) {
00110 if (REMOVE_IDENTICAL_ROWS && rowOut.length() == 0)
00111 *identicalRowsIterator++ = bmIn.rowLabel(fromr);
00112 else {
00113 if (rowOut.length() > maxRowLength)
00114 maxRowLength = rowOut.length();
00115
00116 bmOut.setRowLabel(tor, bmIn.rowLabel(fromr));
00117 tor++;
00118 }
00119 }
00120 }
00121
00122 bmOut.setNRows(tor);
00123 bmOut.setMaxRowLength(maxRowLength);
00124 return tor;
00125 }
00126
00127
00132 template <bool EARLY_FILTERING>
00133 int cardinalitySetdifferenceBySparseBitmatrix_TwoRows(const SparseBitmatrix& bmIn, const int maximalLength) {
00134 const GET_ROW(row0, bmIn, 0);
00135 const GET_ROW(row1, bmIn, 1);
00136 return EARLY_FILTERING && row1.length() > maximalLength
00137 ? cardinalityOfSetdifference<EARLY_FILTERING>(row1, row0, maximalLength)
00138 : cardinalityOfSetdifference<false>(row1, row0, maximalLength);
00139 }
00140
00141
00142 #endif