00001
00006 #ifndef __SPARSEBITMATRIX_INTERSECTION_HPP_
00007 #define __SPARSEBITMATRIX_INTERSECTION_HPP_ t
00008
00009 #include "SparseBitvector_intersection.hpp"
00010
00011
00012 #include "common/debug.hpp"
00013 #include <vector>
00014
00029 template <bool EARLY_FILTERING, bool INTERSECTION_ROWSWAPPING, bool REMOVE_IDENTICAL_ROWS, class OutputIterator>
00030 int intersectSparseBitmatrix(const SparseBitmatrix& bmIn, const int row, SparseBitmatrix& bmOut,
00031 const int minimalLength, OutputIterator identicalRowsIterator) {
00032 assert(row >= 0 && row < bmIn.nRows());
00033
00034
00035 int tor = 0;
00036 int maxRowLength = 0;
00037 bmOut.setNRows(bmIn.nRows() - row - 1);
00038 const GET_ROW(row1, bmIn, row);
00039
00040
00041 for (int otherRow = row+1; otherRow < bmIn.nRows(); otherRow++) {
00042 const GET_ROW(row2, bmIn, otherRow);
00043 GET_ROW(rowOut, bmOut, tor);
00044
00045 bool hasMinimalLength = INTERSECTION_ROWSWAPPING && row1.length() < row2.length()
00046 ? intersection<EARLY_FILTERING>(rowOut, row2, row1, minimalLength)
00047 : intersection<EARLY_FILTERING>(rowOut, row1, row2, minimalLength);
00048
00049
00050 if (hasMinimalLength) {
00051 if (REMOVE_IDENTICAL_ROWS && rowOut.length() == row1.length())
00052
00053 *identicalRowsIterator++ = bmIn.rowLabel(otherRow);
00054 else {
00055
00056
00057 bmOut.setRowLabel(tor, bmIn.rowLabel(otherRow));
00058 if (rowOut.length() > maxRowLength)
00059 maxRowLength = rowOut.length();
00060 tor++;
00061 }
00062 }
00063 }
00064
00065
00066 bmOut.setNRows(tor);
00067 bmOut.setMaxRowLength(maxRowLength);
00068
00069 return tor;
00070 }
00071
00072
00088 template <bool EARLY_FILTERING, bool INTERSECTION_ROWSWAPPING, bool REMOVE_IDENTICAL_ROWS, class OutputIterator>
00089 int intersectSparseBitmatrix(const SparseBitmatrix& bmIn, const int row, const vector<int> otherRows, SparseBitmatrix& bmOut,
00090 const int minimalLength, OutputIterator identicalRowsIterator) {
00091 assert(row >= 0 && row < bmIn.nRows());
00092
00093
00094 int tor = 0;
00095 int maxRowLength = 0;
00096 bmOut.setNRows(otherRows.size());
00097 const GET_ROW(row1, bmIn, row);
00098
00099
00100 for (vector<int>::iterator iter = otherRows.begin(); iter != otherRows.end(); iter++ ) {
00101 int otherRow = *iter;
00102 const GET_ROW(row2, bmIn, otherRow);
00103 GET_ROW(rowOut, bmOut, tor);
00104
00105 bool hasMinimalLength = INTERSECTION_ROWSWAPPING && row1.length() < row2.length()
00106 ? intersection<EARLY_FILTERING>(rowOut, row2, row1, minimalLength)
00107 : intersection<EARLY_FILTERING>(rowOut, row1, row2, minimalLength);
00108
00109
00110 if (hasMinimalLength) {
00111 if (REMOVE_IDENTICAL_ROWS && rowOut.length() == row1.length())
00112
00113 *identicalRowsIterator++ = bmIn.rowLabel(otherRow);
00114 else {
00115
00116
00117 bmOut.setRowLabel(tor, bmIn.rowLabel(otherRow));
00118 if (rowOut.length() > maxRowLength)
00119 maxRowLength = rowOut.length();
00120 tor++;
00121 }
00122 }
00123 }
00124
00125
00126 bmOut.setNRows(tor);
00127 bmOut.setMaxRowLength(maxRowLength);
00128
00129 return tor;
00130 }
00131
00132
00137 template <bool EARLY_FILTERING>
00138 int cardinalityIntersectionSparseBitmatrix_TwoRows(const SparseBitmatrix& bmIn, const int minimalLength) {
00139 const GET_ROW(row0, bmIn, 0);
00140 const GET_ROW(row1, bmIn, 1);
00141 return cardinalityOfIntersection<EARLY_FILTERING>(row0, row1, minimalLength);
00142 }
00143
00144
00145 #endif