// check wait in pool void test_case_2() { tsk::static_pool< tsk::unbounded_fifo > pool( tsk::poolsize( 3) ); boost::uint32_t n = 3; tsk::spin::auto_reset_event ev; tsk::handle< boost::uint32_t > h1( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), pool) ); tsk::handle< boost::uint32_t > h2( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), pool) ); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( ! h1.is_ready() ); BOOST_CHECK( ! h2.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h1.is_ready() || h2.is_ready() ); if ( h1.is_ready() ) { BOOST_CHECK_EQUAL( h1.get(), n); BOOST_CHECK( ! h2.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h2.is_ready() ); BOOST_CHECK_EQUAL( h2.get(), n); } else { BOOST_CHECK( h2.is_ready() ); BOOST_CHECK_EQUAL( h2.get(), n); BOOST_CHECK( ! h1.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h1.is_ready() ); BOOST_CHECK_EQUAL( h1.get(), n); } }
int main() { int counts[10] = {0,0,0,0,0,0,0,0,0,0}; unsigned samples[8] = {333, 632, 1090, 459, 238, 1982, 3411, 379}; int i; for ( i = 0; i < 8; ++i ) counts[h2(samples[i], 11)-1]++; report("Samples with h2", counts); for ( i = 0; i < 992; ++i ) counts[h2(3412+i, 11)-1]++; report("Adding 3412-4403", counts); for ( i = 0; i < 10; ++i ) counts[i] = 0; for ( i = 0; i < 8; ++i ) counts[h3(samples[i], 11)-1]++; report("Samples with h3", counts); for ( i = 0; i < 992; ++i ) counts[h3(3412+i, 11)-1]++; report("Adding 3412-4403", counts); }
int main() { llist entries; int status; html_header(); html_begin("Test CGI"); h1("CGI Test Program"); printf("<hr>\n"); h2("CGI Environment Variables"); print_cgi_env(); status = read_cgi_input(&entries); printf("<h2>Status = %d</h2>\n",status); h2("CGI Entries"); printf("<p>a: %s</p>", cgi_val(entries,"a")); printf("<p>b: %s</p>", cgi_val(entries,"b")); printf("<p>c: %s</p>", cgi_val(entries,"c")); html_end(); list_clear(&entries); return 0; }
void main(int i) { g(1); f(2); h(2); h2(2); h(3) foo(1); }
// Helper function to reinsert a key into the specified hash table after // splitting a bucket static void reinsert_key(InnerTable *innertable, int64 key, int table_no) { int address, hash = h1(key); if (table_no == 2) { hash = h2(key); } address = rightmostnbits(innertable->depth, hash); innertable->buckets[address]->key = key; innertable->buckets[address]->full = true; }
void CHTTPTest::DoTestsL() { testHarness->StartTestL(_L("Creating the string pool")); RStringPool pool; pool.OpenL(table); testHarness->EndTest(0); testHarness->StartTestL(_L("Creating 'hello'")); STRDCI_L(hello, KHello); RStringF def; testHarness->EndTest(hello == def); testHarness->StartTestL(_L("Creating another 'hello'")); ASTRDCI_L(hello1, KHello1); testHarness->EndTest(!(hello == hello1.iObj)); testHarness->StartTestL(_L("Testing !=")); testHarness->EndTest(hello != hello1.iObj); testHarness->StartTestL(_L("Creating 'goodbye'")); STRDCI_L(goodbye, KGoodbye); testHarness->EndTest(hello == goodbye); testHarness->StartTestL(_L("Creating string tokens")); RStringTokenF h1, h2(hello), g; h1 = hello; testHarness->EndTest(h1 != h2); testHarness->StartTestL(_L("Testing == on string tokens")); testHarness->EndTest(!(h1 == h2)); testHarness->StartTestL(_L("Making a string from a token")); hello1.iObj = pool.StringF(h1); testHarness->EndTest(hello != hello1.iObj); testHarness->StartTestL(_L("Non-equal tokens")); g = goodbye; testHarness->EndTest(hello == goodbye); testHarness->StartTestL(_L("Operator != on non-equal tokens")); testHarness->EndTest(!(hello != goodbye)); testHarness->StartTestL(_L("Copy function")); hello1.iObj = hello.Copy(); testHarness->EndTest(hello != hello1.iObj); testHarness->StartTestL(_L("String extraction (same)")); testHarness->EndTest(static_cast<const TDesC8&>(hello).Compare(hello1.iObj)); testHarness->StartTestL(_L("String extraction (different)")); testHarness->EndTest(!static_cast<const TDesC8&>(hello).Compare(goodbye)); testHarness->StartTestL(_L("String extraction (original)")); testHarness->EndTest(static_cast<const TDesC8&>(hello).Compare(KHello)); testHarness->StartTestL(_L("Closing pool")); hello.Copy(); hello.Close(); hello.Close(); hello1.iObj.Close(); // The copys here have got a bit confused hello1.iObj.Close(); goodbye.Close(); pool.CloseAll(); testHarness->EndTest(0); }
// check wait in new thread void test_case_1() { boost::uint32_t n = 3; tsk::spin::auto_reset_event ev; tsk::handle< boost::uint32_t > h1( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); tsk::handle< boost::uint32_t > h2( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( ! h1.is_ready() ); BOOST_CHECK( ! h2.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h1.is_ready() || h2.is_ready() ); if ( h1.is_ready() ) { BOOST_CHECK_EQUAL( h1.get(), n); BOOST_CHECK( ! h2.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h2.is_ready() ); BOOST_CHECK_EQUAL( h2.get(), n); } else { BOOST_CHECK( h2.is_ready() ); BOOST_CHECK_EQUAL( h2.get(), n); BOOST_CHECK( ! h1.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h1.is_ready() ); BOOST_CHECK_EQUAL( h1.get(), n); } }
void test_case_3() { boost::uint32_t n = 3; tsk::spin::manual_reset_event ev( true); tsk::handle< boost::uint32_t > h1( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); tsk::handle< boost::uint32_t > h2( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h1.is_ready() ); BOOST_CHECK( h2.is_ready() ); BOOST_CHECK_EQUAL( h1.get(), n); BOOST_CHECK_EQUAL( h2.get(), n); ev.reset(); tsk::handle< boost::uint32_t > h3( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); tsk::handle< boost::uint32_t > h4( tsk::async( tsk::make_task( wait_fn, n, boost::ref( ev) ), tsk::new_thread() ) ); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( ! h3.is_ready() ); BOOST_CHECK( ! h4.is_ready() ); ev.set(); boost::this_thread::sleep( pt::millisec( 250) ); BOOST_CHECK( h3.is_ready() ); BOOST_CHECK( h4.is_ready() ); BOOST_CHECK_EQUAL( h3.get(), n); BOOST_CHECK_EQUAL( h4.get(), n); }
void simpleMatrixTest::testUnsafeConstructor() { matrix_unsafe<int> c = matrix_unsafe<int>(); Assert(c.nrows == 0 && c.ncols == 0, "Unsafe Constructor 3 failed"); matrix_unsafe<int> d = c; Assert(d.nrows == 0 && d.ncols == 0, "Unsafe Constructor 4 failed"); double* e = new double[8]; for (int i = 0; i < 8; i++) e[i] = static_cast<double>(i*2); double f[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; matrix_unsafe<double> g = matrix_unsafe<double>(4, 2, e); matrix_unsafe<double> g2 = matrix_unsafe<double>(4, 2, e, true); for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { Assert(g(i, j) == e[j*4+i], "Unsafe Constructor 5 failed"); Assert(g2(i, j) == e[i*2+j], "Unsafe Constructor 5 failed"); } } matrix_unsafe<double> h = matrix_unsafe<double>(3, 2, f); matrix_unsafe<double> h2 = matrix_unsafe<double>(3, 2, f, true); for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { Assert(h(i, j) == f[j*3+i], "Unsafe Constructor 6 failed"); Assert(h2(i, j) == f[i*2+j], "Unsafe Constructor 6 failed"); } } matrix_unsafe<double> k = h; matrix_unsafe<double> k2 = h2; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { Assert(k(i, j) == f[j*3+i], "Unsafe Constructor 7 failed"); Assert(k2(i, j) == f[i*2+j], "Unsafe Constructor 7 failed"); } } int w[3] = {1,2,3}; matrix_unsafe<int> z = matrix_unsafe<int>(1,3,w); Assert(z(0,0) == w[0], "Unsafe Constructor 8 failed"); Assert(z(0,1) == w[1], "Unsafe Constructor 8 failed"); Assert(z(0,2) == w[2], "Unsafe Constructor 8 failed"); }
main(int argc, char **argv) { slab_cache_init(100, 0, 0, NULL, NULL); fieldinfos fis; fix_document doc1(1, 10); dyn_document doc2(2); document_helper h1(&doc1, fis); document_helper h2(&doc2, fis); long i = 100; double d = 100.1234; char *s = "string"; fis.add("f1", TDT_STRING); fis.add("f2", TDT_LONG); fis.add("f3", TDT_DOUBLE); h1.add("f1", s); h1.add("f2", &i); h1.add("f3", &d); h2.add("f1", s); h2.add("f2", &i); h2.add("f3", &d); std::cout << fis.i2n(0) << ": " << (char *)doc1.field_data(0) << std::endl; std::cout << fis.i2n(1) << ": " << *(long *)doc1.field_data(1) << std::endl; std::cout << fis.i2n(2) << ": " << *(double *)doc1.field_data(2) << std::endl; std::cout << fis.i2n(0) << ": " << (char *)doc2.field_data(0) << std::endl; std::cout << fis.i2n(1) << ": " << *(long *)doc2.field_data(1) << std::endl; std::cout << fis.i2n(2) << ": " << *(double *)doc2.field_data(2) << std::endl; //std::string qs = "n1 > 01 AND (n2 < 0x2 OR n3 <= 3) NOT n4 >= 4. AND n5 == .5 AND n6 != 6.3 AND n7: (4.e10,.5e11) OR n8:(2.3e1,3e4] OR n9:[04e4,5223.2323e4) OR n10:[2,9]"; std::string qs = "n1 > "; ccFlexLexer lexer(new std::istringstream(qs), &std::cout); query_exp<document_helper>* exp = NULL; yy::query_parser parser(&lexer, &exp); if (parser.parse() != 0) { std::cerr << "parse failed" << std::endl; } else { std::cout << "iQuery: " << qs << std::endl; std::cout << "Parsed: " << exp->to_string() << std::endl; } return 0; }
void g2(void) { myint Myint; vint Vint; myfloat Myfloat; pint Pint; pvint Pvint; str Str; vstr Vstr; void h(str, str, vstr, vstr, str, myint); h(Myint, Vint, Myfloat, Pint, Pvint, Vstr); h2(Str, Vstr); }
int ACE_TMAIN (int argc, ACE_TCHAR *[]) { // If argc > 1 then allow multiple handlers per-signal, else just // allow 1 handler per-signal. ACE_Sig_Handlers multi_handlers; #if defined (ACE_WIN32) ACE_WFMO_Reactor reactor_impl (argc > 1 ? &multi_handlers : (ACE_Sig_Handler *) 0); #else ACE_Select_Reactor reactor_impl (argc > 1 ? &multi_handlers : (ACE_Sig_Handler *) 0); #endif /* ACE_WIN32 */ ACE_Reactor reactor (&reactor_impl); if (argc > 1) { // Register an "external" signal handler so that the // ACE_Sig_Handlers code will have something to incorporate! ACE_SignalHandler eh = (ACE_SignalHandler) external_handler; ACE_Sig_Action sa (eh); sa.register_action (SIGINT); } // Create a bevy of handlers. Sig_Handler_1 h1 (reactor, "howdy"); Sig_Handler_1 h2 (reactor, "doody"); Sig_Handler_2 h3 (reactor, "tutty"); Sig_Handler_2 h4 (reactor, "fruity"); // Wait for user to type SIGINT and SIGQUIT. for (;;) { ACE_DEBUG ((LM_DEBUG, "\nwaiting for SIGINT or SIGQUIT\n")); if (reactor.handle_events () == -1) ACE_ERROR ((LM_ERROR, "%p\n", "handle_events")); } ACE_NOTREACHED (return 0); }
int main() { // two placeholders tql::placeholder <1> x_; tql::placeholder <2> y_; // a function of one variable triqs::clef::function<double(double)> h; h(x_) = 2 + 2*x_; std::cout<<h(3)<<std::endl; // expression can be given at construction triqs::clef::function<double(double)> h2 ( 2 + 2*x_ ,x_); std::cout<<h2(3)<<std::endl; // two variable functions triqs::clef::function<double(double,double)> f,g; f(x_,y_) = x_ + y_; std::cout<<f(2,3)<<std::endl; // affecting a new expression to f f(x_,y_) = x_ + 2*y_; std::cout<<f(2,3)<<std::endl; // f can be called with lazy expressions too to form more complex expressions. g(x_,y_) = x_ - y_ + f(x_,2*y_); std::cout<<g(2,3)<<std::endl; // lazy function are interoperable with std::function std::function<double(double,double)> bf(f); std::cout<<bf(2,3)<<std::endl; }
int main(int argc, char *argv[]) { perf_parse_args(argc, argv); std::cout << "size: " << PERF_N << std::endl; boost::compute::device device = boost::compute::system::default_device(); boost::compute::context context(device); boost::compute::command_queue queue(context, device); std::cout << "device: " << device.name() << std::endl; std::vector<int> h1(PERF_N); std::vector<int> h2(PERF_N); std::generate(h1.begin(), h1.end(), rand_int); std::generate(h2.begin(), h2.end(), rand_int); // create vector on the device and copy the data boost::compute::vector<int> d1(PERF_N, context); boost::compute::vector<int> d2(PERF_N, context); boost::compute::copy(h1.begin(), h1.end(), d1.begin(), queue); boost::compute::copy(h2.begin(), h2.end(), d2.begin(), queue); int product = 0; perf_timer t; for(size_t trial = 0; trial < PERF_TRIALS; trial++){ t.start(); product = boost::compute::inner_product( d1.begin(), d1.end(), d2.begin(), int(0), queue ); queue.finish(); t.stop(); } std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; // verify product is correct int host_product = std::inner_product( h1.begin(), h1.end(), h2.begin(), int(0) ); if(product != host_product){ std::cout << "ERROR: " << "device_product (" << product << ") " << "!= " << "host_product (" << host_product << ")" << std::endl; return -1; } return 0; }
DatasetPlane::DatasetPlane() : Dataset( QDir( "new plane" ), Fn::DatasetType::PLANE ), vbo0( 0 ), m_handle0( GLFunctions::getPickIndex() ), m_handle1( GLFunctions::getPickIndex() ), m_handle2( GLFunctions::getPickIndex() ), dirty( true ) { QList<Dataset*>dsl = Models::getDatasets( Fn::DatasetType::NIFTI_ANY ); int nx = 160; int ny = 200; int nz = 160; float dx = 1.0f; float dy = 1.0f; float dz = 1.0f; float ax = 0.0f; float ay = 0.0f; float az = 0.0f; if ( dsl.size() > 0 ) { nx = dsl[0]->properties().get( Fn::Property::D_NX ).toInt(); ny = dsl[0]->properties().get( Fn::Property::D_NY ).toInt(); nz = dsl[0]->properties().get( Fn::Property::D_NZ ).toInt(); dx = dsl[0]->properties().get( Fn::Property::D_DX ).toFloat(); dy = dsl[0]->properties().get( Fn::Property::D_DY ).toFloat(); dz = dsl[0]->properties().get( Fn::Property::D_DZ ).toFloat(); ax = dsl[0]->properties().get( Fn::Property::D_ADJUST_X ).toFloat(); ay = dsl[0]->properties().get( Fn::Property::D_ADJUST_Y ).toFloat(); az = dsl[0]->properties().get( Fn::Property::D_ADJUST_Z ).toFloat(); } QVector3D h0( nx * dx / 2 + ax, ny * dy / 2 + ay, nz * dz / 2 + az ); QVector3D h1( ax, h0.y(), h0.z() ); QVector3D h2( h0.x(), ay, h0.z() ); m_properties["maingl"].createBool( Fn::Property::D_SHOW_PLANE_HANDLES, true, "general" ); m_properties["maingl"].createColor( Fn::Property::D_HANDLE_COLOR, QColor( 255, 0, 0 ), "general" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_0, h0, "handles" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_1, h1, "handles" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_2, h2, "handles" ); PropertyGroup props2( m_properties["maingl"] ); m_properties.insert( "maingl2", props2 ); m_properties["maingl2"].createBool( Fn::Property::D_SHOW_PLANE_HANDLES, true, "general" ); m_properties["maingl2"].createColor( Fn::Property::D_HANDLE_COLOR, QColor( 255, 0, 0 ), "general" ); }
void mappedLengths(atacFile &AF, atacMatchList &matches, seqCache *A, seqCache *B, char *prefix) { histogram h1(100, 1000000); histogram h2(100, 1000000); // For the coverage to work correctly, we need to either have one // intervalList per input sequence, or build a table of the chained // sequence positions. // uint64 *offset1 = buildOffset(AF.fastaA()); uint64 *offset2 = buildOffset(AF.fastaB()); intervalList<uint64> intervalA; intervalList<uint64> intervalB; for (uint32 m=0; m<matches.numberOfMatches(); m++) { intervalA.add(offset1[matches[m]->iid1] + (uint64)matches[m]->pos1, (uint64)matches[m]->len1); intervalB.add(offset2[matches[m]->iid2] + (uint64)matches[m]->pos2, (uint64)matches[m]->len2); h1.add(matches[m]->len1); h2.add(matches[m]->len2); } fprintf(stdout, "numberOfItems "uint64FMT"\n", (uint64)matches.numberOfMatches()); fprintf(stdout, "matchLength %s "uint64FMT" %s "uint64FMT" # Sum of lengths of sequence in matches\n", AF.labelA(), (uint64)intervalA.sumOfLengths(), AF.labelB(), (uint64)intervalB.sumOfLengths()); h1.show("AmatchLength"); h2.show("BmatchLength"); h1.dump(prefix, "AmatchLength"); h1.plot(prefix, "AmatchLength"); h2.dump(prefix, "BmatchLength"); h2.plot(prefix, "BmatchLength"); intervalA.merge(); intervalB.merge(); fprintf(stdout, "coveredLength %s "uint64FMT" %s "uint64FMT" # sequence covered by a match, including N\n", AF.labelA(), (uint64)intervalA.sumOfLengths(), AF.labelB(), (uint64)intervalB.sumOfLengths()); fprintf(stdout, "coveredLength %s "uint64FMT" %s "uint64FMT" # sequence covered by a match, ACGT only (new)\n", AF.labelA(), tandemRepeatACGTLength(intervalA, offset1, A), AF.labelB(), tandemRepeatACGTLength(intervalB, offset2, B)); delete [] offset1; delete [] offset2; }
/** * Decrypt a single block of data. */ void skipjack_decrypt(byte tab[10][256], byte in[8], byte out[8]) { word32 w1, w2, w3, w4; w1 = (in[0] << 8) + in[1]; w2 = (in[2] << 8) + in[3]; w3 = (in[4] << 8) + in[5]; w4 = (in[6] << 8) + in[7]; /* stepping rule A: */ h1(tab, w2); w3 ^= w2 ^ 32; h0(tab, w3); w4 ^= w3 ^ 31; h4(tab, w4); w1 ^= w4 ^ 30; h3(tab, w1); w2 ^= w1 ^ 29; h2(tab, w2); w3 ^= w2 ^ 28; h1(tab, w3); w4 ^= w3 ^ 27; h0(tab, w4); w1 ^= w4 ^ 26; h4(tab, w1); w2 ^= w1 ^ 25; /* stepping rule B: */ w1 ^= w2 ^ 24; h3(tab, w2); w2 ^= w3 ^ 23; h2(tab, w3); w3 ^= w4 ^ 22; h1(tab, w4); w4 ^= w1 ^ 21; h0(tab, w1); w1 ^= w2 ^ 20; h4(tab, w2); w2 ^= w3 ^ 19; h3(tab, w3); w3 ^= w4 ^ 18; h2(tab, w4); w4 ^= w1 ^ 17; h1(tab, w1); /* stepping rule A: */ h0(tab, w2); w3 ^= w2 ^ 16; h4(tab, w3); w4 ^= w3 ^ 15; h3(tab, w4); w1 ^= w4 ^ 14; h2(tab, w1); w2 ^= w1 ^ 13; h1(tab, w2); w3 ^= w2 ^ 12; h0(tab, w3); w4 ^= w3 ^ 11; h4(tab, w4); w1 ^= w4 ^ 10; h3(tab, w1); w2 ^= w1 ^ 9; /* stepping rule B: */ w1 ^= w2 ^ 8; h2(tab, w2); w2 ^= w3 ^ 7; h1(tab, w3); w3 ^= w4 ^ 6; h0(tab, w4); w4 ^= w1 ^ 5; h4(tab, w1); w1 ^= w2 ^ 4; h3(tab, w2); w2 ^= w3 ^ 3; h2(tab, w3); w3 ^= w4 ^ 2; h1(tab, w4); w4 ^= w1 ^ 1; h0(tab, w1); out[0] = (byte)(w1 >> 8); out[1] = (byte)w1; out[2] = (byte)(w2 >> 8); out[3] = (byte)w2; out[4] = (byte)(w3 >> 8); out[5] = (byte)w3; out[6] = (byte)(w4 >> 8); out[7] = (byte)w4; }
int main() { Sac<int> s; Sac<Horloge> b1(4); s+= 4; s+= 6; s+= 9; s+= 8; IterateurSac<int> it(s); int somme; cout << "Itérateur de sac avec un sac de int" << endl; for(somme=0; !it; ++it){ somme += *it; cout << "Élément: " << *it << endl; } cout << "la somme de tous les éléments est: " << somme << endl << endl; Horloge h1(16,2,4,0); Horloge h2(5,22,56,0); Horloge h3(7,15,8,0); Horloge h4(19,7,14,0); Horloge h5(55,9,5,0); Horloge h6(1,21,22,0); b1+= h1; b1+= h2; b1+= h3; b1+= h4; b1+= h5; b1+= h6; cout << "Itérateur de sac avec un sac d'horloge" << endl; IterateurSac<Horloge> it2(b1); for(; !it2; ++it2){ cout << "Horloge: " << *it2 << endl; } system("PAUSE"); return 0; }
// Delete an integer from the hash. Return true if successful, // false if unsuccessful. bool ClosedHash::remove(int delValue){ if(isEmpty()) return false; int hidx = h(delValue); // home index; int pidx = h2(delValue); // probe index; for(int i = 0; ; i++) { int nidx = (hidx + i * pidx) % size(); if(HashTable[nidx] == delValue) { // found and delete. HashTable[nidx] = TOMBSTONE; cnt--; return true; } if(HashTable[nidx] == EMPTY) { return false; // can't find value. } } return false; }
//----------------------------------------------------------------------------- // Purpose: // Input : sboffset - //----------------------------------------------------------------------------- void CStatusWindow::PositionSliders( int sboffset ) { int lineheight = ( STATUS_FONT_SIZE + 2 ); int linesused = min( MAX_TEXT_LINES, m_nCurrentLine ); linesused = max( linesused, 1 ); int trueh = h2(); int vpixelsneeded = max( linesused * lineheight, trueh ); m_pScrollbar->setVisible( linesused * lineheight > trueh ); m_pScrollbar->setPagesize( trueh ); m_pScrollbar->setRange( 0, vpixelsneeded ); redraw(); }
int search(int htable[TABLESIZE], int key) { int index; int inc; index = h1(key); inc = h2(key); while (1) { if ( htable[index] == key ) return index; else if (htable[index] == -1 ) // search failure return index; else index = (index + inc) % TABLESIZE; } }
ListNode *partition(ListNode *head, int x) { ListNode h1(0), h2(0); ListNode *lt = &h1, *gte = &h2; while (head) { if (head->val < x) { lt->next = head; lt = lt->next; } else { gte->next = head; gte = gte->next; } head = head->next; } gte->next = nullptr; lt->next = h2.next; return h1.next; }
ValueT* Insert(KeyT key, uint32_t dwQuotas) { PointPtr pstPoint = new PointT<ValueT>(); HashT<KeyT> h; uint64_t ddwPointKey = h(key); ddwPointKey = ddwPointKey / AlignSize * AlignSize; m_stHashRing.insert(std::make_pair(ddwPointKey, pstPoint)); HashT<uint64_t> h2; for(size_t i=1; i<VirtualSize * dwQuotas; ++i) { ddwPointKey = h2(ddwPointKey); ddwPointKey = ddwPointKey / AlignSize * AlignSize; m_stHashRing.insert(std::make_pair(ddwPointKey, pstPoint)); } return &pstPoint->Value; }
// Find an integer value in the hash. Return true if found, // false if not. Store the number of probes in the variable // 'probes'. // One possible bug here is, when I fill the hash table to be FULL, // then I delete some items, in this case, the hash table items are // either set to TOMBSTONE or filled. In such a case when I try to // search an not-existed item, it will crash(maybe infinite loop). // My solution is to constrain the loop size to a very large // number. This has been commented out. Make comments if you have any // other work arounds. bool ClosedHash::find(int searchValue, int &probes) const{ probes = 0; int hidx = h(searchValue); // home index; int pidx = h2(searchValue); // probe index; for(int i = 0; /*i < 1000000*/; i++) { //if(i < 0) return false; int nidx = (hidx + i * pidx) % size(); if(HashTable[nidx] == searchValue) { // get it. return true; } else { // probe or can't find. probes++; if(HashTable[nidx] == EMPTY) { return false; } } } return false; }
/** * package http response header * @param responseData * @return */ std::string packHTTPHeader(std::string responseData, int responseNum, std::string response) { std::string h1("HTTP/1.1 "); std::string h4("\nDate: "); //fake apache server: std::string h2("Server: Apache/1.0.0\nContent-Length: "); std::string h3 = this->persistent?"Keep-Alive":"close"; time_t rawtime; time(&rawtime); return h1+std::to_string(responseNum) +" "+response+h4 +std::string(ctime(&rawtime))+h2 +std::to_string(responseData.length()) +std::string("\nConnection: ")+h3 //+std::string("\nContent-Type: text/html") +"\n\n" +std::string(responseData); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void mxStatusWindow::DrawActiveTool() { RECT rcTool; rcTool.left = 0; rcTool.top = GetCaptionHeight() + 2; rcTool.bottom = h2(); rcTool.right = w2() - 16; rcTool.bottom = rcTool.top + 10; rcTool.left = rcTool.right - 500; char sz[ 256 ]; IFacePoserToolWindow *activeTool = IFacePoserToolWindow::GetActiveTool(); static float lastrealtime = 0.0f; float dt = (float)realtime - lastrealtime; dt = clamp( dt, 0.0f, 1.0f ); float fps = 0.0f; if ( dt > 0.0001f ) { fps = 1.0f / dt; } sprintf( sz, "%s (%i) at %.3f (%.2f fps) (soundcount %i)", activeTool ? activeTool->GetToolName() : "None", g_MDLViewer->GetCurrentFrame(), (float)realtime, fps, models->CountActiveSources() ); lastrealtime = realtime; int len = CChoreoWidgetDrawHelper::CalcTextWidth( "Courier New", 10, FW_NORMAL, sz ); CChoreoWidgetDrawHelper helper( this, rcTool, RGB( 32, 0, 0 ) ); rcTool.left = rcTool.right - len - 15; helper.DrawColoredText( "Courier New", 10, FW_NORMAL, RGB( 255, 255, 200 ), rcTool, sz ); }
scHandleArray& scHandleArray::operator=( const scHandleArray& cpa ) { if ( fItems ) MEMResizeHnd( &fItems, cpa.fElemSize * cpa.fElemSlots ); else fItems = MEMAllocHnd( cpa.fElemSize * cpa.fElemSlots ); scAbstractArray::operator=( cpa ); scMemHandle h1_ = (scMemHandle)fItems; scMemHandle h2_ = (scMemHandle)cpa.fItems; scAutoUnlock h1( h1_ ); scAutoUnlock h2( h2_ ); memcpy( *h1, *h2, fElemSize * fNumItems ); return *this; }
//----------------------------------------------------------------------------- // Purpose: // Input : *event - // Output : int //----------------------------------------------------------------------------- int CStatusWindow::handleEvent( mxEvent *event ) { int iret = 0; switch ( event->event ) { default: break; case mxEvent::Size: { m_pScrollbar->setBounds( w2() - STATUS_SCROLLBAR_SIZE, 0, STATUS_SCROLLBAR_SIZE, h2() ); PositionSliders( 0 ); m_pScrollbar->setValue( m_pScrollbar->getMaxValue() ); iret = 1; } break; case mxEvent::Action: { iret = 1; switch ( event->action ) { default: iret = 0; break; case IDC_STATUS_SCROLL: { if ( event->event == mxEvent::Action && event->modifiers == SB_THUMBTRACK) { int offset = event->height; m_pScrollbar->setValue( offset ); PositionSliders( offset ); } } break; } } break; } return iret; }
int main( int argc, char *argv[]) { try { tsk::static_pool< tsk::unbounded_prio_queue< int > > pool( tsk::poolsize( 3) ); tsk::task< int > t1( fibonacci_fn, 10); tsk::task< int > t2( fibonacci_fn, 10); tsk::task< int > t3( fibonacci_fn, 10); tsk::task< int > t4( fibonacci_fn, 10); tsk::handle< int > h1( tsk::async( boost::move( t1) ) ); tsk::handle< int > h2( tsk::async( boost::move( t2), tsk::new_thread() ) ); tsk::handle< int > h3( tsk::async( boost::move( t3), 2, pool) ); tsk::handle< int > h4( tsk::async( boost::move( t4), 2, pool) ); std::cout << h1.get() << std::endl; std::cout << h2.get() << std::endl; std::cout << h3.get() << std::endl; std::cout << h4.get() << std::endl; return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch ( ... ) { std::cerr << "unhandled" << std::endl; } return EXIT_FAILURE; }
void POLYDuplicate( scVertHandle* dstOutHP, ushort& dstNumVerts, scVertHandle srcOutH, ushort srcNumVerts ) { scVertex* srcVert; scVertex* dstVert; *dstOutHP = (scVertHandle)MEMAllocHnd( (size_t)srcNumVerts * sizeof(scVertex) ); scAutoUnlock h1( *dstOutHP ); scAutoUnlock h2( srcOutH ); dstVert = (scVertex*)*h1; srcVert = (scVertex*)*h2; SCmemcpy( dstVert, srcVert, srcNumVerts * sizeof( scVertex ) ); dstNumVerts = srcNumVerts; }