コード例 #1
0
ファイル: plot_overlap.cpp プロジェクト: rforge/intervals
  SEXP _plot_overlap(SEXP e, SEXP c, SEXP full) {

    // Load data and sort
    int n = nrows(e);
    bool full_bool = *LOGICAL(full); 
    Endpoints ep ( REAL(e), LOGICAL(c), n, false, full_bool );

    // Set sorting order, then sort
    Endpoint::set_state_array( reduce_order );
    sort( ep.begin(), ep.end() );

    // Process
    int i;
    int active_count = 0;
    std::set<int> free_interior;
    std::vector<int> y (n);    
    Endpoints::const_iterator it;    

    // Initialize to NA
    for ( i = 0; i < n; i++ ) y[i] = R_NaInt;

    for ( it = ep.begin(); it < ep.end(); it++ ) {
      if ( it->left ) {
	// Opening an interval
	if ( free_interior.size() > 0 ) {
	  y[ it->index ] = *free_interior.begin();
	  free_interior.erase( free_interior.begin() );
	}
	else y[ it->index ] = active_count;
	active_count++;
      }
      else{
	// Closing an interval
	active_count--;
	if ( y[ it->index ] < active_count + free_interior.size() )
	  free_interior.insert( y[ it->index ] );
      }
    }

    // Prepare and return result.
    SEXP result;

    PROTECT( result = allocVector( INTSXP, n ) );    

    copy( 
	 y.begin(), y.end(),
	 std::vector<int>::iterator ( INTEGER( result ) )
	  );
    
    UNPROTECT(1);
    return( result );    

  }
コード例 #2
0
ファイル: ConfigBase.cpp プロジェクト: colding/lorica
Lorica::Config::Endpoints
Lorica::Config::get_endpoints(bool ext)
{
        Endpoints eps;

        if (this->endpoints_.empty()
            && (!this->init_endpoints(true)
                || !this->init_endpoints(false))) {
                this->endpoints_.clear();
                return eps;
        }

        for (Endpoints::const_iterator iter = endpoints_.begin();
	     iter != endpoints_.end();
	     iter++) {
                if (iter->external_ == ext)
                        eps.push_back (*iter);
        }

        return eps;
}
コード例 #3
0
ファイル: discovery.cpp プロジェクト: Mogito89/TOX002
void Discovery::HandleMessage()
{
	std::istream r(&message_);
	std::string line;
	r >> line; //skip version
	r >> line; //code
	if(line != "200")
	{
		std::string comment;
		std::getline(r, comment);
		throw std::runtime_error("Bad reply code: " + line + " " + comment);
	}

	while(std::getline(r, line) && line != "\r") /* =) */ ;

	typedef std::map<Ip::Endpoint, uint> Endpoints;
	typedef std::map<std::string, uint> WebCaches;

	Endpoints hubs;
	WebCaches webcaches;

	bool g2support = false;
	uint32 period = 0;
	while(std::getline(r, line))
	{
		boost::replace_all(line, "|", " ");
		std::stringstream s(line);
		char prefix;
		s >> prefix;
		switch(prefix)
		{
			case 'I': case'i':
			{
				std::string tag;
				std::string val;
				if(s >> tag >> val)
				{
					if(boost::iequals(tag, "support") && boost::iequals(val, "gnutella2"))
						g2support = true;
					else if(boost::iequals(tag, "access") && boost::iequals(val, "period"))
						s >> period;
				}
				break;
			}
			case 'H': case 'h':
			{
				std::string address;
				std::time_t seen = 0;
				if(s >> address)
				{
					s >> seen;
					seen = seen <= System::Now() ? seen : System::Now();
					Ip::Endpoint ep;
					if(ep.FromString(address))
						hubs[ep] = System::Since(seen);

				}
				break;
			}
			case 'U': case 'u':
			{
				std::string address;
				uint seen = 0;
				if(s >> address)
				{
					s >> seen;
					webcaches[address] =  System::Now() - seen;
				}
			}
		}
	}

	if(g2support)
	{
		System::LogBas() << "Discovered " << hubs.size() << " hub(s) and " << webcaches.size() << " web cache(s)" << std::endl;
		for(Endpoints::iterator i = hubs.begin(); i != hubs.end(); ++i)
			System::GetHubCache()->Touch(i->first, i->second);
		for(WebCaches::iterator i = webcaches.begin(); i != webcaches.end(); ++i)
			AddCache(i->first);
	}
	else
		caches_[address_].banned = true;
}