T1* FoldFingerprint(const T1& bv1, unsigned int factor) { if (factor <= 0 || factor >= bv1.getNumBits()) throw ValueErrorException("invalid fold factor"); int initSize = bv1.getNumBits(); int resSize = initSize / factor; T1* res = new T1(resSize); IntVect onBits; bv1.getOnBits(onBits); for (IntVectIter iv = onBits.begin(); iv != onBits.end(); iv++) { int pos = (*iv) % resSize; res->setBit(pos); } return res; }
void TestSortTable() { { typedef std::pair<int, int> IntPair; typedef std::vector<IntPair> IntVect; typedef IntVect::iterator IntVectIter; IntVect test; IntVect checked; test.push_back(make_pair(10, 0)); test.push_back(make_pair(9, 1)); test.push_back(make_pair(3, 2)); test.push_back(make_pair(3, 3)); test.push_back(make_pair(5, 4)); test.push_back(make_pair(5, 5)); test.push_back(make_pair(5, 6)); test.push_back(make_pair(1, 7)); checked.push_back( make_pair(1, 7)); checked.push_back( make_pair(3, 2)); checked.push_back( make_pair(3, 3)); checked.push_back( make_pair(5, 4)); checked.push_back( make_pair(5, 5)); checked.push_back( make_pair(5, 6)); checked.push_back( make_pair(9, 1)); checked.push_back( make_pair(10, 0)); stable_sort(test.begin(), test.end()); bool res = std::equal(test.cbegin(), test.cend(), checked.cbegin(), [](const IntPair& left, const IntPair& right)->bool { return (left.first == right.first) && (left.second == right.second); } ); CHECK_RESULTS(res); } }