void ZipInstaller::install()
{
    qDebug() << "[ZipInstall] initializing installation";

    runner = 0;
    connect(this, SIGNAL(cont()), this, SLOT(installContinue()));
    m_url = m_urllist.at(runner);
    m_logsection = m_loglist.at(runner);
    m_logver = m_verlist.at(runner);
    installStart();
}
void future_cons(futures *fptr){
	int ans=-1,i;
	syscall arg;
	//for(i=0;i<4;i++){
		cont(fptr,prdata);
		if(arg!=-1 && ans!=-1){
			printf("the value produced %d\n",ans);
		//printf("the arg %d\n",arg);
	//}
		}
}
Beispiel #3
0
// put contigs from contfile into contlist
void Contiglist::add_contigs( std::string contigsfiles ){
  std::stringstream ss;
  ss.str( contigsfiles );
  std::string filename;
  std::string buffer("");
  std::string line("");
  std::string contig_id("");

  while( getline( ss, filename, ',' )){
    Log::Inst()->log_it( "contigsfile: " + filename );

    // open contig file
    std::ifstream cont( filename );

    // read in contig objects
    while( getline( cont, line ) ){
      if( line[0] == '>' && buffer.length() != 0 ){
        if( buffer.length() > 2*initial_trim + contig_sub_len ){
          buffer = buffer.substr( initial_trim, buffer.length() - 2*initial_trim );
          contigs.push_back( Contig( reads, buffer, contig_id ));
          if( verbose ){
            Log::Inst()->log_it( "Added contig: " + contig_id );
          }
        }
        else if( buffer.length() > contig_sub_len ){
          int trim = (buffer.length() - contig_sub_len) / 2;
          buffer = buffer.substr( trim, buffer.length() - 2*trim );
          contigs.push_back( Contig( reads, buffer, contig_id ));
          if( verbose ){
            Log::Inst()->log_it( "Added contig: " + contig_id );
          }
        }

        buffer = "";
        contig_id = line.substr(1);
      }
      else if ( line[0] == '>' ){
        contig_id = line.substr(1);
      }
      else{
        buffer += line;
      }
    }

    // close contig file
    cont.close();
  }

  // insert last line into contigs list
  if( buffer.length() != 0 ){
    contigs.push_back( Contig( reads, buffer, contig_id ) );
  }
}
Beispiel #4
0
int main(){

	std::cout << "[t-moeoDMLSMonOp] => START" << std::endl;

	//init all components
	moeoUnboundedArchive<Solution> arch(false);
	eoTimeContinue<Solution> cont(1);
	fullEvalSolution fullEval(8);
	Solution s;
	evalSolution eval(8);
	ObjectiveVector o;
	SolNeighbor n;
	SolNeighborhood nh(8);
	moeoPLS1<SolNeighbor> pls1(cont, fullEval, arch, nh, eval);
	moeoExhaustiveUnvisitedSelect<Solution> select;
	moeoExhaustiveNeighborhoodExplorer<SolNeighbor> explorer(nh, eval);

	//Create a solution
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);
	s.push_back(true);

	//Set its objective Vector
	o[0]=8;
	o[1]=0;
	s.objectiveVector(o);

	//test constructor 1 with a dmls and its archive
	moeoDMLSMonOp<SolNeighbor> test1(pls1, arch);

	//test constructor 2 with an incremental evaluation function, a selector and an explorer
	moeoDMLSMonOp<SolNeighbor> test2(fullEval, explorer, select, 2, true);

	//test constructor 3 with an incremental evaluation function, a selector and an explorer and the dmls archive
	moeoDMLSMonOp<SolNeighbor> test3(fullEval, arch, explorer, select, 2, true);

	std::cout << "initial solution:"  << std::endl;
	std::cout << s << std::endl;

	test1(s);

	std::cout << "mutate solution:"  << std::endl;
	std::cout << s << std::endl;

	std::cout << "[t-moeoDMLSMonOp] => OK" << std::endl;

	return EXIT_SUCCESS;
}
/*
    Extract the next character.
    Returns: the character (between 0 and 1114111)
         or  UTF8_END   (the end)
         or  UTF8_ERROR (error)
*/
int utf8_decode_next() {
    int c;  /* the first byte of the character */
    int c1; /* the first continuation character */
    int c2; /* the second continuation character */
    int c3; /* the third continuation character */
    int r;  /* the result */

    if (the_index >= the_length) {
        return the_index == the_length ? UTF8_END : UTF8_ERROR;
    }
    the_byte = the_index;
    the_char += 1;
    c = get();
/*
    Zero continuation (0 to 127)
*/
    if ((c & 0x80) == 0) {
        return c;
    }
/*
    One continuation (128 to 2047)
*/
    if ((c & 0xE0) == 0xC0) {
        c1 = cont();
        if (c1 >= 0) {
            r = ((c & 0x1F) << 6) | c1;
            if (r >= 128) {
                return r;
            }
        }

/*
    Two continuations (2048 to 55295 and 57344 to 65535)
*/
    } else if ((c & 0xF0) == 0xE0) {
        c1 = cont();
        c2 = cont();
        if ((c1 | c2) >= 0) {
            r = ((c & 0x0F) << 12) | (c1 << 6) | c2;
            if (r >= 2048 && (r < 55296 || r > 57343)) {
                return r;
            }
        }

/*
    Three continuations (65536 to 1114111)
*/
    } else if ((c & 0xF8) == 0xF0) {
        c1 = cont();
        c2 = cont();
        c3 = cont();
        if ((c1 | c2 | c3) >= 0) {
            r = ((c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
            if (r >= 65536 && r <= 1114111) {
                return r;
            }
        }
    }
    return UTF8_ERROR;
}
void virtual_bidirectional_iteratorTest::testString()
{
	std::string source[100];
	std::string correct[100];
	std::string test[100];
	size_t num = sizeof(source) / sizeof(source[0]);
	for (size_t i = 0; i < num; ++i)
	{
		std::ostringstream ostr;
		ostr << "stringnumber:" << i;
		source[i] = ostr.str();
	}
	std::random_shuffle(source, source + num);
	{
		std::list<std::string> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		std::set<std::string> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		std::vector<std::string> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		std::string *cont = new std::string[num];
		std::copy(source, source + num, cont);
		std::reverse_copy(cont, cont + num, correct);
		vrcopy(cont, cont + num, test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
		delete [] cont;
	}
}
Beispiel #7
0
int main(int argc, char **argv)
{
	context cont(width, height, "window");
	cont.attachArcBallCamera(glm::radians(45.0f), glm::vec3(4.0,4.0,3.0f));
	GLFWwindow *window = cont.getGLFWwindow();
	planeOBJ obj(0);
	cont.append_drawObj(&obj);

//	ShaderMan cubeShader("vs.glsl", "fs.glsl");
//	ShaderMan shadowShader("lightvs.glsl", "lightfs.glsl");
	cont.init();
	cont.run();
}
Beispiel #8
0
  void CodeGen::fixupFrame(RegisterState* s) {
    // window size adjustment
    assert(haveStackFrame, "should have stack frame");
    fint stackTempCount = s->stackDepth + s->argDepth;
    if (stackTempCount & 1) ++stackTempCount;
    frameSize = stackTempCountToFrameSize(stackTempCount);
    assert((frameSize & (frame_word_alignment-1))  ==  0, "frame size must be even");

    a.Comment("patching stack frame creation code");
    // The mask in the inline cache marks the regs + the first ntemps stack locs.
    // If we have fewer than ntemps temps and have extra args, the bits for the
    // extra args must be set.
    // All stack locations beyond the first ntemps have to be cleared.
    
    fint ntemps = BitsPerWord - (NumInRegisters + NumLocalRegisters);
    if (stackTempCount - s->argDepth  <  ntemps   &&  s->argDepth > 0) {
      s->fixupMasks(stackTempCount);
    }
    a.saveExcursion(prologueAddr);
    if (stackTempCount <= ntemps && !s->argDepth) {
      // no need to init anything on the stack - just patch frameSize
      a.SaveI(SP, frameSize * -oopSize, SP);    // make new register window
      a.endExcursion();
    } else {
      // need to initialize extra stack locations and/or extra args
      Label* l = a.BraForward(true);
      DefinedLabel cont(a.printing);
      a.endExcursion();
      l->define();
      a.SaveI(SP, frameSize * -oopSize, SP);    // make new register window
      // clear locations beyond first ntemps 
      fint i;
      for ( i = max(ntemps, s->initStackTemps); 
            i < stackTempCount; 
            i++) {
        a.StoreI(FP, (local_slots_offset - i) * oopSize, G0);
      }
      // clear extra args marked "live" by fixupMasks
      // (necessary because the simple fixup scheme marks them as live
      // for the entire method, not only after they're used)
      for ( i = 1; 
            i <= s->argDepth; 
            i++) {
        fint bitNo = stackTempCount - i;
        if (bitNo < ntemps) {
          a.StoreI(FP, (local_slots_offset - bitNo) * oopSize, G0);
        }
      }
      a.Bra(&cont, true);
    }
  }
void virtual_bidirectional_iteratorTest::testInt()
{
	int source[100];
	int correct[100];
	int test[100];
	size_t num = sizeof(source) / sizeof(source[0]);
	for (size_t i = 0; i < num; ++i)
	{
		source[i] = i;
	}
	std::random_shuffle(source, source + num);
	{
		std::list<int> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		std::set<int> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		std::vector<int> cont(source, source + num);
		std::reverse_copy(cont.begin(), cont.end(), correct);
		vrcopy(cont.begin(), cont.end(), test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
	}
	{
		int *cont = new int[num];
		std::copy(source, source + num, cont);
		std::reverse_copy(cont, cont + num, correct);
		vrcopy(cont, cont + num, test);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
		delete [] cont;
	}
}
Beispiel #10
0
void do_paused()
{
  enum user_commands cmd = get_command();
  
  switch(cmd) {
    case CMD_START:
  		cont();
      break;
  	case CMD_NEXT:
      stop();
  		next();
      break;
	}
}
Beispiel #11
0
void ScrollViewer::OnVerticalScroll(suic::ElementPtr eScroll, ScrollEventArg& scroll)
{
    suic::Int32 curpos = (int)_vScroll->GetScrollSize();

    suic::PanelPtr cont(GetContent());

    if (cont)
    {
        cont->SetVerticalOffset(curpos);

        cont->InvalidateArrange();
        cont->InvalidateVisual();
    }
}
Beispiel #12
0
        inline bool apply_l_p(actions::continuation* c,
            naming::address const& addr, threads::thread_priority priority)
        {
            typedef typename hpx::actions::extract_action<Action>::type action_type;

            BOOST_ASSERT(components::types_are_compatible(addr.type_,
                components::get_component_type<
                    typename action_type::component_type>()));

            actions::continuation_type cont(c);
            util::tuple<> env;
            apply_helper<action_type>::call(cont, addr.address_, priority, env);
            return true;     // no parcel has been sent (dest is local)
        }
Beispiel #13
0
bool Client::handleMyShare() {
    //Reads a file, assumes filename given in data.filename, userId in data.user
    //Puts the data into a vector - kabir decides.
    cout << " #### bak1\n";
    std::string req(RETURN_ALL_SHARED);
    conn.writeToSocket((req));
    cout << " #### bak2\n";
    std::string conti;

    conn.readFromSocket(conti);
    cout << " #### bak3\n";
    conn.writeToSocket(data.filename);
    cout << " #### bak4\n";
    conn.readFromSocket(conti);
    cout << " #### bak5\n";
    conn.writeToSocket(data.user.userID);
    cout << " #### bak6\n";
    conn.readFromSocket(conti);
    cout << " #### bak7\n";

    string _tempfile = "HarmanDeclares.txt";
    cout << " #### bak8\n";
    conn.readFromSocket_file(_tempfile);
    cout << " #### bak9\n";
    std::string cont(CONTINUE);
    conn.writeToSocket(cont);
    //Harman processes filea nd puts it in place for kabir.

//    this->getServerFiles_login();
//    cout << " #### bak10\n";
//    this->dropboxpage->updateServerFiles();
//    cout << " #### bak11\n";
    string name;
    ifstream f;
    f.open(_tempfile);
    string trash;
    f >> trash; //Trash values.
    while(f) {
        f >> name;
        if (name=="") {
            //Dont add it.
        } else {
            this->dropboxpage->names.insert(name);
        }
    }
    cout << " #### bak12\n";
    f.close();

    return true;
}
Beispiel #14
0
    int main(void)
    {
        Container<3,int> cont(1,2,3);

        double sum = 0.0;
        cont.doOperation([&sum](int x, int y, int z)->void{
            sum += x;
            sum += y;
            sum += z;
        });

        std::cout << sum << std::endl;

        return 0;
    }
Beispiel #15
0
void Widget::SetParent( Widget::Ptr parent ) {
	Container::Ptr  cont( std::dynamic_pointer_cast<Container>( parent ) );

	if( !cont ) {
		return;
	}

	Container::Ptr oldparent = m_parent.lock();

	if( oldparent ) {
		oldparent->Remove( shared_from_this() );
	}

	m_parent = cont;
}
Beispiel #16
0
/*
    Extract the next character.
    Returns: the character (between 0 and 1114111)
         or  UTF8_END   (the end)
         or  UTF8_ERROR (error)
*/
int 
utf8_decode_next(json_utf8_decode *utf8)
{
    int c;  /* the first byte of the character */
    int r;  /* the result */

    if (utf8->the_index >= utf8->the_length) {
        return utf8->the_index == utf8->the_length ? UTF8_END : UTF8_ERROR;
    }
    utf8->the_byte = utf8->the_index;
    utf8->the_char += 1;
    c = get(utf8);
/*
    Zero continuation (0 to 127)
*/
    if ((c & 0x80) == 0) {
        return c;
    }
/*
    One contination (128 to 2047)
*/
    if ((c & 0xE0) == 0xC0) {
        int c1 = cont(utf8);
        if (c1 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x1F) << 6) | c1;
        return r >= 128 ? r : UTF8_ERROR;
    }
/*
    Two continuation (2048 to 55295 and 57344 to 65535) 
*/
    if ((c & 0xF0) == 0xE0) {
        int c1 = cont(utf8);
        int c2 = cont(utf8);
        if (c1 < 0 || c2 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x0F) << 12) | (c1 << 6) | c2;
        return r >= 2048 && (r < 55296 || r > 57343) ? r : UTF8_ERROR;
    }
/*
    Three continuation (65536 to 1114111)
*/
    if ((c & 0xF1) == 0xF0) {
        int c1 = cont(utf8);
        int c2 = cont(utf8);
        int c3 = cont(utf8);
        if (c1 < 0 || c2 < 0 || c3 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x0F) << 18) | (c1 << 12) | (c2 << 6) | c3;
        return r >= 65536 && r <= 1114111 ? r : UTF8_ERROR;
    }
    return UTF8_ERROR;
}
bool
RealTrafficIPC::sendChangeset( const Disturbances& newElements,
                               const Disturbances& removedElements ) {
   Disturbances newClonedElements;
   Disturbances removedClonedElements;
   clone( newElements, newClonedElements );
   clone( removedElements, removedClonedElements );

   DisturbanceChangeset changeset( newClonedElements, removedClonedElements );
   // create the packet
   DisturbanceChangesetRequestPacket* packet = 
      new DisturbanceChangesetRequestPacket( Packet::PacketID( 0 ),
                                             m_moduleCom.getNextRequestID(),
                                             changeset );
   uint32 mapID = MAX_UINT32;
   if ( ! newElements.empty() ) {
      mapID = newElements.front()->getMapID();
   } else if ( ! removedElements.empty() ) {
      mapID = removedElements.front()->getMapID();
   }

   packet->setMapID( mapID );
   // send the packet and get the packet container as a return.
   auto_ptr<PacketContainer> cont( m_moduleCom.
                                   putRequest( packet, MODULE_TYPE_TRAFFIC ) );

   DisturbanceChangesetReplyPacket* answer;
   if ( getValidPacket( answer, cont.get() ) ) {
      if( answer && answer->getStatus() == StringTable::OK ) {
         mc2dbg4 << "[RTIPC] send change set OK" << endl;
         return true;
      } else {

         if ( answer->getUpdateStatus() == StringTable::NOTOK ) {
            mc2log << warn
                   << "[RTIPC] Failed to update new DisturbanceElements."
                   << endl;
         } 

         if ( answer->getRemoveStatus() == StringTable::NOTOK ) {
            mc2log << warn
                   << "[RTIPC] Failed to remove old DisturbanceElements."
                   << endl;
         }
      }
   }
   return false;
}
/*
	This function tests, if there is an overflow at the clock counter
	Function should be called at least every 30 min., if the cpu_time is stoped
	Otherwise there might be more than one overflow and results are wrong!
*/
void CStopWatch::testOverflow()
{
	if(m_iTimeType == util_CPU_TIME)
	{
		stop();
		if (m_iLast < m_iFirst)
		{
			m_fOverflowTime += (double(m_iLast - m_iFirst + ULONG_MAX)) / CLOCKS_PER_SEC;
			start();
		}
		else
			cont();
	}
	else
		warning("testOverflow() : overflow has to be tested only when measuring cpu-time");
};
  /*!
   * @if jp
   * @brief NamingContext を再帰的に下って非アクティブ化する
   * @else
   * @brief Destroy the naming context recursively
   * @endif
   */
  void CorbaNaming::destroyRecursive(CosNaming::NamingContext_ptr context)
    throw (SystemException, NotEmpty, NotFound, CannotProceed, InvalidName)
  {
    CosNaming::BindingList_var     bl;
    CosNaming::BindingIterator_var bi;
    CORBA::Boolean cont(true);
    
#ifndef ORB_IS_RTORB
    context->list(m_blLength, bl.out(), bi.out());
#else // ORB_IS_RTORB
    //    context->list(m_blLength, bl, bi);
    context->list(m_blLength, (CosNaming::BindingList_out)bl,
                  (CosNaming::BindingIterator_ptr)bi);
#endif // ORB_IS_RTORB
    
    while (cont)
      {
	CORBA::ULong len(bl->length());
	
	for (CORBA::ULong i = 0; i < len; ++i)
	  {
	    if (bl[i].binding_type == CosNaming::ncontext)
	      {	// If Object is context, destroy recursive.
		CosNaming::NamingContext_var next_context;
		next_context = CosNaming::NamingContext::
		  _narrow(context->resolve(bl[i].binding_name));
		
		// Recursive function call
		destroyRecursive(next_context); // +++ Recursive call +++
		context->unbind(bl[i].binding_name);
		next_context->destroy();
	      }
	    else if (bl[i].binding_type == CosNaming::nobject)
	      {	// If Object is object, unbind it.
		context->unbind(bl[i].binding_name);
	      }
	    else assert(0); // never comes here
	  }
	
	// no more binding -> do-while loop will be finished
	if (CORBA::is_nil(bi)) cont = false;
	else bi->next_n(m_blLength, bl);
      }
    
    if (!CORBA::is_nil(bi)) bi->destroy();
    return;
  }
int main (int argc, char **argv)
{
  EDAMetasearchStart (argc, argv);
  if (argc != 2)
  {
    std::cerr << "Usage : ./" <<  __progname
              << " [instance]" << std::endl;
  }
  else
  {
            
    Graph graph(argv[1]);
    edaSolutionList list;
    for(unsigned int i = 0; i < 40; i++) {
      tspSolution *route = new tspSolution (graph); 
      route->init();
      list.push_back(route);
    }	     

    
    tspTwoOpt two_opt (graph);
    tspTwoOptNext two_opt_next (graph);   
    edaFirstImprSelect moveSelect;
    edaGenContinue cont(1500);  
    edaHC hcSearch (&two_opt, &two_opt_next, &moveSelect, &cont); 
    
    // Use the declaration below to run on single machine:
    edaSeqWrapperControl sfControl;          
    sfControl.insertVertex (&hcSearch);  
    if (!sfControl.search (list))
    {
      cerr << "Error: Cannot execute search" << endl;
    }
    else
    {
      tspSolution route = *( (tspSolution*) list.getBest() );
      cout << "[Route] " << route << endl;
      cout << "[Fitness] " << route.evaluate () << endl;
//      route.save("route.txt");
    }
  }

  EDAMetasearchStop ();

  return 0;
}
Beispiel #21
0
        inline bool
        apply_r_p(naming::address& addr, actions::continuation* c,
            naming::id_type const& gid, threads::thread_priority priority)
        {
            typedef typename hpx::actions::extract_action<Action>::type action_type;

            actions::continuation_type cont(c);

            // If remote, create a new parcel to be sent to the destination
            // Create a new parcel with the gid, action, and arguments
            parcelset::parcel p (gid.get_gid(), complement_addr<action_type>(addr),
                new hpx::actions::transfer_action<action_type>(priority), cont);

            // Send the parcel through the parcel handler
            hpx::applier::get_applier().get_parcel_handler().put_parcel(p);
            return false;     // destination is remote
        }
Beispiel #22
0
void pi_do_claimed( PIA *pi, void(*cont)(void))

#ifdef CONFIG_PARPORT

{	long flags;

	spin_lock_irqsave(&pi_spinlock,flags); 

	if (!pi->pardev || !parport_claim(pi->pardev)) {
		pi->claimed = 1;
		spin_unlock_irqrestore(&pi_spinlock,flags);
		cont();
	} else {
		pi->claim_cont = cont;
		spin_unlock_irqrestore(&pi_spinlock,flags);	
	}
}
Beispiel #23
0
suic::Size ScrollViewer::ArrangeOverride(const suic::Size& availableSize)
{
    ClearVisualChildren();

    suic::ElementPtr cont(GetContent());

    if (cont)
    {
        suic::Rect rect;

        rect.right = availableSize.cx;
        rect.bottom = availableSize.cy;

        _vScroll->SetVisible(false);
        _hScroll->SetVisible(false);

        suic::Size desiredSize = cont->GetDesiredSize();

        //
        // 计算是否有滚动条
        //
        _hScroll->UpdateScrollInfo(rect.right, desiredSize.cx, false);
        _vScroll->UpdateScrollInfo(rect.bottom, desiredSize.cy, false);

        ComputeScrollBar(rect.right, rect.bottom, desiredSize.cx, desiredSize.cy);

        suic::PanelPtr lay(cont);

        if (lay)
        {
            lay->SetHorizontalOffset(_hScroll->GetScrollSize());
            lay->SetVerticalOffset(_vScroll->GetScrollSize());
        }

        rect.left += _contentOffset.x;
        rect.top += _contentOffset.y;

        if (rect.bottom > rect.top)
        {
            AddVisualChild(cont.get());
            cont->Arrange(rect);
        }
    }

    return availableSize;
}
Beispiel #24
0
void testHashMapCStr()
{
	typedef NS_STDEXT::AutoAlloc AllocT;
	typedef NS_STDEXT::HashMap<const char*, int, NS_STDEXT::HashCompare<const char*>, AllocT> MapT;

	AllocT alloc;
	MapT cont(alloc);

	cont.insert(MapT::value_type("Mon", 1));
	cont.insert(MapT::value_type("Tue", 2));

	const char key[] = "Mon";
	MapT::iterator it = cont.find(key);
	if (it != cont.end())
		std::cout << (*it).second << "\n";
	else
		std::cout << "ERROR: Not found!\n";
}
// bfs.
// 用dfs也可以解决,键枝的依据在于,结果的长度不会高于一直平方的长度.比如,1-2-4-8-16...
// 这个问题是经典的NPC问题.wiki上有上述的论述.
// en.m.wikipedia.org/wiki/Addition-chain_exponentiation
// http://www.mathblog.dk/project-euler-122-efficient-exponentiation/
int solve_122()
{
	std::queue<container> que;
	
	container cont(Count);
	cont[0] = 1;

	bs_type sieve;
	sieve.set(0);
	
	que.push(container(1, 1));

	size_t deep = 0;
	
	while(!que.empty())
	{	
		container coins = que.front();
		que.pop();

		container::value_type last = coins.back();
		deep = coins.size();

		for(size_t i = 0; i < deep; ++i)
		{
			size_t tmp = last + coins[i];
			if(tmp > Count)
				break;

			// [1], see below.
			// already set and need more steps.
			if(sieve.test(tmp - 1) && cont[tmp - 1] < deep)
				continue;

			if(!set_value(&cont, tmp - 1, deep, sieve))
				return std::accumulate(cont.begin(), cont.end(), 0) - 1;// (zero step to get 1)

			coins.push_back(tmp);
			que.push(coins);
			coins.pop_back();
		}
	}
	throw std::runtime_error("runtime error: unable to get the answer!");
	return deep;
}
Beispiel #26
0
void Widget::SetParent( const Widget::Ptr& parent ) {
	Container::Ptr cont( DynamicPointerCast<Container>( parent ) );

	if( !cont ) {
		return;
	}

	Container::Ptr oldparent = m_parent.lock();

	if( oldparent ) {
		oldparent->Remove( shared_from_this() );
	}

	m_parent = cont;

	SetHierarchyLevel( parent->GetHierarchyLevel() + 1 );

	HandleAbsolutePositionChange();
}
Beispiel #27
0
suic::Size ScrollViewer::MeasureOverride(const suic::Size& availableSize)
{
    _hScroll->Measure(availableSize);
    _vScroll->Measure(availableSize);

    suic::Size retSize(GetDesiredSize());
    suic::ElementPtr cont(GetContent());

    if (cont)
    {
        cont->Measure(availableSize);

        return cont->GetDesiredSize();
    }
    else
    {
        return retSize;
    }
}
bool RealTrafficIPC::getAllDisturbances( const MC2String& provider,
                                         Disturbances& disturbances ) {
   FetchAllDisturbancesRequestPacket* packet =
      new FetchAllDisturbancesRequestPacket( Packet::PacketID( 0 ),
                                             m_moduleCom.getNextRequestID(),
                                             provider );

   // create the packet container
   auto_ptr<PacketContainer> cont( m_moduleCom.
                                   putRequest( packet, MODULE_TYPE_TRAFFIC ) );

   FetchAllDisturbancesReplyPacket* answer;
   if ( getValidPacket( answer, cont.get() ) ) {
      answer->getDisturbances( disturbances );
      return true;
   }

   return false;
}
Beispiel #29
0
        inline bool
        apply_r_p_cb(naming::address& addr, actions::continuation* c,
            naming::id_type const& id, threads::thread_priority priority,
            Callback && cb)
        {
            typedef typename hpx::actions::extract_action<Action>::type action_type;

            actions::continuation_type cont(c);

            // If remote, create a new parcel to be sent to the destination
            // Create a new parcel with the gid, action, and arguments
            parcelset::parcel p(id, complement_addr<action_type>(addr),
                new hpx::actions::transfer_action<action_type>(priority,
                    util::forward_as_tuple()), cont);

            // Send the parcel through the parcel handler
            hpx::applier::get_applier().get_parcel_handler()
                .put_parcel(p, std::forward<Callback>(cb));
            return false;     // destination is remote
        }
Beispiel #30
0
static void pi_wake_up( void *p)

{       PIA  *pi = (PIA *) p;
	long flags;
	void (*cont)(void) = NULL;

	spin_lock_irqsave(&pi_spinlock,flags);

	if (pi->claim_cont && !parport_claim(pi->pardev)) {
		cont = pi->claim_cont;
		pi->claim_cont = NULL;
		pi->claimed = 1;
	}

	spin_unlock_irqrestore(&pi_spinlock,flags);	

	wake_up(&(pi->parq));

	if (cont) cont();
}