void GenerateFullMatrices(double values[], double scale, boost::shared_ptr<NekMatrix<NekDouble, StandardMatrixTag> >& m1, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag> >& m2, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag> >& m3) { m1 = MakePtr(new NekMatrix<NekDouble, StandardMatrixTag>(4, 4, values)); double inner_values[16]; std::transform(values, values+16, inner_values, boost::bind(std::divides<NekDouble>(), _1, scale)); boost::shared_ptr<NekMatrix<NekDouble> > inner( new NekMatrix<NekDouble>(4, 4, inner_values)); m2 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag>(scale, inner)); double block_1_values[] = {values[0], values[1], values[4], values[5]}; double block_2_values[] = {values[2], values[3], values[6], values[7]}; double block_3_values[] = {values[8], values[9], values[12], values[13]}; double block_4_values[] = {values[10], values[11], values[14], values[15]}; boost::shared_ptr<NekMatrix<NekDouble> > block1(new NekMatrix<NekDouble>(2, 2, block_1_values)); boost::shared_ptr<NekMatrix<NekDouble> > block2(new NekMatrix<NekDouble>(2, 2, block_2_values)); boost::shared_ptr<NekMatrix<NekDouble> > block3(new NekMatrix<NekDouble>(2, 2, block_3_values)); boost::shared_ptr<NekMatrix<NekDouble> > block4(new NekMatrix<NekDouble>(2, 2, block_4_values)); m3 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag>(2, 2, 2, 2)); m3->SetBlock(0,0, block1); m3->SetBlock(1,0, block2); m3->SetBlock(0,1, block3); m3->SetBlock(1,1, block4); }
void GenerateUpperTriangularMatrices(NekDouble values[], NekDouble scale, boost::shared_ptr<NekMatrix<NekDouble, StandardMatrixTag> >& m1, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag> >& m2, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag> >& m3) { m1 = MakePtr(new NekMatrix<NekDouble, StandardMatrixTag>(4, 4, values, eUPPER_TRIANGULAR)); double inner_values[10]; std::transform(values, values+10, inner_values, boost::bind(std::divides<NekDouble>(), _1, scale)); boost::shared_ptr<NekMatrix<NekDouble> > inner( new NekMatrix<NekDouble>(4, 4, inner_values, eUPPER_TRIANGULAR)); m2 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag>(scale, inner)); double block_1_values[] = {values[0], 0.0, values[1], values[2]}; double block_2_values[] = {values[3], values[4], values[6], values[7]}; double block_4_values[] = {values[5], 0.0, values[8], values[9]}; boost::shared_ptr<NekMatrix<NekDouble> > block1(new NekMatrix<NekDouble>(2, 2, block_1_values)); boost::shared_ptr<NekMatrix<NekDouble> > block2(new NekMatrix<NekDouble>(2, 2, block_2_values)); boost::shared_ptr<NekMatrix<NekDouble> > block4(new NekMatrix<NekDouble>(2, 2, block_4_values)); m3 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag>(2, 2, 2, 2)); m3->SetBlock(0,0, block1); m3->SetBlock(0,1, block2); m3->SetBlock(1,1, block4); }
std::list<Point> medianCut(Point* image, int numPoints, unsigned int desiredSize) { std::priority_queue<Block> blockQueue; Block initialBlock(image, numPoints); initialBlock.shrink(); blockQueue.push(initialBlock); while (blockQueue.size() < desiredSize) { Block longestBlock = blockQueue.top(); blockQueue.pop(); Point * begin = longestBlock.getPoints(); Point * median = longestBlock.getPoints() + (longestBlock.numPoints()+1)/2; Point * end = longestBlock.getPoints() + longestBlock.numPoints(); switch(longestBlock.longestSideIndex()) { case 0: std::nth_element(begin, median, end, CoordinatePointComparator<0>()); break; case 1: std::nth_element(begin, median, end, CoordinatePointComparator<1>()); break; case 2: std::nth_element(begin, median, end, CoordinatePointComparator<2>()); break; } Block block1(begin, median-begin), block2(median, end-median); block1.shrink(); block2.shrink(); blockQueue.push(block1); blockQueue.push(block2); } std::list<Point> result; while(!blockQueue.empty()) { Block block = blockQueue.top(); blockQueue.pop(); Point * points = block.getPoints(); int sum[NUM_DIMENSIONS] = {0}; for(int i=0; i < block.numPoints(); i++) { for(int j=0; j < NUM_DIMENSIONS; j++) { sum[j] += points[i].x[j]; } } Point averagePoint; for(int j=0; j < NUM_DIMENSIONS; j++) { averagePoint.x[j] = sum[j] / block.numPoints(); } result.push_back(averagePoint); } return result; }
TEST(Block, testIsSquare) { char p[32]; Block block(p, 32, 2); EXPECT_TRUE(block.isSquare()); Block block2(p, 16, 2); EXPECT_FALSE(block2.isSquare()); }
int main() { __block int i; i = 0; void (^block)() = ^{ printf("Hello world %d\n", i); }; ++i; void (^block2)() = Block_copy(block); ++i; block2(); Block_release(block2); return 0; }
void defense(void){ d_calibrateR(); Delay(500); d_calibrateL(); Delay(500); d_centre(steps_taken); Delay(500); block1(); Delay(500); unblock1(); Delay(500); block2(); Delay(500); unblock2(); Delay(500); return; }
QgsRasterBlock* QgsRasterResampleFilter::block( int bandNo, const QgsRectangle &extent, int width, int height ) { return block2( bandNo, extent, width, height ); }
QgsRasterBlock* QgsRasterProjector::block( int bandNo, const QgsRectangle & extent, int width, int height ) { return block2( bandNo, extent, width, height ); }
//from Kwalletbackend. // this should be SHA-512 for release probably QString Hash::password2hash(const QByteArray& password) { SHA1 sha; QByteArray hash; hash.resize(20); hash.fill(0); int shasz = sha.size() / 8; assert(shasz >= 20); QByteArray block1(shasz, 0); sha.process(password.data(), qMin(password.size(), 16)); // To make brute force take longer for (int i = 0; i < 2000; i++) { memcpy(block1.data(), sha.hash(), shasz); sha.reset(); sha.process(block1.data(), shasz); } sha.reset(); if (password.size() > 16) { sha.process(password.data() + 16, qMin(password.size() - 16, 16)); QByteArray block2(shasz, 0); // To make brute force take longer for (int i = 0; i < 2000; i++) { memcpy(block2.data(), sha.hash(), shasz); sha.reset(); sha.process(block2.data(), shasz); } sha.reset(); if (password.size() > 32) { sha.process(password.data() + 32, qMin(password.size() - 32, 16)); QByteArray block3(shasz, 0); // To make brute force take longer for (int i = 0; i < 2000; i++) { memcpy(block3.data(), sha.hash(), shasz); sha.reset(); sha.process(block3.data(), shasz); } sha.reset(); if (password.size() > 48) { sha.process(password.data() + 48, password.size() - 48); QByteArray block4(shasz, 0); // To make brute force take longer for (int i = 0; i < 2000; i++) { memcpy(block4.data(), sha.hash(), shasz); sha.reset(); sha.process(block4.data(), shasz); } sha.reset(); // split 14/14/14/14 hash.resize(56); memcpy(hash.data(), block1.data(), 14); memcpy(hash.data() + 14, block2.data(), 14); memcpy(hash.data() + 28, block3.data(), 14); memcpy(hash.data() + 42, block4.data(), 14); block4.fill(0); } else { // split 20/20/16 hash.resize(56); memcpy(hash.data(), block1.data(), 20); memcpy(hash.data() + 20, block2.data(), 20); memcpy(hash.data() + 40, block3.data(), 16); } block3.fill(0); } else { // split 20/20 hash.resize(40); memcpy(hash.data(), block1.data(), 20); memcpy(hash.data() + 20, block2.data(), 20); } block2.fill(0); } else { // entirely block1 hash.resize(20); memcpy(hash.data(), block1.data(), 20); } block1.fill(0); //MCH: to store hash as a String... QString output, tmp; unsigned char *digest; digest = (unsigned char*) hash.data(); for (int i = 0; i < 20; ++i) output += tmp.sprintf("%02x", digest[i]); output = output.toUpper(); qDebug()<<"HASH::Result == "<<output; return output; }